Search in sources :

Example 16 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 testFragmentPathTextOnly.

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

Example 17 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 testAllowedEmbeddablesDataSourceServlet.

@Test
public void testAllowedEmbeddablesDataSourceServlet() {
    context.contentPolicyMapping("my-app/components/embed", Objects.requireNonNull(context.resourceResolver().getResource("/apps/conf/policy_1558011912823")).getValueMap());
    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 : DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 18 with DataSource

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

the class AllowedHeadingElementsDataSourceServletTest method testDataSource.

@Test
void testDataSource() throws Exception {
    context.contentPolicyMapping("core/wcm/components/title/v1/title", "type", "h3", AllowedHeadingElementsDataSourceServlet.PN_ALLOWED_TYPES, new String[] { "h3", "h4" });
    dataSourceServlet.doGet(context.request(), context.response());
    DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
    assertNotNull(dataSource);
    dataSource.iterator().forEachRemaining(resource -> {
        assertTrue(TextValueDataResourceSource.class.isAssignableFrom(resource.getClass()), "Expected class");
        TextValueDataResourceSource textValueDataResourceSource = (TextValueDataResourceSource) resource;
        assertTrue(textValueDataResourceSource.getText().matches("h[3|4]"), "Expected type in (h3, h4)");
        assertTrue(textValueDataResourceSource.getValue().matches("h[3|4]"), "Expected value in (h3, h4)");
        if (textValueDataResourceSource.getValue().equals("h3")) {
            assertTrue(textValueDataResourceSource.getSelected());
        } else {
            assertFalse(textValueDataResourceSource.getSelected());
        }
    });
}
Also used : DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 19 with DataSource

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

the class ClientLibraryCategoriesDataSourceServletTest method testDataSource.

@Test
public void testDataSource() throws Exception {
    context.currentResource("/apps/clientlibrarycategoriesinput");
    dataSourceServlet.doGet(context.request(), context.response());
    DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
    assertNotNull(dataSource);
    dataSource.iterator().forEachRemaining(resource -> {
        assertTrue(TextValueDataResourceSource.class.isAssignableFrom(resource.getClass()), "Expected class");
        TextValueDataResourceSource textValueDataResourceSource = (TextValueDataResourceSource) resource;
        assertTrue(Arrays.asList(CLIENTLIB_A_CATEGORIES[0], CLIENTLIB_B_CATEGORIES[0], CLIENTLIB_C_CATEGORIES[0]).contains(textValueDataResourceSource.getText()), "Expected type in (clientlib.a.jsonly, clientlib.b.cssonly, clientlib.c.jsandcss)");
        assertTrue(Arrays.asList(CLIENTLIB_A_CATEGORIES[0], CLIENTLIB_B_CATEGORIES[0], CLIENTLIB_C_CATEGORIES[0]).contains(textValueDataResourceSource.getValue()), "Expected value in (clientlib.a.jsonly, clientlib.b.cssonly, clientlib.c.jsandcss)");
    });
}
Also used : DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 20 with DataSource

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

the class ClientLibraryCategoriesDataSourceServletTest method testDataSourceTypeCSS.

@Test
public void testDataSourceTypeCSS() throws Exception {
    context.currentResource("/apps/clientlibrarycategoriesinputcss");
    dataSourceServlet.doGet(context.request(), context.response());
    DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
    assertNotNull(dataSource);
    dataSource.iterator().forEachRemaining(resource -> {
        assertTrue(TextValueDataResourceSource.class.isAssignableFrom(resource.getClass()), "Expected class");
        TextValueDataResourceSource textValueDataResourceSource = (TextValueDataResourceSource) resource;
        assertTrue(Arrays.asList(CLIENTLIB_B_CATEGORIES[0], CLIENTLIB_C_CATEGORIES[0]).contains(textValueDataResourceSource.getText()), "Expected type in (clientlib.b.cssonly, clientlib.c.jsandcss)");
        assertTrue(Arrays.asList(CLIENTLIB_B_CATEGORIES[0], CLIENTLIB_C_CATEGORIES[0]).contains(textValueDataResourceSource.getValue()), "Expected value in (clientlib.b.cssonly, clientlib.c.jsandcss)");
    });
}
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