From 97a4abed0235c03e085dbabf3cbdbc725a995558 Mon Sep 17 00:00:00 2001 From: Ignacio Machuca <4760146+comunacho@users.noreply.github.com> Date: Tue, 18 Aug 2020 19:52:38 -0700 Subject: [PATCH] Space placeholder for plural separator in ThirdPartySync --- .../command/ThirdPartySyncCommandTest.java | 2 +- .../service/thirdparty/ThirdPartyService.java | 14 ++- .../thirdparty/ThirdPartyServiceTest.java | 104 +++++++++++++++++- 3 files changed, 117 insertions(+), 3 deletions(-) diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommandTest.java index 982bac6380..076028a24f 100644 --- a/cli/src/test/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommandTest.java +++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommandTest.java @@ -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 options = Arrays.asList( diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java index 19607c9f30..15fd9c3d08 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java @@ -52,6 +52,8 @@ public class ThirdPartyService { static Logger logger = LoggerFactory.getLogger(ThirdPartyService.class); + static final String PLURAL_SEPARATOR_SPACE = "%s"; + @Autowired TextUnitSearcher textUnitSearcher; @@ -111,7 +113,13 @@ void syncMojitoWithThirdPartyTMS(Long repositoryId, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List 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); @@ -335,6 +343,10 @@ LoadingCache> getAssetCache(Repository repository) { }) ); } + + String replaceSpacePlaceholder(String input) { + return input.replaceAll(PLURAL_SEPARATOR_SPACE, " "); + } } diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTest.java index 6f7ae92ad0..cf45a3b8fc 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTest.java @@ -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 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")); @@ -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 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")); @@ -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 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"); @@ -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); }