@Test public void slugified() { final LocalizedString ls = LocalizedString.of(Locale.GERMAN, "Hundefutter", Locale.ENGLISH, "dog food"); assertThat(ls.slugified()) .isEqualTo(LocalizedString.of(Locale.GERMAN, "hundefutter", Locale.ENGLISH, "dog-food")); }
@Test public void defaultUseCases() { final LocalizedString ls = LocalizedString.of(Locale.GERMAN, "Hundefutter", Locale.ENGLISH, "dog food"); assertThat(ls.getTranslation(singletonList(Locale.US))).isEqualTo("dog food");//fuzzy search assertThat(ls.getTranslation(singletonList(Locale.ENGLISH))).isEqualTo("dog food");//strict search assertThat(ls.getLocales()).isEqualTo(new HashSet<>(asList(Locale.GERMAN, Locale.ENGLISH)));//inspecting locales assertThat(ls.slugified())//slugified values for urls .isEqualTo(LocalizedString.of(Locale.GERMAN, "hundefutter", Locale.ENGLISH, "dog-food")); final LocalizedString slugifiedUnique = ls.slugifiedUnique(); assertThat(slugifiedUnique.get(Locale.GERMAN)).matches("hundefutter-\\d+");//example: hundefutter-62899407 assertThat(slugifiedUnique.get(Locale.ENGLISH)).matches("dog-food-\\d+"); }
@Test public void slugify() throws Exception { final LocalizedString actual = LocalizedString.of(Locale.GERMAN, "Aa -A_", Locale.ENGLISH, "dog food").slugified(); final LocalizedString expected = LocalizedString.of(Locale.GERMAN, "aa-a_", Locale.ENGLISH, "dog-food"); assertThat(actual).isEqualTo(expected); }
@Test public void slugifyRespectsAllowedCharacters() { final String actual = LocalizedString.ofEnglish("Pick + Mix 18 Volt").slugified().get(Locale.ENGLISH); final String expected = "pick-mix-18-volt"; assertThat(actual).isEqualTo(expected); }
@Test public void slugifyRespectsAllowedLength() { final int allowedLength = 256; final String tooLongString = StringUtils.repeat("a", allowedLength - 1) + "bc"; assertThat(tooLongString).hasSize(allowedLength + 1); final String actual = LocalizedString.ofEnglish(tooLongString).slugified().get(Locale.ENGLISH); assertThat(actual).hasSize(allowedLength).endsWith("ab"); }
public static void withPersistentCategory(final BlockingSphereClient client, final Consumer<Category> user) { final String externalId = "persistent-category-id"; final Optional<Category> fetchedCategory = client.executeBlocking(CategoryQuery.of().byExternalId(externalId)).head(); final Category category = fetchedCategory.orElseGet(() -> { final LocalizedString name = en("name persistent-category-id"); final CategoryDraftBuilder catSupplier = CategoryDraftBuilder.of(name, name.slugified()).externalId(externalId); return client.executeBlocking(CategoryCreateCommand.of(catSupplier.build())); }); user.accept(category); }