Search in sources :

Example 1 with AemContext

use of io.wcm.testing.mock.aem.junit5.AemContext in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentUtilsTest method getComponentExport.

@Test
public void getComponentExport() {
    // GIVEN
    AemContext slingContext = CoreComponentTestContext.newAemContext();
    slingContext.load().json(this.getClass().getResourceAsStream("foo.json"), "/foo");
    MockSlingHttpServletRequest slingHttpServletRequest = new MockSlingHttpServletRequest(slingContext.bundleContext());
    ComponentExporter componentExporter = new TestComponentExporter();
    ModelFactory modelFactory = Mockito.mock(ModelFactory.class);
    Mockito.when(modelFactory.getModelFromWrappedRequest(Mockito.any(), Mockito.any(), Mockito.eq(ComponentExporter.class))).thenReturn(componentExporter);
    // WHEN
    Map<String, ComponentExporter> exporterMap = ContentFragmentUtils.getComponentExporters(slingContext.resourceResolver().getResource("/foo").listChildren(), modelFactory, slingHttpServletRequest, null);
    // THEN
    Assertions.assertEquals(componentExporter, exporterMap.get("bar"));
    Assertions.assertEquals(componentExporter, exporterMap.get("qux"));
}
Also used : AemContext(io.wcm.testing.mock.aem.junit5.AemContext) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ComponentExporter(com.adobe.cq.export.json.ComponentExporter) ModelFactory(org.apache.sling.models.factory.ModelFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentExporter (com.adobe.cq.export.json.ComponentExporter)1 AemContext (io.wcm.testing.mock.aem.junit5.AemContext)1 ModelFactory (org.apache.sling.models.factory.ModelFactory)1 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)1 Test (org.junit.jupiter.api.Test)1