My JUnit test is getting stuck in this section resourceResolver.getResource(filePath). My Mock AEM Context resource is having page path, its component details and in this section resourceResolver.getResource(filePath), I am trying to fetch an asset. How can I handle this?
Solved! Go to Solution.
Views
Replies
Total Likes
Sample code
@ExtendWith({ AemContextExtension.class, MockitoExtension.class }) public class SampleTest { private final AemContext aemContext = new AemContext(ResourceResolverType.JCR_MOCK); @Mock private Resource resource; @Mock private SlingHttpServletRequest request; @Mock private ResourceResolver resourceresolver; @BeforeEach void setUp() throws Exception { lenient().when(request.getResourceResolver()).thenReturn(resourceresolver); aemContext.addModelsForClasses(Sample.class); aemContext.load().json("/sample/component.json", "/content"); aemContext.load().json("/sample/assets.json", SAMPLE_DAM_PATH);
Mockito.when(resourceResolver.getResource(ASSET_PATH_FROM_JSON)).thenReturn(resource); } }
Sample code
@ExtendWith({ AemContextExtension.class, MockitoExtension.class }) public class SampleTest { private final AemContext aemContext = new AemContext(ResourceResolverType.JCR_MOCK); @Mock private Resource resource; @Mock private SlingHttpServletRequest request; @Mock private ResourceResolver resourceresolver; @BeforeEach void setUp() throws Exception { lenient().when(request.getResourceResolver()).thenReturn(resourceresolver); aemContext.addModelsForClasses(Sample.class); aemContext.load().json("/sample/component.json", "/content"); aemContext.load().json("/sample/assets.json", SAMPLE_DAM_PATH);
Mockito.when(resourceResolver.getResource(ASSET_PATH_FROM_JSON)).thenReturn(resource); } }
what will be the content structure for /sample/assets.json , considering assets (nt:file) will have rendition/original etc.
Because I need to adapt the asset original to input stream.
Views
Replies
Total Likes
Views
Likes
Replies