-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix DropServiceBoxTests out-of-sync testing logic
DropServiceBoxTest logic was out of sync with base DropServiceTest due to overrides in testing logic. It was done this way likely because DropServiceTest logic was coupled with java.io.File. Drop file access is now isolated from testing logic and overriden in DropServiceBoxTest. Testing logic overrides are not needed anymore so they are deleted, thus all tests are in sync again.
- Loading branch information
Showing
3 changed files
with
117 additions
and
137 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
webapp/src/test/java/com/box/l10n/mojito/service/drop/DropFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.box.l10n.mojito.service.drop; | ||
|
||
import com.box.l10n.mojito.boxsdk.BoxSDKServiceException; | ||
import java.io.IOException; | ||
|
||
public interface DropFile { | ||
String getName(); | ||
|
||
String getContent() throws BoxSDKServiceException, IOException; | ||
} |
147 changes: 51 additions & 96 deletions
147
webapp/src/test/java/com/box/l10n/mojito/service/drop/DropServiceBoxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,103 @@ | ||
package com.box.l10n.mojito.service.drop; | ||
|
||
import com.box.l10n.mojito.boxsdk.BoxFileWithContent; | ||
import com.box.l10n.mojito.boxsdk.BoxSDKService; | ||
import com.box.l10n.mojito.boxsdk.BoxSDKServiceConfigFromProperties; | ||
import com.box.l10n.mojito.boxsdk.BoxSDKServiceException; | ||
import com.box.l10n.mojito.entity.Drop; | ||
import com.box.l10n.mojito.okapi.XliffState; | ||
import com.box.l10n.mojito.service.drop.exporter.BoxDropExporter; | ||
import com.box.l10n.mojito.service.drop.exporter.BoxDropExporterConfig; | ||
import com.box.l10n.mojito.service.drop.exporter.DropExporterException; | ||
import com.box.l10n.mojito.test.XliffUtils; | ||
import com.box.l10n.mojito.test.category.BoxSDKTest; | ||
import com.box.l10n.mojito.test.category.SlowTest; | ||
import com.box.sdk.BoxFile; | ||
import org.junit.Test; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.junit.experimental.categories.Category; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
import org.junit.Assume; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.springframework.boot.test.WebIntegrationTest; | ||
|
||
import static com.box.l10n.mojito.service.drop.exporter.DropExporterDirectories.*; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
/** | ||
* @author jaurambault | ||
*/ | ||
@Ignore("won't work without @DirtiesContext which makes the build to slow") | ||
@WebIntegrationTest(randomPort = true, value = {"l10n.dropexporter.type=BOX"}) | ||
@Category({BoxSDKTest.class, SlowTest.class}) | ||
public class DropServiceBoxTest extends DropServiceTest { | ||
|
||
static Logger logger = LoggerFactory.getLogger(DropServiceBoxTest.class); | ||
|
||
@Autowired | ||
BoxSDKServiceConfigFromProperties boxSDKServiceConfigFromProperties; | ||
|
||
@Autowired | ||
BoxSDKService boxSDKService; | ||
|
||
@Before | ||
public void checkBoxConfig() { | ||
//TODO(P1) here we'll need to check if Box credential are available, if not don't run tests | ||
Assume.assumeTrue(true); | ||
} | ||
|
||
@Test | ||
@Category({BoxSDKTest.class, SlowTest.class}) | ||
@Override | ||
public void testCreateDrop() throws Exception { | ||
super.testCreateDrop(); | ||
} | ||
|
||
@Test | ||
@Category({BoxSDKTest.class, SlowTest.class}) | ||
@Override | ||
public void forTranslation() throws Exception { | ||
super.forTranslation(); | ||
} | ||
|
||
@Test | ||
@Category({BoxSDKTest.class, SlowTest.class}) | ||
@Override | ||
public void forTranslationWithTranslationAddedAfterExport() throws Exception { | ||
super.forTranslationWithTranslationAddedAfterExport(); | ||
assumeTrue(StringUtils.isNotEmpty(boxSDKServiceConfigFromProperties.getRootFolderId())); | ||
} | ||
|
||
@Test | ||
@Category({BoxSDKTest.class, SlowTest.class}) | ||
@Override | ||
public void forReview() throws Exception { | ||
super.forTranslation(); | ||
public List<DropFile> getDropFiles(Drop drop, String dropFolder) throws DropExporterException, BoxSDKServiceException { | ||
return boxSDKService.listFiles(getDropFolderIdForName(drop, dropFolder)).stream() | ||
.map(boxFile -> | ||
new BoxDropFile(boxFile, boxSDKService)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Test | ||
@Category({BoxSDKTest.class, SlowTest.class}) | ||
@Override | ||
public void allWithSevereError() throws Exception { | ||
super.allWithSevereError(); | ||
public void writeDropFile(Drop drop, String dropFolder, String fileName, String content) | ||
throws BoxSDKServiceException, DropExporterException { | ||
boxSDKService.uploadFile(getDropFolderIdForName(drop, dropFolder), fileName, content); | ||
} | ||
|
||
@Override | ||
public void localizeDropFiles(Drop drop, int round) throws BoxSDKServiceException, DropExporterException { | ||
|
||
logger.debug("Localize files in a drop for testing"); | ||
|
||
BoxDropExporter boxDropExporter = (BoxDropExporter) dropExporterService.recreateDropExporter(drop); | ||
public String getDropFolderIdForName(Drop drop, String dropFolderName) | ||
throws DropExporterException { | ||
BoxDropExporter boxDropExporter = | ||
(BoxDropExporter) dropExporterService.recreateDropExporter(drop); | ||
BoxDropExporterConfig boxDropExporterConfig = boxDropExporter.getBoxDropExporterConfig(); | ||
|
||
List<BoxFile> sourceFiles = boxSDKService.listFiles(boxDropExporterConfig.getSourceFolderId()); | ||
|
||
for (BoxFile sourceFile : sourceFiles) { | ||
BoxFileWithContent fileContent = boxSDKService.getFileContent(sourceFile); | ||
String localizedContent = fileContent.getContent(); | ||
|
||
if (sourceFile.getInfo().getName().startsWith("ko-KR")) { | ||
logger.debug("For the Korean file, don't translate but add a corrupted text unit (invalid id) at the end"); | ||
localizedContent = localizedContent.replaceAll("</body>", | ||
"<trans-unit id=\"badid\" resname=\"TEST2\">\n" | ||
+ "<source xml:lang=\"en\">Content2</source>\n" | ||
+ "<target xml:lang=\"ko-kr\">Import Drop" + round + " - Content2 ko-kr</target>\n" | ||
+ "</trans-unit>\n" | ||
+ "</body>"); | ||
} else if (sourceFile.getInfo().getName().startsWith("it-IT")) { | ||
logger.debug("For the Italien file, don't translate but add a corrupted xml"); | ||
localizedContent = localizedContent.replaceAll("</body>", "</bod"); | ||
} else { | ||
localizedContent = XliffUtils.localizeTarget(localizedContent, "Import Drop" + round); | ||
} | ||
|
||
boxSDKService.uploadFile(boxDropExporterConfig.getLocalizedFolderId(), sourceFile.getInfo().getName(), localizedContent); | ||
switch (dropFolderName) { | ||
case DROP_FOLDER_SOURCE_FILES_NAME: | ||
return boxDropExporterConfig.getSourceFolderId(); | ||
case DROP_FOLDER_LOCALIZED_FILES_NAME: | ||
return boxDropExporterConfig.getLocalizedFolderId(); | ||
case DROP_FOLDER_IMPORTED_FILES_NAME: | ||
return boxDropExporterConfig.getImportedFolderId(); | ||
case DROP_FOLDER_QUERIES_NAME: | ||
return boxDropExporterConfig.getQueriesFolderId(); | ||
case DROP_FOLDER_QUOTES_NAME: | ||
return boxDropExporterConfig.getQuotesFolderId(); | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void reviewDropFiles(Drop drop) throws DropExporterException, BoxSDKServiceException { | ||
|
||
logger.debug("Review files in a drop for testing"); | ||
|
||
BoxDropExporter boxDropExporter = (BoxDropExporter) dropExporterService.recreateDropExporter(drop); | ||
BoxDropExporterConfig boxDropExporterConfig = boxDropExporter.getBoxDropExporterConfig(); | ||
|
||
List<BoxFile> sourceFiles = boxSDKService.listFiles(boxDropExporterConfig.getSourceFolderId()); | ||
|
||
for (BoxFile sourceFile : sourceFiles) { | ||
BoxFileWithContent fileContent = boxSDKService.getFileContent(sourceFile); | ||
String reviewedContent = fileContent.getContent(); | ||
|
||
reviewedContent = XliffUtils.replaceTargetState(reviewedContent, XliffState.SIGNED_OFF.toString()); | ||
class BoxDropFile implements DropFile { | ||
private final BoxFile boxFile; | ||
private final BoxSDKService boxSDKService; | ||
|
||
boxSDKService.uploadFile(boxDropExporterConfig.getLocalizedFolderId(), sourceFile.getInfo().getName(), reviewedContent); | ||
} | ||
BoxDropFile(BoxFile boxFile, BoxSDKService boxSDKService) { | ||
this.boxFile = boxFile; | ||
this.boxSDKService = boxSDKService; | ||
} | ||
|
||
@Override | ||
public void checkImportedFilesContent(Drop drop, int round) throws BoxSDKServiceException, DropExporterException { | ||
|
||
logger.debug("Check imported files contains text unit variant ids"); | ||
|
||
BoxDropExporter boxDropExporter = (BoxDropExporter) dropExporterService.recreateDropExporter(drop); | ||
BoxDropExporterConfig boxDropExporterConfig = boxDropExporter.getBoxDropExporterConfig(); | ||
|
||
List<BoxFile> importedFiles = boxSDKService.listFiles(boxDropExporterConfig.getImportedFolderId()); | ||
|
||
for (BoxFile importedFile : importedFiles) { | ||
BoxFileWithContent fileWithContent = boxSDKService.getFileContent(importedFile); | ||
checkImportedFilesContent(importedFile.getInfo().getName(), fileWithContent.getContent(), round); | ||
} | ||
public String getName() { | ||
return boxFile.getInfo().getName(); | ||
} | ||
|
||
} | ||
public String getContent() throws BoxSDKServiceException { | ||
return boxSDKService.getFileContent(boxFile).getContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters