Skip to content

Commit

Permalink
Space placeholder for plural separator in ThirdPartySync
Browse files Browse the repository at this point in the history
  • Loading branch information
comunacho authored and aurambaj committed Aug 19, 2020
1 parent be28b59 commit 97a4abe
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void execute() throws Exception {
// 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 pluralSeparator = "%s_";
String skipTextUnitPattern = "%skip_text_pattern";
String skipAssetPattern = "%skip_asset_pattern%";
List<String> options = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class ThirdPartyService {

static Logger logger = LoggerFactory.getLogger(ThirdPartyService.class);

static final String PLURAL_SEPARATOR_SPACE = "%s";

@Autowired
TextUnitSearcher textUnitSearcher;

Expand Down Expand Up @@ -111,7 +113,13 @@ void syncMojitoWithThirdPartyTMS(Long repositoryId,
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern,
List<String> options) {
logger.debug("thirdparty TMS: {}", thirdPartyTMS);
pluralSeparator = replaceSpacePlaceholder(pluralSeparator);
logger.debug("Thirdparty TMS Sync: repositoryId={} thirdPartyProjectId={} " +
"actions={} pluralSeparator={} localeMapping={} " +
"skipTextUnitsWithPattern={} skipAssetsWithPattern={} " +
"options={}", repositoryId, thirdPartyProjectId, actions,
pluralSeparator, localeMapping, skipTextUnitsWithPattern,
skipAssetsWithPathPattern, options);

Repository repository = repositoryRepository.findById(repositoryId).orElse(null);

Expand Down Expand Up @@ -335,6 +343,10 @@ LoadingCache<String, Optional<Asset>> getAssetCache(Repository repository) {
})
);
}

String replaceSpacePlaceholder(String input) {
return input.replaceAll(PLURAL_SEPARATOR_SPACE, " ");
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,34 @@ public void testPushArguments() throws RepositoryNameAlreadyUsedException, Execu
assertThat(optionsArgumentCaptor.getValue()).contains("option1=value1", "option2=value2");
}

@Test
public void testPushArgumentsWithSpacePlaceholder() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException {
Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository"));

ThirdPartySync thirdPartySync = new ThirdPartySync();
thirdPartySync.setRepositoryId(repository.getId());
thirdPartySync.setProjectId("projectId");
thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.PUSH));
thirdPartySync.setPluralSeparator("%s_");
thirdPartySync.setSkipTextUnitsWithPattern("text_unit_pattern");
thirdPartySync.setSkipAssetsWithPathPattern("asset_path_pattern");
thirdPartySync.setOptions(Arrays.asList("option1=value1", "option2=value2"));
ArgumentCaptor<Repository> repoCaptor = ArgumentCaptor.forClass(Repository.class);

thirdPartyService.asyncSyncMojitoWithThirdPartyTMS(thirdPartySync).get();

verify(thirdPartyTMSMock, only()).push(
repoCaptor.capture(),
eq("projectId"),
eq(" _"),
eq("text_unit_pattern"),
eq("asset_path_pattern"),
optionsArgumentCaptor.capture());

assertThat(repoCaptor.getValue().getId()).isEqualTo(repository.getId());
assertThat(optionsArgumentCaptor.getValue()).contains("option1=value1", "option2=value2");
}

@Test
public void testPushTranslationArguments() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException {
Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository"));
Expand Down Expand Up @@ -399,6 +427,38 @@ public void testPushTranslationArguments() throws RepositoryNameAlreadyUsedExcep
assertThat(optionsArgumentCaptor.getValue()).contains("option1=value1", "option2=value2");
}

@Test
public void testPushTranslationArgumentsWithSpacePlaceholder() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException {
Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository"));

String localeMapping = "ja:ja-JP";
ThirdPartySync thirdPartySync = new ThirdPartySync();
thirdPartySync.setRepositoryId(repository.getId());
thirdPartySync.setProjectId("projectId");
thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.PUSH_TRANSLATION));
thirdPartySync.setPluralSeparator("%s_");
thirdPartySync.setLocaleMapping(localeMapping);
thirdPartySync.setSkipTextUnitsWithPattern("text_unit_pattern");
thirdPartySync.setSkipAssetsWithPathPattern("asset_path_pattern");
thirdPartySync.setOptions(Arrays.asList("option1=value1", "option2=value2"));
ArgumentCaptor<Repository> repoCaptor = ArgumentCaptor.forClass(Repository.class);

