Search in sources :

Example 1 with MockStyle

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

the class DownloadImplTest method testDownloadWithDefaultTitleType.

@Test
void testDownloadWithDefaultTitleType() {
    Resource mockResource = mock(Resource.class);
    Style mockStyle = new MockStyle(mockResource, new MockValueMap(mockResource));
    Download download = getDownloadUnderTest(DOWNLOAD_1, mockStyle);
    assertNull(download.getTitleType(), "Expected title type is not correct");
    Utils.testJSONExport(download, Utils.getTestExporterJSONPath(TEST_BASE, DOWNLOAD_FULLY_CONFIGURED));
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) Style(com.day.cq.wcm.api.designer.Style) Download(com.adobe.cq.wcm.core.components.models.Download) Test(org.junit.jupiter.api.Test)

Example 2 with MockStyle

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

the class AllowedEmbeddablesDataSourceServletTest method testAllowedEmbeddablesDesignDataSourceServlet.

@Test
public void testAllowedEmbeddablesDesignDataSourceServlet() {
    Designer designer = mock(Designer.class);
    context.registerAdapter(ResourceResolver.class, Designer.class, (Function<ResourceResolver, Designer>) input -> designer);
    Resource styleResource = context.resourceResolver().getResource("/apps/etc/designs/embed");
    MockStyle mockStyle = new MockStyle(styleResource, styleResource.getValueMap());
    when(designer.getStyle(any(Resource.class))).thenReturn(mockStyle);
    context.request().setAttribute(Value.CONTENTPATH_ATTRIBUTE, CURRENT_PATH);
    dataSourceServlet.doGet(context.request(), context.response());
    DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
    assertNotNull(dataSource);
    validateAllowedEmbeddables(dataSource, getExpectedAllowedEmbeddables(new String[][] { { "Select", "" }, { "Chatbot", "/apps/my-app/chatbot" }, { "Social", "/apps/my-app/social" } }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Iterator(java.util.Iterator) Designer(com.day.cq.wcm.api.designer.Designer) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) Resource(org.apache.sling.api.resource.Resource) Value(com.adobe.granite.ui.components.Value) AemContextExtension(io.wcm.testing.mock.aem.junit5.AemContextExtension) Mockito.when(org.mockito.Mockito.when) Function(java.util.function.Function) AemContext(io.wcm.testing.mock.aem.junit5.AemContext) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) DataSource(com.adobe.granite.ui.components.ds.DataSource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CoreComponentTestContext(com.adobe.cq.wcm.core.components.context.CoreComponentTestContext) TextValueDataResourceSource(com.adobe.cq.wcm.core.components.internal.servlets.TextValueDataResourceSource) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Designer(com.day.cq.wcm.api.designer.Designer) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 3 with MockStyle

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

the class DownloadImplTest method testDownloadWithHiddenTitleLink.

@Test
void testDownloadWithHiddenTitleLink() {
    Resource mockResource = mock(Resource.class);
    MockValueMap mockValueMap = new MockValueMap(mockResource);
    mockValueMap.put(Download.PN_HIDE_TITLE_LINK, true);
    Style mockStyle = new MockStyle(mockResource, mockValueMap);
    Download download = getDownloadUnderTest(DOWNLOAD_1, mockStyle);
    assertTrue(download.hideTitleLink(), "Expected title link to be hidden");
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) Style(com.day.cq.wcm.api.designer.Style) Download(com.adobe.cq.wcm.core.components.models.Download) Test(org.junit.jupiter.api.Test)

Aggregations

MockStyle (com.adobe.cq.wcm.core.components.testing.MockStyle)3 Resource (org.apache.sling.api.resource.Resource)3 Test (org.junit.jupiter.api.Test)3 Download (com.adobe.cq.wcm.core.components.models.Download)2 Style (com.day.cq.wcm.api.designer.Style)2 MockValueMap (org.apache.sling.testing.resourceresolver.MockValueMap)2 CoreComponentTestContext (com.adobe.cq.wcm.core.components.context.CoreComponentTestContext)1 TextValueDataResourceSource (com.adobe.cq.wcm.core.components.internal.servlets.TextValueDataResourceSource)1 Value (com.adobe.granite.ui.components.Value)1 DataSource (com.adobe.granite.ui.components.ds.DataSource)1 Designer (com.day.cq.wcm.api.designer.Designer)1 AemContext (io.wcm.testing.mock.aem.junit5.AemContext)1 AemContextExtension (io.wcm.testing.mock.aem.junit5.AemContextExtension)1 Iterator (java.util.Iterator)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1