Could not yet find an adapter factory for the model class my_class from adaptable class org.apache.sling.testing.resourceresolver.MockResource
Hi All,
I coudln't able to adapt the resource to my Sling Model class,
getting the error
Could not yet find an adapter factory for the model class my_class from adaptable class org.apache.sling.testing.resourceresolver.MockResource.
Attaching the Sling models and junit files here.
Model Interface
package com.mycore.core.models;
import org.apache.commons.lang.StringUtils;
public interface ConfiguratorPromptModel {
default String getNameplateId() {
return StringUtils.EMPTY;
}
}
Model Implementation
package com.mycore.core.internal.models.v1;
import com.mycore.core.models.ConfiguratorPromptModel;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
@Model(adaptables = Resource.class, adapters = {ConfiguratorPromptModel.class})
public class ConfiguratorPromptModelImpl implements ConfiguratorPromptModel {
public String getNameplateId() {
return nameplateId;
}
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String nameplateId;
}
Test Case
package com.mycore.core.internal.models.v1;
import com.mycore.core.models.ConfiguratorPromptModel;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.factory.ModelFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(AemContextExtension.class)
class ConfiguratorPromptModelImplTest {
private ConfiguratorPromptModel configuratorPromptModel;
@BeforeEach
public void setUp(AemContext context) throws Exception {
context.load().json("/content/configuratorprompt/configuratorprompt.json", "/content/configuratorprompt.html");
Resource resource = context.resourceResolver().getResource("/content/configuratorprompt.html");
this.configuratorPromptModel = context.getService(ModelFactory.class).createModel(resource, ConfiguratorPromptModelImpl.class);
}
void getNameplateId() {
assertEquals("nameplate", configuratorPromptModel.getNameplateId());
}
}
Thanks,
Gokulraj