I am trying the below java code
Java code
directContext, indirectContext);
junit code
@ExtendWith(AemContextExtension.class)
class CreatesampleServletTest {
private final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
@InjectMocks
private CreatesampleServlet createsample = new CreatesampleServlet();
@Mock
private MockSlingHttpServletRequest request;
@Mock
private MockSlingHttpServletResponse response;
@Mock
private ResourceResolver resourceResolver;
@Mock
private Session session;
@BeforeEach
void setUp() throws Exception {
request = context.request();
response = context.response();
resourceResolver = context.request().getResourceResolver();
context.registerAdapter(ResourceResolver.class, Session.class, session);
context.request().setQueryString("sourcePath =/content/dam/demo/sampleimage&baselinetitle=sample&label=label");
}
@test
void test_post() throws ServletException, IOException {
createsample.doPost(request,response);
assertEquals("sample",response.getOutputAsString());
}
Solved! Go to Solution.
Views
Replies
Total Likes
@djohn98390536 : I have shared the code for the class "DxmlInvalidResourceException.java". As mentioned in my previous comment you can add code for this class in your project to resolve the reference in JUnit.
I hope this helps
@djohn98390536 : I can reproduce the issue and acknowledge that the API itself is injecting dependency to a internal class that is not exposed in the API jar - hence it is giving compile time exception.
I have raised a request (GUIDES-18857) to remove dependency of such internal class from the API jar.
For now, for you to compile the JUnit we can provide code for the class "DxmlInvalidResourceException*" which you can create under your project and use it only for compilation.
* this class only logs the error
Thanks @DivrajSingh for the reply .It will be helpful if u can provide junit sample code to compile.
@djohn98390536 : I have shared the code for the class "DxmlInvalidResourceException.java". As mentioned in my previous comment you can add code for this class in your project to resolve the reference in JUnit.
I hope this helps
@djohn98390536 : were you able to review the code I shared in direct message? Did that help resolving the issue?