-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port support for test framework application descriptors from Jersey 1.x #2531
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented
|
@glassfishrobot Commented
Can you try it in your case? |
@glassfishrobot Commented But I still think you can design your Application/ResourceConfig implementation to be testeable. Or what am I missing? Thanks for you response. |
@glassfishrobot Commented
Thanks. |
@glassfishrobot Commented |
@glassfishrobot Commented
So, point #1 is is I can't extend JerseyTest directly because it is JUnit-specific and I am using TestNG so my test code actually looks like this:
And point #2 is, I need to configure web.xml (by way of WebAppDescriptor) in order to pass TestModule and DebugModeModule (DI configurations) into the server. In Jersey 1.x I was using Grizzly for unit tests simply because I don't think Jetty is supported. I think Jetty would be a good substitute for Grizzly but I'd need to test. How do you propose migrating the above logic to Jersey 2.x? |
@glassfishrobot Commented And you can also configure other servlet classes via WebappContext (https://grizzly.java.net/docs/2.3/apidocs/org/glassfish/grizzly/servlet/WebappContext.html), e.g. how to register ServletContextListener implementation:
In such case you run the application as follows:
|
@glassfishrobot Commented For example you can start from servlet-2.5-init-1 integration test module (https://github.com/jersey/jersey/tree/master/tests/integration/servlet-2.5-init-1) and configure jetty-maven-plugin to use different web.xml during tests. Change pom.xml as follows:
And place your test-specific web.xml to src/test/webapp/WEB-INF directory. Maven will start Jetty and unit test Servlet25Init1ITCase works with already running JAX-RS application - in case of JerseyTest it uses external container provider (ExternalTestContainerFactory, https://github.com/jersey/jersey/blob/master/tests/integration/servlet-2.5-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25Init1ITCase.java#L75). |
@glassfishrobot Commented This isn't equivalent to the Jersey 1.x functionality. I am expecting JerseyTest to manage the server lifecycle and pass in a web.xml-like configuration. The examples you provided detach JerseyTest from the server lifecycle. |
@glassfishrobot Commented |
@glassfishrobot Commented I am pointing out that in Jersey 1.0 I could configure JerseyTest to start up the test server at the beginning of every test, and shut it down at the end of every test, and configure it to use a specific web.xml configuration ... and in Jersey 2.0 this does not seem to be possible. You are asking me to choose between having JerseyTest handle the server lifecycle, and the ability to configure web.xml. I am saying that in Jersey 1.0 it was possible to do both at once. |
@glassfishrobot Commented If you want to cache instance of JerseyTest per one TestNG test class the solution could be to enhance JerseyTest to invoke TestContainerFactory.create(...) per each test method. Such feature could be configured per JerseyTest instance. Let me know if such change to JerseyTest could solve your use case. Still it means you create TestContainerFactory extension (GrizzlyTestContainerFactory can be used for inspiration) to be able to create TestContainer instances with different configuration per each test method? |
@glassfishrobot Commented You're asking me to create my own TestContainerFactory for the typical use-case of configuring web.xml. This requires too much work on the part of the user and (again) demonstrates that functionality that was available in Jersey 1.0 is missing in 2.0. What I am expecting: 1. All servlet-based container factories should provide a mechanism for configuring web.xml. Jersey 1.0 used approach 2a but I am willing to live with 2b. In either case, this functionality should be available out of the box and users should not have to create their own container factory. |
@glassfishrobot Commented Q: Do you really need to change web.xml per test method? I think it is extreme case that can be realized by different tests classes. |
@glassfishrobot Commented While I appreciate your attempt to provide workarounds, let's please focus on the long-term solution from now on.
|
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented
It migth be possible to write this:
Actually similar problem was reported by other person in this thread: Also, after jersey-mvc component became more popular, I bealive, more and more people would ask for this. |
@glassfishrobot Commented |
|
There doesn't seem to be a way to pass information into the Application that unit tests launch. I looked at https://jersey.java.net/documentation/latest/user-guide.html#test-framework and this use-case was not covered.
For example, I am trying to pass a ServletContext attribute to the JAX-RS application in order to indicate which HK2 dynamic configuration should be bound at runtime. Unit tests bind to mock implementations whereas in production I bind to real implementations.
Affected Versions
[2.4.1]
The text was updated successfully, but these errors were encountered: