Skip to main content
Level 2
November 25, 2024
Solved

MockSlingHttpServletRequest how to set a selector

Hi, 

I want to write a Testcase for my Servlet, which expects a specific selector.

So far I ve always created my MockSlingHttpServletRequest request object using AemContext context.request().

However, I have nt found any method which might allow me to set a selector for it ?

Would be great if you could share an example setting a selector.

thanks a lot for your support in advance.

 

--

Volker

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
Community Advisor
November 25, 2024

2 replies

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
November 25, 2024
Ritesh_Mittal
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
November 25, 2024

Hi @vhochsteintef ,

 

To set a selector in a MockSlingHttpServletRequest for your AEM servlet test, you can use the setSelectorString() method. Here's a brief example:

 

MockSlingHttpServletRequest request = context.request();

request.setSelectorString("myselector");

// Your servlet logic here

servlet.doGet(request, context.response());

 

// Verify the selector

assertEquals("myselector", request.getRequestPathInfo().getSelectorString());

 

 

This will set the selector to "myselector" and you can then use it in your test.

 

Thanks

Ritesh Mittal

Translate