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());
}
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());
}
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());
}
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;
}
Aggregations