Search in sources :

Example 31 with DataSource

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

the class AbstractContentFragmentDataSourceServletTest method getDataSource.

/**
 * Calls the servlet with the specified datasource resource and returns the resulting datasource.
 */
DataSource getDataSource(AbstractContentFragmentDataSourceServlet servlet, String name) throws ServletException, IOException {
    // get datasource resource
    ResourceResolver resolver = context.resourceResolver();
    Resource dataSource = resolver.getResource(DATASOURCES_PATH + "/" + name);
    // mock the request and request resource
    Resource resource = mock(Resource.class);
    when(resource.getChild(Config.DATASOURCE)).thenReturn(dataSource);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resolver, context.bundleContext());
    request.setResource(resource);
    // call the servlet
    servlet.doGet(request, new MockSlingHttpServletResponse());
    // return the resulting datasource
    return (DataSource) request.getAttribute(DataSource.class.getName());
}
Also used : MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.servlethelpers.MockSlingHttpServletResponse) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Example 32 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 testComponentPathStructuredDisplayModeSingle.

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

Example 33 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 testFragmentPathOverride.

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

Example 34 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 testComponentPathInvalidFragmentPath.

@Test
void testComponentPathInvalidFragmentPath() throws ServletException, IOException {
    DataSource dataSource = getDataSource(servlet, DS_COMPONENT_PATH_INVALID_FRAGMENT_PATH);
    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 35 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 testFragmentPathInvalid.

@Test
void testFragmentPathInvalid() throws ServletException, IOException {
    DataSource dataSource = getDataSource(servlet, DS_FRAGMENT_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)

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