Expand my Community achievements bar.

SOLVED

In junit throwing exception java.lang.NoClassDefFoundError: com/adobe/guides/core/exception/DxmlInvalidResourceException

Avatar

Level 4

I am trying the below java code 

Java code

String sourcePath = request.getParameter("Path");
String baselinetitle = request.getParameter("baselinetitle ");
String label= request.getParameter("label");
ResourceResolver resolver = request.getResourceResolver();
Session session = resolver.adaptTo(Session.class);
String baselineDetails =BaselineUtils.createBaseline(session, sourcePath, baselineTitle, label,

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());
}

1 Accepted Solution

Avatar

Correct answer by
Employee

@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

 

View solution in original post

4 Replies

Avatar

Employee

@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

 

 

Avatar

Level 4

Thanks @DivrajSingh  for the reply .It will be helpful if u can provide junit sample code to compile.

Avatar

Correct answer by
Employee

@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

 

Avatar

Employee

@djohn98390536 : were you able to review the code I shared in direct message? Did that help resolving the issue?