Search in sources :

Example 1 with SeoTags

use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImplTest method testCanonicalLinkWhenSeoApiUnavailable.

@Test
public void testCanonicalLinkWhenSeoApiUnavailable() {
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        doThrow(new NoClassDefFoundError()).when(seoTags).getCanonicalUrl();
        return seoTags;
    });
    Page page = getPageUnderTest(PAGE);
    assertEquals("https://example.org/content/page/templated-page.html", page.getCanonicalLink());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) Arrays(java.util.Arrays) Constants(org.osgi.framework.Constants) MockPersistenceStrategy(com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Page(com.adobe.cq.wcm.core.components.models.Page) HashMap(java.util.HashMap) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) Calendar(java.util.Calendar) NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Utils.testJSONExport(com.adobe.cq.wcm.core.components.Utils.testJSONExport) Map(java.util.Map) Utils.getTestExporterJSONPath(com.adobe.cq.wcm.core.components.Utils.getTestExporterJSONPath) SeoTags(com.adobe.aem.wcm.seo.SeoTags) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) MockHtmlLibraryManager(com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager) MockProductInfoProvider(com.adobe.cq.wcm.core.components.testing.MockProductInfoProvider) ValueSource(org.junit.jupiter.params.provider.ValueSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Utils(com.adobe.cq.wcm.core.components.testing.Utils) Set(java.util.Set) Resource(org.apache.sling.api.resource.Resource) AemContextExtension(io.wcm.testing.mock.aem.junit5.AemContextExtension) Mockito.when(org.mockito.Mockito.when) Version(org.osgi.framework.Version) MockContextAwareConfig(org.apache.sling.testing.mock.caconfig.MockContextAwareConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) SeoTags(com.adobe.aem.wcm.seo.SeoTags) Resource(org.apache.sling.api.resource.Resource) Page(com.adobe.cq.wcm.core.components.models.Page) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with SeoTags

use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImplTest method testNoRobotsTags.

@Test
public void testNoRobotsTags() {
    Page page = getPageUnderTest(PAGE);
    // without adapter
    assertTrue(page.getRobotsTags().isEmpty());
    // with adapter
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        when(seoTags.getRobotsTags()).thenReturn(Collections.emptyList());
        return seoTags;
    });
    assertTrue(page.getRobotsTags().isEmpty());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) Arrays(java.util.Arrays) Constants(org.osgi.framework.Constants) MockPersistenceStrategy(com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Page(com.adobe.cq.wcm.core.components.models.Page) HashMap(java.util.HashMap) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) Calendar(java.util.Calendar) NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Utils.testJSONExport(com.adobe.cq.wcm.core.components.Utils.testJSONExport) Map(java.util.Map) Utils.getTestExporterJSONPath(com.adobe.cq.wcm.core.components.Utils.getTestExporterJSONPath) SeoTags(com.adobe.aem.wcm.seo.SeoTags) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) MockHtmlLibraryManager(com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager) MockProductInfoProvider(com.adobe.cq.wcm.core.components.testing.MockProductInfoProvider) ValueSource(org.junit.jupiter.params.provider.ValueSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Utils(com.adobe.cq.wcm.core.components.testing.Utils) Set(java.util.Set) Resource(org.apache.sling.api.resource.Resource) AemContextExtension(io.wcm.testing.mock.aem.junit5.AemContextExtension) Mockito.when(org.mockito.Mockito.when) Version(org.osgi.framework.Version) MockContextAwareConfig(org.apache.sling.testing.mock.caconfig.MockContextAwareConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) SeoTags(com.adobe.aem.wcm.seo.SeoTags) Resource(org.apache.sling.api.resource.Resource) Page(com.adobe.cq.wcm.core.components.models.Page) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SeoTags

use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImplTest method testNoAlternateLanguageLinks.

@Test
public void testNoAlternateLanguageLinks() {
    Page page = getPageUnderTest(PAGE, PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS, true);
    // without adapter
    assertTrue(page.getAlternateLanguageLinks().isEmpty());
    // with adapter
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        when(seoTags.getAlternateLanguages()).thenReturn(Collections.emptyMap());
        return seoTags;
    });
    assertTrue(page.getAlternateLanguageLinks().isEmpty());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) Arrays(java.util.Arrays) Constants(org.osgi.framework.Constants) MockPersistenceStrategy(com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Page(com.adobe.cq.wcm.core.components.models.Page) HashMap(java.util.HashMap) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) Calendar(java.util.Calendar) NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Utils.testJSONExport(com.adobe.cq.wcm.core.components.Utils.testJSONExport) Map(java.util.Map) Utils.getTestExporterJSONPath(com.adobe.cq.wcm.core.components.Utils.getTestExporterJSONPath) SeoTags(com.adobe.aem.wcm.seo.SeoTags) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) MockHtmlLibraryManager(com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager) MockProductInfoProvider(com.adobe.cq.wcm.core.components.testing.MockProductInfoProvider) ValueSource(org.junit.jupiter.params.provider.ValueSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Utils(com.adobe.cq.wcm.core.components.testing.Utils) Set(java.util.Set) Resource(org.apache.sling.api.resource.Resource) AemContextExtension(io.wcm.testing.mock.aem.junit5.AemContextExtension) Mockito.when(org.mockito.Mockito.when) Version(org.osgi.framework.Version) MockContextAwareConfig(org.apache.sling.testing.mock.caconfig.MockContextAwareConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) SeoTags(com.adobe.aem.wcm.seo.SeoTags) Resource(org.apache.sling.api.resource.Resource) Page(com.adobe.cq.wcm.core.components.models.Page) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SeoTags

use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImplTest method testAlternateLanguageLinksWhenSeoApiUnavailable.

@Test
public void testAlternateLanguageLinksWhenSeoApiUnavailable() {
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        doThrow(new NoClassDefFoundError()).when(seoTags).getAlternateLanguages();
        return seoTags;
    });
    Page page = getPageUnderTest(PAGE, PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS, true);
    assertTrue(page.getAlternateLanguageLinks().isEmpty());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) Arrays(java.util.Arrays) Constants(org.osgi.framework.Constants) MockPersistenceStrategy(com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Page(com.adobe.cq.wcm.core.components.models.Page) HashMap(java.util.HashMap) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) Calendar(java.util.Calendar) NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Utils.testJSONExport(com.adobe.cq.wcm.core.components.Utils.testJSONExport) Map(java.util.Map) Utils.getTestExporterJSONPath(com.adobe.cq.wcm.core.components.Utils.getTestExporterJSONPath) SeoTags(com.adobe.aem.wcm.seo.SeoTags) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) MockHtmlLibraryManager(com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager) MockProductInfoProvider(com.adobe.cq.wcm.core.components.testing.MockProductInfoProvider) ValueSource(org.junit.jupiter.params.provider.ValueSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Utils(com.adobe.cq.wcm.core.components.testing.Utils) Set(java.util.Set) Resource(org.apache.sling.api.resource.Resource) AemContextExtension(io.wcm.testing.mock.aem.junit5.AemContextExtension) Mockito.when(org.mockito.Mockito.when) Version(org.osgi.framework.Version) MockContextAwareConfig(org.apache.sling.testing.mock.caconfig.MockContextAwareConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) SeoTags(com.adobe.aem.wcm.seo.SeoTags) Resource(org.apache.sling.api.resource.Resource) Page(com.adobe.cq.wcm.core.components.models.Page) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SeoTags

use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImplTest method testAlternateLanguageLinks.

@ParameterizedTest(name = PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS + " = {0}")
@ValueSource(strings = { "true", "false" })
public void testAlternateLanguageLinks(String renderProperty) {
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        Map<Locale, String> expectedAlternates = ImmutableMap.of(Locale.ENGLISH, "http://foo.bar/content/en/templated-page", Locale.GERMAN, "http://foo.bar/content/de/templated-page");
        when(seoTags.getAlternateLanguages()).thenReturn(expectedAlternates);
        return seoTags;
    });
    boolean renderAlternateLanguages = Boolean.parseBoolean(renderProperty);
    Page page = getPageUnderTest(PAGE, PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS, renderProperty);
    Map<Locale, String> alternateLanguageLinks = page.getAlternateLanguageLinks();
    if (renderAlternateLanguages) {
        assertEquals(2, alternateLanguageLinks.size());
        assertEquals("http://foo.bar/content/en/templated-page", page.getAlternateLanguageLinks().get(Locale.ENGLISH));
        assertEquals("http://foo.bar/content/de/templated-page", page.getAlternateLanguageLinks().get(Locale.GERMAN));
    } else {
        assertTrue(alternateLanguageLinks.isEmpty());
    }
    // assert that the returned object is cached by the instance
    assertSame(alternateLanguageLinks, page.getAlternateLanguageLinks());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) Arrays(java.util.Arrays) Constants(org.osgi.framework.Constants) MockPersistenceStrategy(com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Page(com.adobe.cq.wcm.core.components.models.Page) HashMap(java.util.HashMap) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) Calendar(java.util.Calendar) NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Utils.testJSONExport(com.adobe.cq.wcm.core.components.Utils.testJSONExport) Map(java.util.Map) Utils.getTestExporterJSONPath(com.adobe.cq.wcm.core.components.Utils.getTestExporterJSONPath) SeoTags(com.adobe.aem.wcm.seo.SeoTags) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) MockHtmlLibraryManager(com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager) MockProductInfoProvider(com.adobe.cq.wcm.core.components.testing.MockProductInfoProvider) ValueSource(org.junit.jupiter.params.provider.ValueSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Utils(com.adobe.cq.wcm.core.components.testing.Utils) Set(java.util.Set) Resource(org.apache.sling.api.resource.Resource) AemContextExtension(io.wcm.testing.mock.aem.junit5.AemContextExtension) Mockito.when(org.mockito.Mockito.when) Version(org.osgi.framework.Version) MockContextAwareConfig(org.apache.sling.testing.mock.caconfig.MockContextAwareConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Locale(java.util.Locale) SeoTags(com.adobe.aem.wcm.seo.SeoTags) Resource(org.apache.sling.api.resource.Resource) Page(com.adobe.cq.wcm.core.components.models.Page) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SeoTags (com.adobe.aem.wcm.seo.SeoTags)11 Utils.getTestExporterJSONPath (com.adobe.cq.wcm.core.components.Utils.getTestExporterJSONPath)8 Utils.testJSONExport (com.adobe.cq.wcm.core.components.Utils.testJSONExport)8 HtmlPageItemsConfig (com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig)8 HtmlPageItem (com.adobe.cq.wcm.core.components.models.HtmlPageItem)8 NavigationItem (com.adobe.cq.wcm.core.components.models.NavigationItem)8 Page (com.adobe.cq.wcm.core.components.models.Page)8 MockHtmlLibraryManager (com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager)8 MockPersistenceStrategy (com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy)8 MockProductInfoProvider (com.adobe.cq.wcm.core.components.testing.MockProductInfoProvider)8 Utils (com.adobe.cq.wcm.core.components.testing.Utils)8 ClientLibrary (com.adobe.granite.ui.clientlibs.ClientLibrary)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 AemContextExtension (io.wcm.testing.mock.aem.junit5.AemContextExtension)8 ParseException (java.text.ParseException)8 SimpleDateFormat (java.text.SimpleDateFormat)8 Arrays (java.util.Arrays)8 Calendar (java.util.Calendar)8 Collections (java.util.Collections)8 HashMap (java.util.HashMap)8