Search in sources :

Example 36 with DataSource

use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ElementsDataSourceServletTest method testComponentPathStructured.

@Test
void testComponentPathStructured() throws ServletException, IOException {
    DataSource dataSource = getDataSource(servlet, DS_COMPONENT_PATH_STRUCTURED);
    assertDataSource(dataSource, ELEMENT_NAMES, ELEMENT_TITLES);
}
Also used : DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 37 with DataSource

use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ElementsDataSourceServletTest method testComponentPathInvalid.

@Test
void testComponentPathInvalid() throws ServletException, IOException {
    DataSource dataSource = getDataSource(servlet, DS_COMPONENT_PATH_INVALID);
    assertDataSource(dataSource, new String[0], new String[0]);
}
Also used : DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 38 with DataSource

use of com.adobe.granite.ui.components.ds.DataSource 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 39 with DataSource

use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class EmbeddablesDataSourceServletTest method testEmbeddablesDataSourceServlet.

@Test
public void testEmbeddablesDataSourceServlet() {
    context.currentResource("/apps/embeddablesdatasource");
    EmbeddablesDataSourceServlet dataSourceServlet = new EmbeddablesDataSourceServlet();
    dataSourceServlet.doGet(request, context.response());
    DataSource dataSource = (com.adobe.granite.ui.components.ds.DataSource) request.getAttribute(DataSource.class.getName());
    assertNotNull(dataSource);
    Resource resource = dataSource.iterator().next();
    ValueMap valueMap = resource.getValueMap();
    assertEquals("YouTube", valueMap.get(TextValueDataResourceSource.PN_TEXT, String.class));
    assertEquals("my-app/youtube", valueMap.get(TextValueDataResourceSource.PN_VALUE, String.class));
    EmbeddableDescription embed1 = new EmbeddableDescription(null, embeddableResources.get(1).getName(), embeddableResources.get(1).getValueMap());
    EmbeddableDescription embed2 = new EmbeddableDescription(null, embeddableResources.get(0).getName(), embeddableResources.get(0).getValueMap());
    assertNotEquals(embed2, embed1);
    assertNotNull(embed1.hashCode());
}
Also used : EmbeddableDescription(com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 40 with DataSource

use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class VariationsDataSourceServletTest method testFragmentPathStructured.

@Test
void testFragmentPathStructured() throws ServletException, IOException {
    DataSource dataSource = getDataSource(servlet, DS_FRAGMENT_PATH_STRUCTURED);
    assertDataSource(dataSource, VARIATION_NAMES, VARIATION_TITLES);
}
Also used : DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Aggregations

DataSource (com.adobe.granite.ui.components.ds.DataSource)48 Test (org.junit.jupiter.api.Test)37 Resource (org.apache.sling.api.resource.Resource)14 SimpleDataSource (com.adobe.granite.ui.components.ds.SimpleDataSource)10 ValueMap (org.apache.sling.api.resource.ValueMap)6 EmptyDataSource (com.adobe.granite.ui.components.ds.EmptyDataSource)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 LinkedList (java.util.LinkedList)3 ValueMapResource (com.adobe.granite.ui.components.ds.ValueMapResource)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 DataSourceOption (com.adobe.acs.commons.wcm.datasources.DataSourceOption)1 ContentFragment (com.adobe.cq.dam.cfm.ContentFragment)1 CoreComponentTestContext (com.adobe.cq.wcm.core.components.context.CoreComponentTestContext)1 TextValueDataResourceSource (com.adobe.cq.wcm.core.components.internal.servlets.TextValueDataResourceSource)1 EmbeddableDescription (com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription)1 MockStyle (com.adobe.cq.wcm.core.components.testing.MockStyle)1 Config (com.adobe.granite.ui.components.Config)1 Value (com.adobe.granite.ui.components.Value)1