Search in sources :

Example 6 with SeoTags

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

the class PageImplTest method testRobotsTags.

@Test
public void testRobotsTags() {
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        String[] robotsTags = resource.getValueMap().get(SeoTags.PN_ROBOTS_TAGS, new String[0]);
        when(seoTags.getRobotsTags()).thenReturn(Arrays.asList(robotsTags));
        return seoTags;
    });
    Page page = getPageUnderTest(PAGE);
    List<String> robotsTags = page.getRobotsTags();
    assertEquals(2, robotsTags.size());
    assertThat(page.getRobotsTags(), hasItems("index", "nofollow"));
    // assert that the returned object is cached by the instance
    assertSame(robotsTags, page.getRobotsTags());
}
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 7 with SeoTags

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

the class PageImpl method getCanonicalLink.

@Override
@Nullable
public String getCanonicalLink() {
    if (this.canonicalUrl == null) {
        String canonicalUrl;
        try {
            SeoTags seoTags = resource.adaptTo(SeoTags.class);
            canonicalUrl = seoTags != null ? seoTags.getCanonicalUrl() : null;
        } catch (NoClassDefFoundError ex) {
            canonicalUrl = null;
        }
        this.canonicalUrl = canonicalUrl != null ? canonicalUrl : linkHandler.getLink(currentPage).map(Link::getExternalizedURL).orElse(null);
    }
    return canonicalUrl;
}
Also used : SeoTags(com.adobe.aem.wcm.seo.SeoTags) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with SeoTags

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

the class PageImplTest method testCanonicalLink.

@Test
public void testCanonicalLink() {
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        when(seoTags.getCanonicalUrl()).thenReturn("http://foo.bar" + resource.getParent().getPath() + ".html");
        return seoTags;
    });
    Page page = getPageUnderTest(PAGE);
    String canonicalLink = page.getCanonicalLink();
    assertEquals("http://foo.bar/content/page/templated-page.html", canonicalLink);
    // assert that the returned object is cached by the instance
    assertSame(canonicalLink, 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 9 with SeoTags

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

the class PageImplTest method testRobotsTagsEmptyWhenSeoApiUnavailable.

@Test
public void testRobotsTagsEmptyWhenSeoApiUnavailable() {
    context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
        SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
        doThrow(new NoClassDefFoundError()).when(seoTags).getRobotsTags();
        return seoTags;
    });
    Page page = getPageUnderTest(PAGE);
    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 10 with SeoTags

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

the class PageImpl method getRobotsTags.

@Override
@NotNull
public List<String> getRobotsTags() {
    if (robotsTags == null) {
        try {
            SeoTags seoTags = resource.adaptTo(SeoTags.class);
            robotsTags = seoTags != null && seoTags.getRobotsTags().size() > 0 ? Collections.unmodifiableList(seoTags.getRobotsTags()) : Collections.emptyList();
        } catch (NoClassDefFoundError ex) {
            robotsTags = Collections.emptyList();
        }
    }
    return robotsTags;
}
Also used : SeoTags(com.adobe.aem.wcm.seo.SeoTags) NotNull(org.jetbrains.annotations.NotNull)

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