use of org.apache.sling.models.factory.ModelFactory in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ClientLibrariesImplTest method testUtilsGetXFResourceTypes.
//
// Below are tests for the specific methods in com.adobe.cq.wcm.core.components.internal.Utils
//
@Test
void testUtilsGetXFResourceTypes() {
Resource xfResource = context.currentResource(EXPERIENCE_FRAGMENT_PATH);
ModelFactory modelFactory = mock(ModelFactory.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
Resource resource = (Resource) args[1];
String fragmentPath = resource.getValueMap().get("fragmentVariationPath", String.class);
ExperienceFragment experienceFragment = mock(ExperienceFragment.class);
when(experienceFragment.getLocalizedFragmentVariationPath()).thenReturn(fragmentPath);
return experienceFragment;
}).when(modelFactory).getModelFromWrappedRequest(any(SlingHttpServletRequest.class), any(Resource.class), eq(ExperienceFragment.class));
Set<String> resourceTypes = Utils.getXFResourceTypes(xfResource, context.request(), modelFactory);
Set<String> expectedResourceTypes = new HashSet<>(Arrays.asList("core/wcm/components/page/v2/page", "cq:Page", "core/wcm/components/teaser/v1/teaser", "wcm/foundation/components/responsivegrid"));
assertEquals(expectedResourceTypes, resourceTypes);
}
use of org.apache.sling.models.factory.ModelFactory in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class YouTubeImplTest method getYouTubeUnderTest.
private YouTubeImpl getYouTubeUnderTest(String resourcePath, Page page) {
Resource resource = context.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Did you forget to define test resource " + resourcePath + "?");
}
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(SlingBindings.REQUEST, request);
bindings.put(WCMBindingsConstants.NAME_CURRENT_PAGE, page);
bindings.put(WCMBindingsConstants.NAME_COMPONENT_CONTEXT, componentContext);
bindings.put(WCMBindingsConstants.NAME_PROPERTIES, resource.getValueMap());
((MockRequestPathInfo) request.getRequestPathInfo()).setResourcePath(resourcePath);
request.setResource(resource);
request.setAttribute(SlingBindings.class.getName(), bindings);
ModelFactory modelFactory = context.getService(ModelFactory.class);
YouTubeImpl youTubeImpl = (YouTubeImpl) modelFactory.createModel(request, YouTube.class);
return youTubeImpl;
}
use of org.apache.sling.models.factory.ModelFactory 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"));
}
use of org.apache.sling.models.factory.ModelFactory in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ClientLibrariesImplTest method testUtilsGetTemplateResourceTypes.
@Test
void testUtilsGetTemplateResourceTypes() {
Page page = context.currentPage(PAGE_WITH_TEMPLATE);
ModelFactory modelFactory = mock(ModelFactory.class);
Set<String> resourceTypes = Utils.getTemplateResourceTypes(page, context.request(), modelFactory);
Set<String> expectedResourceTypes = new HashSet<>(Arrays.asList("core/wcm/components/page/v2/page", "wcm/foundation/components/responsivegrid", "core/wcm/components/text/v1/text"));
assertEquals(expectedResourceTypes, resourceTypes);
}
Aggregations