Can any one help me with junit for the multifield model class for accordion:
@Model(adaptables = Resource.class)
public class Accordion {
// Inject the accordion node under the current node
@inject
@Deleted Account
public Resource accordion;
}
Regards,
Santosh
Solved! Go to Solution.
Views
Replies
Total Likes
Hi, unit test for Accordion will be like this->
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
public class AccordionTest {
private final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
private Accordion accordion;
@Mock
private ModelFactory modelFactory;
@BeforeEach
public void setUp() throws Exception {
context.addModelsForClasses(Accordion.class);
context.load().json("/com/java/components/accordion.json", "/content/accordion");
context.currentResource("/content/accordion");
context.registerService(ModelFactory.class, modelFactory, Constants.SERVICE_RANKING, Integer.MAX_VALUE);
accordion = context.currentResource().adaptTo(Accordion.class);
}
@Test
public void accordionModelTest() throws Exception {
assertNotNull(accordion);
}
}
In the resources, accordion.json should exist /com/java/components under this directory. accordion.json will contain json format of crx content node or:
{
"items": {
"item1": {
"title": "Career",
"link": "demo link"
},
"item2": {
"title": "Profession",
"link": "another demo link"
}
}
}
Hope it will help you...
Hi, unit test for Accordion will be like this->
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
public class AccordionTest {
private final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
private Accordion accordion;
@Mock
private ModelFactory modelFactory;
@BeforeEach
public void setUp() throws Exception {
context.addModelsForClasses(Accordion.class);
context.load().json("/com/java/components/accordion.json", "/content/accordion");
context.currentResource("/content/accordion");
context.registerService(ModelFactory.class, modelFactory, Constants.SERVICE_RANKING, Integer.MAX_VALUE);
accordion = context.currentResource().adaptTo(Accordion.class);
}
@Test
public void accordionModelTest() throws Exception {
assertNotNull(accordion);
}
}
In the resources, accordion.json should exist /com/java/components under this directory. accordion.json will contain json format of crx content node or:
{
"items": {
"item1": {
"title": "Career",
"link": "demo link"
},
"item2": {
"title": "Profession",
"link": "another demo link"
}
}
}
Hope it will help you...
Views
Replies
Total Likes