@Test public void testPullNoBatches() throws RepositoryLocaleCreationException { ThirdPartyServiceTestData testData = new ThirdPartyServiceTestData(testIdWatcher); Repository repository = testData.repository; Map<String, String> localeMapping = Collections.emptyMap(); Locale frCA = localeService.findByBcp47Tag("fr-CA"); Locale jaJP = localeService.findByBcp47Tag("ja-JP"); repositoryService.addRepositoryLocale(repository, frCA.getBcp47Tag()); repositoryService.addRepositoryLocale(repository, jaJP.getBcp47Tag()); doReturn(singularContent(testData, frCA)).when(smartlingClient).downloadPublishedFile(eq("projectId"), eq(frCA.getBcp47Tag()), eq(singularFileName(repository, 0)), eq(false)); doReturn(singularContent(testData, jaJP)).when(smartlingClient).downloadPublishedFile(eq("projectId"), eq(jaJP.getBcp47Tag()), eq(singularFileName(repository, 0)), eq(false)); doReturn(pluralsContent(frCA)).when(smartlingClient).downloadPublishedFile(eq("projectId"), eq(frCA.getBcp47Tag()), eq(pluralFileName(repository, 0)), eq(false)); doReturn(pluralsContent(jaJP)).when(smartlingClient).downloadPublishedFile(eq("projectId"), eq(jaJP.getBcp47Tag()), eq(pluralFileName(repository, 0)), eq(false)); tmsSmartling = new ThirdPartyTMSSmartling(smartlingClient, textUnitSearcher, assetPathAndTextUnitNameKeys, mockTextUnitBatchImporterService, resultProcessor); tmsSmartling.pull(repository, "projectId", pluralSep, localeMapping, null, null, Collections.emptyList()); verify(mockTextUnitBatchImporterService, times(4)).importTextUnits( textUnitListCaptor.capture(), eq(false), eq(true)); List<List<TextUnitDTO>> captured = textUnitListCaptor.getAllValues(); String assetPath = "src/main/res/values/strings.xml"; assertThat(captured.subList(0,2).stream().flatMap(List::stream)) .extracting("name", "comment", "target", "assetPath", "targetLocale", "repositoryName") .containsExactlyInAnyOrder( tuple("hello", "comment 1", "Hello in ja-JP", assetPath, "ja-JP", repository.getName()), tuple("bye", "comment 2", "Bye in ja-JP", assetPath, "ja-JP", repository.getName()), tuple("hello", "comment 1", "Hello in fr-CA", assetPath, "fr-CA", repository.getName()), tuple("bye", "comment 2", "Bye in fr-CA", assetPath, "fr-CA", repository.getName())); assertThat(captured.subList(2,4).stream().flatMap(List::stream)) .extracting("name", "target", "pluralForm", "assetPath", "targetLocale", "repositoryName") .containsExactlyInAnyOrder( tuple("plural_things _one", "One thing in ja-JP", "one", assetPath, "ja-JP", repository.getName()), tuple("plural_things _few", "Few things in ja-JP", "few", assetPath, "ja-JP", repository.getName()), tuple("plural_things _other", "Other things in ja-JP", "other", assetPath, "ja-JP", repository.getName()), tuple("plural_things _one", "One thing in fr-CA", "one", assetPath, "fr-CA", repository.getName()), tuple("plural_things _few", "Few things in fr-CA", "few", assetPath, "fr-CA", repository.getName()), tuple("plural_things _other", "Other things in fr-CA", "other", assetPath, "fr-CA", repository.getName())); }
@Override public void pull(Repository repository, String projectId, String pluralSeparator, Map<String, String> localeMapping, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); Long singulars = singularCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(singulars)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.SINGULAR)); Long plurals = pluralCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(plurals)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.PLURAL)); }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void pull(Repository repository, String projectId, String pluralSeparator, Map<String, String> localeMapping, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); Long singulars = singularCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(singulars)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.SINGULAR)); Long plurals = pluralCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(plurals)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.PLURAL)); } }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void pull(Repository repository, String projectId, String pluralSeparator, Map<String, String> localeMapping, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); Long singulars = singularCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(singulars)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.SINGULAR)); Long plurals = pluralCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(plurals)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.PLURAL)); } @Autowired  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor);  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor,
                                  int batchSize); }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void pull(Repository repository, String projectId, String pluralSeparator, Map<String, String> localeMapping, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); Long singulars = singularCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(singulars)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.SINGULAR)); Long plurals = pluralCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(plurals)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.PLURAL)); } @Autowired  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor);  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor,
                                  int batchSize); @Override ThirdPartyTMSImage uploadImage(String projectId, String name, byte[] content); @Override List<ThirdPartyTextUnit> getThirdPartyTextUnits(Repository repository, String projectId); @Override void createImageToTextUnitMappings(String projectId, List<ThirdPartyImageToTextUnit> thirdPartyImageToTextUnits); @Override void push(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pull(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     Map<String, String> localeMapping,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pushTranslations(Repository repository,
                                 String projectId,
                                 String pluralSeparator,
                                 Map<String, String> localeMapping,
                                 String skipTextUnitsWithPattern,
                                 String skipAssetsWithPathPattern,
                                 List<String> optionList); }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void pull(Repository repository, String projectId, String pluralSeparator, Map<String, String> localeMapping, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); Long singulars = singularCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(singulars)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.SINGULAR)); Long plurals = pluralCount(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern); LongStream.range(0, batchesFor(plurals)) .forEach(num -> processPullBatch(num, pluralSeparator, repository, projectId, options, localeMapping, Prefix.PLURAL)); } @Autowired  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor);  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor,
                                  int batchSize); @Override ThirdPartyTMSImage uploadImage(String projectId, String name, byte[] content); @Override List<ThirdPartyTextUnit> getThirdPartyTextUnits(Repository repository, String projectId); @Override void createImageToTextUnitMappings(String projectId, List<ThirdPartyImageToTextUnit> thirdPartyImageToTextUnits); @Override void push(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pull(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     Map<String, String> localeMapping,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pushTranslations(Repository repository,
                                 String projectId,
                                 String pluralSeparator,
                                 Map<String, String> localeMapping,
                                 String skipTextUnitsWithPattern,
                                 String skipAssetsWithPathPattern,
                                 List<String> optionList);  }