Is there anyway to bring web @Context into JUnit (CXF+Spring)
I am trying to create unit test environment to test RESTFul services (cfx+spring) in my dev environemnt. To test RESTFul Services, I require @Context within JUnit test cases. @Context should contain HttpRequest, HttpSession, ServletContext, ServletConfig and all other webserver related information.
I have setup the JUnit for the above, but when I run, @Context is coming as null. This could be because there is no webserver running and there is no @Context. I am just doubting whether there is a way to created sample web @Context and pass to JUnit. Any o开发者_JAVA百科ther ideas are welcome to bring web @Context into JUnit test cases.
You need to embed a web container.
Try for example Jetty as an embedded container.
This article contains useful information.
Spring has some help for mocking the web server environment and thus testing without a real web container. See these Spring Framework docs on testing to get started. I haven't used this in your context, but it may be helpful.
精彩评论