Hi everyone, I was trying to create a Junit test for my ImagePlus component, an image to which I added a getName. I initialized the test in setUp like so:
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
class ImagePlusTest {
private final AemContext ctx = new AemContext();
private ImagePlus image;
@Mock
private ModelFactory modelFactory;
@BeforeEach
void setup() {
ctx.addModelsForClasses(ImagePlus.class);
ctx.load().json("mypath/ImagePlusTest.json", "/content");
ctx.registerService(ModelFactory.class, modelFactory, Constants.SERVICE_RANKING, Integer.MAX_VALUE);
ctx.currentResource("/content/image");
image = ctx.request().adaptTo(ImagePlus.class);
}
I don't understand why the image is set to null in the adapter. I've read that it might be that the implementation doesn't support the target type, but what can I do in this case? How do I see which types are supported or not?
Solved! Go to Solution.
Views
Replies
Total Likes
I solved it by myself, the problem was in how to initialize a resource via the referenced Json file. All the fields that the image needs to be inserted into the environment must be entered
Hi Santosh, it has this
(adaptables = SlingHttpServletRequest.class
@Model(adaptables = {SlingHttpServletRequest.class, Resource.class})
Should work, try this and let us know.
Views
Replies
Total Likes
Sorry, Nothing change.
Views
Replies
Total Likes
Hi @Jacket97 ,
please add your Implementation class to your context,
ctx.addModelsForClasses(ImagePlus.class)
to ctx.addModelsForClasses(ImagePlusImpl.class).
Thanks,
Sravan
I solved it by myself, the problem was in how to initialize a resource via the referenced Json file. All the fields that the image needs to be inserted into the environment must be entered
Views
Likes
Replies
Views
Like
Replies