This is very frustrating. I am building an application using dropwizard and testing it with junit5 and the dropwizard-testing module (the junit5 version). Then, I am trying to test a simple endPoint in a resource. The endpoint receives a HttpSession (and the request) but it is always null. I have read a lot but I can not find how to inject the session.
This is my Resource:
@POST
@Path("/doStuff")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public String doStuff(@Session HttpSession session
, @Context HttpServletRequest request) {
// Do the stuff with the session and the request
}
My test is something like this:
@ExtendWith(DropwizardExtensionsSupport.class)
class MyResourceTest {
ResourceExtension resources = ResourceExtension.builder()
.addResource(new MyResource())
.build();
@BeforeEach
void setup() {
}
@Test
void testDoStuff() {
Response response = resources.target("/api/doStuff")
.request(MediaType.APPLICATION_FORM_URLENCODED)
.accept(MediaType.TEXT_HTML)
.post();
System.out.println(response);
}
}
I need to manipulate the session and the request by test. Is it possible? all help is appreciated.