Search in sources :

Example 11 with MockStyle

use of com.adobe.cq.wcm.core.components.context.MockStyle in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class BreadcrumbImplTest method testStartLevel.

@Test
public void testStartLevel() throws Exception {
    Resource resource = context.currentResource(CURRENT_PAGE + "/jcr:content/header/breadcrumb-start-level");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    underTest = context.request().adaptTo(Breadcrumb.class);
    checkBreadcrumbConsistency(new String[] { "Shirts", "Devi Sleeveless Shirt" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Breadcrumb(com.adobe.cq.wcm.core.components.models.Breadcrumb) Test(org.junit.Test)

Example 12 with MockStyle

use of com.adobe.cq.wcm.core.components.context.MockStyle in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class BreadcrumbImplTest method testBreadcrumbItems.

@Test
public void testBreadcrumbItems() throws Exception {
    Resource resource = context.currentResource(CURRENT_PAGE + "/jcr:content/header/breadcrumb");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    underTest = context.request().adaptTo(Breadcrumb.class);
    checkBreadcrumbConsistency(new String[] { "Women", "Devi Sleeveless Shirt" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Breadcrumb(com.adobe.cq.wcm.core.components.models.Breadcrumb) Test(org.junit.Test)

Example 13 with MockStyle

use of com.adobe.cq.wcm.core.components.context.MockStyle in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class BreadcrumbImplTest method testGetShowHidden.

@Test
public void testGetShowHidden() throws Exception {
    Resource resource = context.currentResource(CURRENT_PAGE + "/jcr:content/header/breadcrumb-show-hidden");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    underTest = context.request().adaptTo(Breadcrumb.class);
    checkBreadcrumbConsistency(new String[] { "Women", "Shirts", "Devi Sleeveless Shirt" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Breadcrumb(com.adobe.cq.wcm.core.components.models.Breadcrumb) Test(org.junit.Test)

Example 14 with MockStyle

use of com.adobe.cq.wcm.core.components.context.MockStyle in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class TitleImplTest method testGetTitleFromCurrentPageWithWrongElementInfo.

@Test
public void testGetTitleFromCurrentPageWithWrongElementInfo() {
    Resource resource = context.currentResource(TITLE_WRONGTYPE);
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    underTest = context.request().adaptTo(Title.class);
    assertNull(underTest.getType());
}
Also used : Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Title(com.adobe.cq.wcm.core.components.models.Title) Test(org.junit.Test)

Example 15 with MockStyle

use of com.adobe.cq.wcm.core.components.context.MockStyle in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImplTest method getPageUnderTest.

private Page getPageUnderTest(String pagePath, String designPath) {
    Resource resource = aemContext.currentResource(pagePath);
    com.day.cq.wcm.api.Page page = spy(aemContext.currentPage(pagePath));
    SlingBindings slingBindings = (SlingBindings) aemContext.request().getAttribute(SlingBindings.class.getName());
    Design design = mock(Design.class);
    if (designPath != null) {
        when(design.getPath()).thenReturn(designPath);
    } else {
        when(design.getPath()).thenReturn(Designer.DEFAULT_DESIGN_PATH);
    }
    Resource templateResource = aemContext.resourceResolver().getResource("/conf/coretest/settings/wcm/templates/product-page");
    Template template = mock(Template.class);
    when(template.hasStructureSupport()).thenReturn(true);
    when(template.adaptTo(Resource.class)).thenReturn(templateResource);
    when(page.getTemplate()).thenReturn(template);
    ContentPolicyMapping mapping = templateResource.getChild(POLICIES_MAPPING_PATH).adaptTo(ContentPolicyMapping.class);
    ContentPolicy contentPolicy = mapping.getPolicy();
    Style style;
    slingBindings.put(WCMBindings.CURRENT_DESIGN, design);
    if (contentPolicy != null) {
        Resource contentPolicyResource = aemContext.resourceResolver().getResource(contentPolicy.getPath());
        style = new MockStyle(contentPolicyResource, contentPolicyResource.adaptTo(ValueMap.class));
    } else {
        style = mock(Style.class);
        when(style.get(anyString(), Matchers.anyObject())).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[1]);
    }
    slingBindings.put(WCMBindings.CURRENT_STYLE, style);
    slingBindings.put(SlingBindings.RESOLVER, aemContext.request().getResourceResolver());
    slingBindings.put(WCMBindings.CURRENT_PAGE, page);
    slingBindings.put(WCMBindings.PAGE_MANAGER, aemContext.pageManager());
    slingBindings.put(SlingBindings.RESOURCE, resource);
    slingBindings.put(WCMBindings.PAGE_PROPERTIES, page.getProperties());
    MockSlingHttpServletRequest request = aemContext.request();
    request.setContextPath(CONTEXT_PATH);
    request.setResource(resource);
    return request.adaptTo(Page.class);
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) Resource(org.apache.sling.api.resource.Resource) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) Template(com.day.cq.wcm.api.Template) Design(com.day.cq.wcm.api.designer.Design) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Style(com.day.cq.wcm.api.designer.Style) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle)

Aggregations

MockStyle (com.adobe.cq.wcm.core.components.context.MockStyle)19 Resource (org.apache.sling.api.resource.Resource)19 Test (org.junit.Test)18 ValueMap (org.apache.sling.api.resource.ValueMap)15 List (com.adobe.cq.wcm.core.components.models.List)11 Breadcrumb (com.adobe.cq.wcm.core.components.models.Breadcrumb)4 Title (com.adobe.cq.wcm.core.components.models.Title)3 Hit (com.day.cq.search.result.Hit)1 SearchResult (com.day.cq.search.result.SearchResult)1 Template (com.day.cq.wcm.api.Template)1 Design (com.day.cq.wcm.api.designer.Design)1 Style (com.day.cq.wcm.api.designer.Style)1 ContentPolicy (com.day.cq.wcm.api.policies.ContentPolicy)1 ContentPolicyMapping (com.day.cq.wcm.api.policies.ContentPolicyMapping)1 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)1