-
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.
Adding new parameters to ThirdPartyService
- Loading branch information
Showing
22 changed files
with
474 additions
and
110 deletions.
There are no files selected for viewing
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
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
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
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
8 changes: 4 additions & 4 deletions
8
cli/src/main/java/com/box/l10n/mojito/cli/command/ThirdPartySyncActionsConverter.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,15 +1,15 @@ | ||
package com.box.l10n.mojito.cli.command; | ||
|
||
import com.box.l10n.mojito.rest.client.ThirdPartySync; | ||
import com.box.l10n.mojito.rest.ThirdPartySyncAction; | ||
|
||
/** | ||
* | ||
* @author sdemyanenko | ||
*/ | ||
public class ThirdPartySyncActionsConverter extends EnumConverter<ThirdPartySync.Action> { | ||
public class ThirdPartySyncActionsConverter extends EnumConverter<ThirdPartySyncAction> { | ||
|
||
@Override | ||
protected Class<ThirdPartySync.Action> getGenericClass() { | ||
return ThirdPartySync.Action.class; | ||
protected Class<ThirdPartySyncAction> getGenericClass() { | ||
return ThirdPartySyncAction.class; | ||
} | ||
} |
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
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
97 changes: 85 additions & 12 deletions
97
cli/src/test/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommandTest.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,32 +1,105 @@ | ||
package com.box.l10n.mojito.cli.command; | ||
|
||
import com.box.l10n.mojito.cli.CLITestBase; | ||
import com.box.l10n.mojito.cli.utils.PollableTaskJobMatcher; | ||
import com.box.l10n.mojito.cli.utils.TestingJobListener; | ||
import com.box.l10n.mojito.entity.Repository; | ||
import com.box.l10n.mojito.rest.client.ThirdPartySync; | ||
import com.box.l10n.mojito.json.ObjectMapper; | ||
import com.box.l10n.mojito.rest.thirdparty.ThirdPartySyncAction; | ||
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJob; | ||
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobInput; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.quartz.JobKey; | ||
import org.quartz.Matcher; | ||
import org.quartz.Scheduler; | ||
import org.quartz.SchedulerException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static com.box.l10n.mojito.rest.thirdparty.ThirdPartySyncAction.MAP_TEXTUNIT; | ||
import static com.box.l10n.mojito.rest.thirdparty.ThirdPartySyncAction.PUSH_SCREENSHOT; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ThirdPartySyncCommandTest extends CLITestBase { | ||
|
||
/** | ||
* logger | ||
*/ | ||
static Logger logger = LoggerFactory.getLogger(ThirdPartySyncCommandTest.class); | ||
@Autowired | ||
@Qualifier("fail_on_unknown_properties_false") | ||
ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
Scheduler scheduler; | ||
|
||
Matcher<JobKey> jobMatcher; | ||
TestingJobListener testingJobListener; | ||
|
||
@Before | ||
public void setUp() throws SchedulerException { | ||
testingJobListener = new TestingJobListener(objectMapper); | ||
jobMatcher = new PollableTaskJobMatcher<>(ThirdPartySyncJob.class); | ||
scheduler.getListenerManager().addJobListener(testingJobListener, jobMatcher); | ||
} | ||
|
||
@After | ||
public void tearDown() throws SchedulerException { | ||
scheduler.getListenerManager().removeJobListener(testingJobListener.getName()); | ||
scheduler.getListenerManager().removeJobListenerMatcher(testingJobListener.getName(), jobMatcher); | ||
} | ||
|
||
@Test | ||
public void execute() throws Exception { | ||
|
||
String repoName = testIdWatcher.getEntityName("thirdpartysync_execute"); | ||
|
||
Repository repository = repositoryService.createRepository(repoName, repoName + " description", null, false); | ||
getL10nJCommander().run("thirdparty-sync", "-r", repository.getName(), "-p", "does-not-matter-yet", "-ps", " _"); | ||
String projectId = testIdWatcher.getEntityName("projectId"); | ||
|
||
// TODO: For a plural separator like " _" this test will fail. The current version we have for | ||
// JCommander trims the argument values, even when quoted. | ||
// https://github.com/cbeust/jcommander/issues/417 | ||
// https://github.com/cbeust/jcommander/commit/4aec38b4a0ea63a8dc6f41636fa81c2ebafddc18 | ||
String pluralSeparator = "_"; | ||
String skipTextUnitPattern = "%skip_text_pattern"; | ||
String skipAssetPattern = "%skip_asset_pattern%"; | ||
List<String> options = Arrays.asList( | ||
"special-option=value@of%Option", | ||
"smartling-placeholder-custom=\\{\\{\\}\\}|\\{\\{?.+?\\}\\}?|\\%\\%\\(.+?\\)s|\\%\\(.+?\\)s|\\%\\(.+?\\)d|\\%\\%s|\\%s" | ||
); | ||
|
||
getL10nJCommander().run("thirdparty-sync", | ||
"-r", repository.getName(), | ||
"-p", projectId, | ||
"-a", MAP_TEXTUNIT.name(), PUSH_SCREENSHOT.name(), | ||
"-ps", pluralSeparator, | ||
"-st", skipTextUnitPattern, | ||
"-sa", skipAssetPattern, | ||
"-o", options.get(0), options.get(1)); | ||
|
||
String output = outputCapture.toString(); | ||
assertThat(output).contains("repository: " + repository.getName()); | ||
assertThat(output).contains("project id: " + projectId); | ||
assertThat(output).contains("actions: " + Arrays.asList(ThirdPartySyncAction.MAP_TEXTUNIT, ThirdPartySyncAction.PUSH_SCREENSHOT).toString()); | ||
assertThat(output).contains("skip-text-units-with-pattern: " + skipTextUnitPattern); | ||
assertThat(output).contains("skip-assets-path-pattern: " + skipAssetPattern); | ||
assertThat(output).contains("options: " + options.toString()); | ||
|
||
waitForCondition("Ensure ThirdPartySyncJob gets executed", | ||
() -> testingJobListener.getExecuted().size() > 0); | ||
|
||
ThirdPartySyncJobInput jobInput = testingJobListener.getFirstInputMapAs(ThirdPartySyncJobInput.class); | ||
|
||
String outputString = outputCapture.toString(); | ||
assertTrue(outputString.contains(Arrays.asList(ThirdPartySync.Action.MAP_TEXTUNIT, ThirdPartySync.Action.PUSH_SCREENSHOT).toString())); | ||
assertThat(jobInput).isNotNull(); | ||
assertThat(jobInput.getRepositoryId()).isEqualTo(repository.getId()); | ||
assertThat(jobInput.getThirdPartyProjectId()).isEqualTo(projectId); | ||
assertThat(jobInput.getActions()).containsExactlyInAnyOrder(MAP_TEXTUNIT, PUSH_SCREENSHOT); | ||
assertThat(jobInput.getPluralSeparator()).isEqualTo(pluralSeparator); | ||
assertThat(jobInput.getSkipTextUnitsWithPattern()).isEqualTo(skipTextUnitPattern); | ||
assertThat(jobInput.getSkipAssetsWithPathPattern()).isEqualTo(skipAssetPattern); | ||
assertThat(jobInput.getOptions()).containsExactlyInAnyOrderElementsOf(options); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
cli/src/test/java/com/box/l10n/mojito/cli/utils/PollableTaskJobMatcher.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,21 @@ | ||
package com.box.l10n.mojito.cli.utils; | ||
|
||
import com.box.l10n.mojito.quartz.QuartzPollableJob; | ||
import org.quartz.JobKey; | ||
import org.quartz.Matcher; | ||
|
||
import static com.box.l10n.mojito.quartz.QuartzConfig.DYNAMIC_GROUP_NAME; | ||
|
||
public class PollableTaskJobMatcher<T extends QuartzPollableJob> implements Matcher<JobKey> { | ||
|
||
private final Class<T> target; | ||
|
||
public PollableTaskJobMatcher(Class<T> target) { | ||
this.target = target; | ||
} | ||
|
||
@Override | ||
public boolean isMatch(JobKey key) { | ||
return key.getName().startsWith(target.getName()) && DYNAMIC_GROUP_NAME.equals(key.getGroup()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
cli/src/test/java/com/box/l10n/mojito/cli/utils/TestingJobListener.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,65 @@ | ||
package com.box.l10n.mojito.cli.utils; | ||
|
||
import com.box.l10n.mojito.json.ObjectMapper; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
import org.quartz.JobListener; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
import static com.box.l10n.mojito.quartz.QuartzPollableJob.INPUT; | ||
|
||
public class TestingJobListener implements JobListener { | ||
|
||
private final Queue<JobExecutionContext> toBeExecuted = new LinkedList<>(); | ||
private final Queue<JobExecutionContext> executed = new LinkedList<>(); | ||
private final Queue<JobExecutionException> exceptions = new LinkedList<>(); | ||
private final ObjectMapper objectMapper; | ||
|
||
public TestingJobListener(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
public TestingJobListener() { | ||
this.objectMapper = new ObjectMapper(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "TestingJobListener"; | ||
} | ||
|
||
@Override | ||
public void jobToBeExecuted(JobExecutionContext context) { | ||
toBeExecuted.offer(context); | ||
} | ||
|
||
@Override | ||
public void jobExecutionVetoed(JobExecutionContext context) { | ||
} | ||
|
||
@Override | ||
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { | ||
executed.offer(context); | ||
exceptions.offer(jobException); | ||
} | ||
|
||
public Queue<JobExecutionContext> getExecuted() { | ||
return executed; | ||
} | ||
|
||
public Queue<JobExecutionContext> getToBeExecuted() { | ||
return toBeExecuted; | ||
} | ||
|
||
public <T> T getFirstInputMapAs(Class<T> klass) { | ||
String input = getExecuted().stream() | ||
.filter(context -> context.getMergedJobDataMap().containsKey(INPUT)) | ||
.map(context -> context.getMergedJobDataMap().getString(INPUT)) | ||
.findFirst() | ||
.orElse(""); | ||
|
||
return objectMapper.readValueUnchecked(input, klass); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
restclient/src/main/java/com/box/l10n/mojito/rest/ThirdPartySyncAction.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,9 @@ | ||
package com.box.l10n.mojito.rest; | ||
|
||
public enum ThirdPartySyncAction { | ||
PUSH, | ||
PUSH_TRANSLATION, | ||
PULL, | ||
MAP_TEXTUNIT, | ||
PUSH_SCREENSHOT | ||
} |
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
Oops, something went wrong.