thirdPartyService.asyncSyncMojitoWithThirdPartyTMS(thirdPartySync).get();

verify(thirdPartyTMSMock, only()).pushTranslations(
repoCaptor.capture(),
eq("projectId"),
eq(" _"),
localeMappingArgumentCaptor.capture(),
eq("text_unit_pattern"),
eq("asset_path_pattern"),
optionsArgumentCaptor.capture());

assertThat(repoCaptor.getValue().getId()).isEqualTo(repository.getId());
assertThat(localeMappingArgumentCaptor.getValue()).contains(entry("ja-JP", "ja"));
assertThat(optionsArgumentCaptor.getValue()).contains("option1=value1", "option2=value2");
}

@Test
public void testPullArguments() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException {
Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository"));
Expand All @@ -408,7 +468,39 @@ public void testPullArguments() throws RepositoryNameAlreadyUsedException, Execu
thirdPartySync.setRepositoryId(repository.getId());
thirdPartySync.setProjectId("projectId");
thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.PULL));
thirdPartySync.setPluralSeparator(" _");
thirdPartySync.setPluralSeparator("_");
thirdPartySync.setLocaleMapping(localeMapping);
thirdPartySync.setSkipTextUnitsWithPattern("text_unit_pattern");
thirdPartySync.setSkipAssetsWithPathPattern("asset_path_pattern");
thirdPartySync.setOptions(Arrays.asList("option1=value1", "option2=value2"));
ArgumentCaptor<Repository> repoCaptor = ArgumentCaptor.forClass(Repository.class);

thirdPartyService.asyncSyncMojitoWithThirdPartyTMS(thirdPartySync).get();

verify(thirdPartyTMSMock, only()).pull(
repoCaptor.capture(),
eq("projectId"),
eq("_"),
localeMappingArgumentCaptor.capture(),
eq("text_unit_pattern"),
eq("asset_path_pattern"),
optionsArgumentCaptor.capture());

assertThat(repoCaptor.getValue().getId()).isEqualTo(repository.getId());
assertThat(localeMappingArgumentCaptor.getValue()).contains(entry("ja-JP", "ja"));
assertThat(optionsArgumentCaptor.getValue()).contains("option1=value1", "option2=value2");
}

@Test
public void testPullArgumentsWithSpacePlaceholder() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException {
Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository"));

String localeMapping = "ja:ja-JP";
ThirdPartySync thirdPartySync = new ThirdPartySync();
thirdPartySync.setRepositoryId(repository.getId());
thirdPartySync.setProjectId("projectId");
thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.PULL));
thirdPartySync.setPluralSeparator("%s_");
thirdPartySync.setLocaleMapping(localeMapping);
thirdPartySync.setSkipTextUnitsWithPattern("text_unit_pattern");
thirdPartySync.setSkipAssetsWithPathPattern("asset_path_pattern");
Expand All @@ -431,6 +523,16 @@ public void testPullArguments() throws RepositoryNameAlreadyUsedException, Execu
assertThat(optionsArgumentCaptor.getValue()).contains("option1=value1", "option2=value2");
}

@Test
public void testReplaceSpacePlaceholder() {
assertThat(thirdPartyService.replaceSpacePlaceholder("%s_")).isEqualTo(" _");
assertThat(thirdPartyService.replaceSpacePlaceholder("_%s%")).isEqualTo("_ %");
assertThat(thirdPartyService.replaceSpacePlaceholder("_%ss")).isEqualTo("_ s");
assertThat(thirdPartyService.replaceSpacePlaceholder("%s-s")).isEqualTo(" -s");
assertThat(thirdPartyService.replaceSpacePlaceholder("%%ss")).isEqualTo("% s");
assertThat(thirdPartyService.replaceSpacePlaceholder("%s%s")).isEqualTo(" ");
}

ThirdPartyTextUnit createThirdPartyTextUnit(String assetPath, String id, String name) {
return createThirdPartyTextUnit(assetPath, id, name, false);
}
Expand Down

0 comments on commit 97a4abe

Please sign in to comment.