Search in sources :

Example 1 with EmbeddableDescription

use of com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class EmbeddablesDataSourceServletTest method setUp.

@BeforeEach
public void setUp() {
    context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, APPS_ROOT);
    Resource embeddable1 = Objects.requireNonNull(context.resourceResolver().getResource("/apps/my-app/youtube"));
    Resource embeddable2 = Objects.requireNonNull(context.resourceResolver().getResource("/apps/my-app/chatbot"));
    Resource embeddable3 = Objects.requireNonNull(context.resourceResolver().getResource("/apps/my-app/social"));
    embeddableResources.add(embeddable1);
    embeddableResources.add(embeddable2);
    embeddableResources.add(embeddable3);
    request = Mockito.spy(context.request());
    ResourceResolver resolver = Mockito.spy(context.resourceResolver());
    when(request.getResourceResolver()).thenReturn(resolver);
    final String rt = embeddable1.getPath().substring("/apps".length() + 1);
    List<Resource> outputResources = new ArrayList<>();
    outputResources.add(new EmbeddableDataResourceSource(new EmbeddableDescription(rt, embeddable1.getName(), embeddable1.getValueMap()), resolver));
    outputResources.add(new EmbeddableDataResourceSource(new EmbeddableDescription(rt, embeddable2.getName(), embeddable2.getValueMap()), resolver));
    context.request().setAttribute(DataSource.class.getName(), new SimpleDataSource(outputResources.iterator()));
    when(resolver.findResources(any(), any())).thenReturn(embeddableResources.iterator());
    when(resolver.getSearchPath()).thenReturn(context.resourceResolver().getSearchPath());
}
Also used : EmbeddableDescription(com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) Resource(org.apache.sling.api.resource.Resource) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) EmbeddableDataResourceSource(com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDataResourceSource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with EmbeddableDescription

use of com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class EmbedDesignTabsDataSourceServletTest method setUp.

@BeforeEach
public void setUp() {
    context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, APPS_ROOT);
    Resource embeddable1 = Objects.requireNonNull(context.resourceResolver().getResource("/apps/my-app/youtube"));
    Resource embeddable2 = Objects.requireNonNull(context.resourceResolver().getResource("/apps/my-app/chatbot"));
    Resource embeddable3 = Objects.requireNonNull(context.resourceResolver().getResource("/apps/my-app/social"));
    embeddableResources.add(embeddable1);
    embeddableResources.add(embeddable2);
    embeddableResources.add(embeddable3);
    context.currentResource("/apps/embed");
    request = Mockito.spy(context.request());
    ResourceResolver resolver = Mockito.spy(context.resourceResolver());
    when(request.getResourceResolver()).thenReturn(resolver);
    final String rt = embeddable1.getPath().substring("/apps".length() + 1);
    List<Resource> outputResources = new ArrayList<>();
    outputResources.add(new EmbeddableDataResourceSource(new EmbeddableDescription(rt, embeddable1.getName(), embeddable1.getValueMap()), resolver));
    outputResources.add(new EmbeddableDataResourceSource(new EmbeddableDescription(rt, embeddable2.getName(), embeddable2.getValueMap()), resolver));
    context.request().setAttribute(DataSource.class.getName(), new SimpleDataSource(outputResources.iterator()));
    when(resolver.findResources(any(), any())).thenReturn(embeddableResources.iterator());
    when(resolver.getSearchPath()).thenReturn(context.resourceResolver().getSearchPath());
}
Also used : EmbeddableDescription(com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) Resource(org.apache.sling.api.resource.Resource) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) EmbeddableDataResourceSource(com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDataResourceSource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with EmbeddableDescription

use of com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription 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 4 with EmbeddableDescription

use of com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class EmbedDesignTabsDataSourceServlet method getEmbedDesignTabs.

private List<Resource> getEmbedDesignTabs(@NotNull SlingHttpServletRequest request) {
    List<Resource> embedDesignTabs = new ArrayList<>();
    // first include static tabs below "firsttabs"
    Resource firstTabs = request.getResource().getChild("firsttabs");
    if (firstTabs != null) {
        firstTabs.getChildren().forEach(embedDesignTabs::add);
    }
    ResourceResolver resolver = request.getResourceResolver();
    // then dynamic tabs for embeddables
    for (EmbeddableDescription embeddableDescription : EmbeddablesDataSourceServlet.findEmbeddables(request.getResourceResolver())) {
        Resource embeddableDesignTab = resolver.getResource(embeddableDescription.getResourceType() + "/" + NN_DESIGN_DIALOG);
        if (embeddableDesignTab != null) {
            embedDesignTabs.add(embeddableDesignTab);
        }
    }
    // last include static tabs below "lasttabs"
    Resource lastTabs = request.getResource().getChild("lasttabs");
    if (lastTabs != null) {
        lastTabs.getChildren().forEach(embedDesignTabs::add);
    }
    return embedDesignTabs;
}
Also used : EmbeddableDescription(com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ResourceResolver(org.apache.sling.api.resource.ResourceResolver)

Aggregations

EmbeddableDescription (com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription)4 Resource (org.apache.sling.api.resource.Resource)4 DataSource (com.adobe.granite.ui.components.ds.DataSource)3 SimpleDataSource (com.adobe.granite.ui.components.ds.SimpleDataSource)3 ArrayList (java.util.ArrayList)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 EmbeddableDataResourceSource (com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDataResourceSource)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ValueMap (org.apache.sling.api.resource.ValueMap)1 Test (org.junit.jupiter.api.Test)1