public LocalizedStringAssert doesNotContain(final Locale locale, final String value) { if (value.equals(actual.get(locale))) { failWithMessage(String.format("%s does contain an entry %s -> %s", actual, locale, value)); } return this; } }
private Map<LocalizedStringEntry, Category> getLocalizedStringEntryCategoryMap(final List<Category> allCategoriesAsFlatList) { final Map<LocalizedStringEntry, Category> categoriesByLocaleAndSlug = new HashMap<>(); allCategoriesAsFlatList.forEach(category -> { final Set<Locale> localesForTheCategory = category.getSlug().getLocales(); localesForTheCategory.forEach(locale -> { final LocalizedStringEntry stringsEntry = LocalizedStringEntry.of(locale, category.getSlug().get(locale)); categoriesByLocaleAndSlug.put(stringsEntry, category); }); }); return categoriesByLocaleAndSlug; }
public LocalizedStringAssert contains(final Locale locale, final String value) { if (!value.equals(actual.get(locale))) { failWithMessage(String.format("%s does not contain an entry %s -> %s", actual, locale, value)); } return this; }
private static Map<LocaleSlugPair, Category> buildBySlugMap(final Collection<Category> categories) { final Map<LocaleSlugPair, Category> map = new HashMap<>(); for (final Category category : categories) { for (final Locale locale : category.getSlug().getLocales()) { map.put(new LocaleSlugPair(locale, category.getSlug().get(locale).get()), category); } } return map; }
public LocalizedStringAssert contains(final Locale locale, final String value) { if (!value.equals(actual.get(locale).orElse(null))) { failIfCustomMessageIsSet(); throw failure(String.format("%s does not contain an entry %s -> %s", actual, locale, value)); } return this; }
@Test public void createFromTwoValues() throws Exception { final LocalizedString ls = LocalizedString.of(Locale.GERMAN, "Hundefutter", Locale.ENGLISH, "dog food"); assertThat(ls.getLocales()).containsExactly(Locale.GERMAN, Locale.ENGLISH); assertThat(ls.get(Locale.GERMAN)).isEqualTo("Hundefutter"); assertThat(ls.get(Locale.ENGLISH)).isEqualTo("dog food"); }
public LocalizedStringAssert doesNotContain(final Locale locale, final String value) { if (value.equals(actual.get(locale).orElse(null))) { failIfCustomMessageIsSet(); throw failure(String.format("%s does contain an entry %s -> %s", actual, locale, value)); } return this; } }
@Test public void getByOneLocale() { final LocalizedString ls = LocalizedString.of(Locale.GERMAN, "Hundefutter"); final String germanTranslation = ls.get(Locale.GERMAN); assertThat(germanTranslation).isNotNull().isEqualTo("Hundefutter"); final String englishTranslation = ls.get(Locale.ENGLISH); assertThat(englishTranslation).isNull(); }
@Test public void slugExistsExample() { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().bySlug(ENGLISH, SLUG1); testResult(search, result -> { final List<ProductProjection> results = result.getResults(); assertThat(results.size()).isEqualTo(1); assertThat(results.get(0).getSlug().get(ENGLISH)).isEqualTo(SLUG1); }); }
@Test public void isGreaterThanOrEqualToComparisonPredicate() throws Exception { final QueryPredicate<Category> predicate = CategoryQueryModel.of().name().lang(Locale.ENGLISH).isGreaterThanOrEqualTo("x10"); final Consumer<List<Category>> assertions = categories -> { final List<String> names = categories.stream().map(c -> c.getName().get(Locale.ENGLISH)).collect(toList()); assertThat(names).contains("x2", "x10"); assertThat(names.contains("x1")).isFalse(); }; predicateTestCase(predicate, assertions); }
@Test public void fetchAll() throws Exception { final CompletionStage<List<Category>> categoriesStage = QueryExecutionUtils.queryAll(client(), CategoryQuery.of(), 500); final List<Category> categories = SphereClientUtils.blockingWait(categoriesStage, Duration.ofMinutes(1)); assertThat(categories) .hasSize(15) .matches(cats -> cats.parallelStream().anyMatch(cat -> cat.getSlug().get(ENGLISH).equals("boots-women"))); }
@Test public void fetchAll_withMapper() throws Exception { final CompletionStage<List<Category>> categoriesStage = QueryExecutionUtils .queryAll(client(), CategoryQuery.of(), category -> category, 500); final List<Category> categories = SphereClientUtils .blockingWait(categoriesStage, Duration.ofMinutes(1)); assertThat(categories) .hasSize(15) .matches(cats -> cats.parallelStream().anyMatch(cat -> cat.getSlug().get(ENGLISH).equals("boots-women"))); }
@Test public void createByJson() { final ProductDiscountDraft productDiscountDraft = SphereJsonUtils.readObjectFromResource("drafts-tests/productDiscount.json", ProductDiscountDraft.class); withProductDiscount(client(), productDiscountDraft, productDiscount -> { assertThat(productDiscount.getName().get(ENGLISH)).isEqualTo("example product discount"); assertThat(productDiscount.getValue()).isEqualTo(ProductDiscountValue.ofAbsolute(EURO_20)); assertThat(productDiscount.isActive()).isTrue(); }); } }
@Test public void slugifyUniqueRespectsAllowedLength() { final int allowedLength = 256; final String tooLongString = StringUtils.repeat("a", allowedLength + 1); assertThat(tooLongString).hasSize(allowedLength + 1); final String actual = LocalizedString.ofEnglish(tooLongString).slugifiedUnique().get(Locale.ENGLISH); assertThat(actual).hasSize(allowedLength).matches("a{247}-\\d{8}"); }
@Test public void onLocTextAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofLocalizedString(ATTR_NAME_LOC_TEXT).locale(ENGLISH).allTerms(), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_TEXT_FOO.get(ENGLISH), 1L), TermStats.of(LOC_TEXT_BAR.get(ENGLISH), 1L))); }
@Test public void changeName() throws Exception { withUpdateableShoppingList(client(), shoppingList -> { final String newName = randomString(); final ShoppingList updatedShoppingList = client().executeBlocking( ShoppingListUpdateCommand.of(shoppingList, ChangeName.of(en(newName)))); assertThat(updatedShoppingList.getName().get(Locale.ENGLISH)).isEqualTo(newName); return updatedShoppingList; }); }
@Test public void onLocTextSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedStringSet(ATTR_NAME_LOC_TEXT_SET).locale(ENGLISH).is(LOC_TEXT_BAR.get(ENGLISH)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onLocTextAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedString(ATTR_NAME_LOC_TEXT).locale(ENGLISH).is(LOC_TEXT_FOO.get(ENGLISH)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onLocEnumLabelAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).is(LOC_ENUM_TWO.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void queryBySlug() throws Exception { with2products("queryBySlug", (p1, p2) ->{ final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED).bySlug(ENGLISH, p1.getMasterData().getStaged().getSlug().get(ENGLISH)); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId()); }); }