ThirdPartyService { public PollableFuture<Void> asyncSyncMojitoWithThirdPartyTMS(ThirdPartySync thirdPartySync) { ThirdPartySyncJobInput thirdPartySyncJobInput = new ThirdPartySyncJobInput(); thirdPartySyncJobInput.setRepositoryId(thirdPartySync.getRepositoryId()); thirdPartySyncJobInput.setThirdPartyProjectId(thirdPartySync.getProjectId()); thirdPartySyncJobInput.setActions(thirdPartySync.getActions()); thirdPartySyncJobInput.setPluralSeparator(thirdPartySync.getPluralSeparator()); thirdPartySyncJobInput.setLocaleMapping(thirdPartySync.getLocaleMapping()); thirdPartySyncJobInput.setSkipTextUnitsWithPattern(thirdPartySync.getSkipTextUnitsWithPattern()); thirdPartySyncJobInput.setSkipAssetsWithPathPattern(thirdPartySync.getSkipAssetsWithPathPattern()); thirdPartySyncJobInput.setOptions(thirdPartySync.getOptions()); return quartzPollableTaskScheduler.scheduleJob(ThirdPartySyncJob.class, thirdPartySyncJobInput); }  PollableFuture<Void> asyncSyncMojitoWithThirdPartyTMS(ThirdPartySync thirdPartySync);  }
@Test public void duplicatedNamesSubSequentMapping() throws ExecutionException, InterruptedException { ThirdPartyServiceTestData thirdPartyServiceTestData = new ThirdPartyServiceTestData(testIdWatcher); Repository repository = thirdPartyServiceTestData.repository; Asset asset = thirdPartyServiceTestData.asset; String projectId = "someProjectIdForTest"; logger.debug("Create mocks and data for tests"); doAnswer(invocation -> Arrays.asList( createThirdPartyTextUnit(asset.getPath(), "3rd-hello", "hello") )).doAnswer(invocation -> Arrays.asList( createThirdPartyTextUnit(asset.getPath(), "3rd-hello-duplicate", "hello") )).when(thirdPartyTMSMock).getThirdPartyTextUnits(any(), any()); doNothing().when(thirdPartyTMSMock).createImageToTextUnitMappings(any(), any()); logger.debug("Invoke function to test"); ThirdPartySync thirdPartySync = new ThirdPartySync(); thirdPartySync.setRepositoryId(repository.getId()); thirdPartySync.setProjectId(projectId); thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.MAP_TEXTUNIT)); thirdPartySync.setPluralSeparator(" _"); thirdPartySync.setOptions(new ArrayList<>()); thirdPartyService.asyncSyncMojitoWithThirdPartyTMS(thirdPartySync).get(); logger.debug("Verify states"); thirdPartyTextUnitRepository.findAll().stream() .filter(thirdPartyTextUnit -> thirdPartyTextUnit.getAsset().getId().equals(asset.getId())) .forEach(t -> { logger.debug("id:{}, asset: {}, ttuid: {}, ttuname:{}, tpid:{}", t.getId(), t.getAsset().getPath(), t.getTmTextUnit().getId(), t.getTmTextUnit().getName(), t.getThirdPartyId()); }); List<com.box.l10n.mojito.entity.ThirdPartyTextUnit> thirdPartyTextUnits = thirdPartyTextUnitRepository.findAll().stream() .filter(thirdPartyTextUnit -> thirdPartyTextUnit.getAsset().getId().equals(asset.getId())) .collect(toList()); assertEquals(1, thirdPartyTextUnits.size()); thirdPartyTextUnits.forEach(t -> assertEquals(asset.getId(), t.getAsset().getId())); assertEquals(thirdPartyServiceTestData.tmTextUnitHello.getId(), thirdPartyTextUnits.get(0).getTmTextUnit().getId()); assertEquals("3rd-hello", thirdPartyTextUnits.get(0).getThirdPartyId()); logger.debug("Invoke function to test - duplicate name"); thirdPartySync = new ThirdPartySync(); thirdPartySync.setRepositoryId(repository.getId()); thirdPartySync.setProjectId(projectId); thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.MAP_TEXTUNIT)); thirdPartySync.setPluralSeparator(" _"); thirdPartySync.setOptions(new ArrayList<>()); logger.debug("Verify states - duplicate name"); thirdPartyTextUnits = thirdPartyTextUnitRepository.findAll().stream() .filter(thirdPartyTextUnit -> thirdPartyTextUnit.getAsset().getId().equals(asset.getId())) .collect(toList()); assertEquals(1, thirdPartyTextUnits.size()); thirdPartyTextUnits.forEach(t -> assertEquals(asset.getId(), t.getAsset().getId())); assertEquals(thirdPartyServiceTestData.tmTextUnitHello.getId(), thirdPartyTextUnits.get(0).getTmTextUnit().getId()); assertEquals("3rd-hello", thirdPartyTextUnits.get(0).getThirdPartyId()); }
@Test public void testPushArguments() 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(" _"); 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 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")); 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(" _"); 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 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")); String localeMapping = "ja:ja-JP"; ThirdPartySync thirdPartySync = new ThirdPartySync(); thirdPartySync.setRepositoryId(repository.getId()); thirdPartySync.setProjectId("projectId"); thirdPartySync.setActions(Arrays.asList(ThirdPartySyncAction.PULL)); 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"); 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"); }