Hi Arun,
Below is the snippet of my model class
@Model(
adaptables = SlingHttpServletRequest.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class LocationsModel extends ComponentModel implements Validatable {
private static final Logger log = LoggerFactory.getLogger(LocationsModel.class);
private static final String CSS_CLASS_NAME = "dover-locations";
@OSGiService
private GoogleMapAPIConfiguration mapAPIConfiguration;
@ValueMapValue
private String title;
@ValueMapValue
private int zoomLevel;
@ChildResourceFromRequest
private final List<LocationItem> locations = emptyList();
private String locationsJson;
private String key;
if you see the above code if we remove @ChildResourceFromRequest annotation then I am able to get the LocationsModel object via adaptTo() in Test class
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
class LocationsModelTest {
public final AemContext ctx = new AemContext();
public LocationsModel locationsModel;
@BeforeEach
void setUp() throws Exception {
ctx.addModelsForClasses(LocationsModel.class);
ctx.load().json("/com/dovercorporation/core/models/components/content/utilities/LocationComponentTest.json", "/content");
}
@Test
void getTitle() {
ctx.currentResource("/content/location");
locationsModel = ctx.request().adaptTo(LocationsModel.class);
String expected = "dover-locations";
String actual = locationsModel.getTitle();
assertEquals(expected, actual);
}
}I am facing issue if my model class has multifield functionality for an example
in above case my model class
LocationsModel.java
public class LocationsModel extends ComponentModel implements Validatable {
@ChildResourceFromRequest
private final List<LocationItem> locations = emptyList();