jersey-test-framework

Configure JettyTestContainer with SSL for JerseyTest

拥有回忆 提交于 2021-01-27 21:11:19
问题 I've been tasked with setting up integration tests for my team's code. These tests will require performing HTTPS requests to REST endpoints implemented in Jersey 2.27. In my search for how to perform this kind of test, I stumbled upon this article from Baeldung that pointed me to the Jersey Test Framework and the provider containers they've implemented for this purpose. I chose the Jetty container, as our code was using a 'roll your own' Jetty instance to do all this. I began the

Static initializer doesn't run during JUnit tests

心不动则不痛 提交于 2021-01-27 04:32:26
问题 I have an interesting JUnit problem here (JUnit 4.12). I have a base class that only has static methods. They have to be static, because of the way they're used. I inherit other classes from the base class. So, if the base class is Base , we have ChildA and ChildB . Most of the methods are contained in the base class, but it has to know which child it actually is (just calling the methods as the base class is invalid). This is done via a static data member in the base class: public class Base

Pure JerseyTest without letting Spring messing with services

早过忘川 提交于 2019-12-23 22:26:42
问题 I am having hard time with JerseyTest and Spring. Previously in non-Spring Java projects what I usually did for my REST APIs was to extend my Test from JerseyTest, mocking the Service classes and simply (unit)testing my REST API. Now I'm using spring in my project where in my REST resource classes the Services are annotated with @Autowired. Now that I'm using the same scenario. Spring jumps in and nags about stuff like lack of applicationcontext.xml. I do want to use spring in my production

Jersey rest test fails because of session inside of resource method

浪尽此生 提交于 2019-12-23 05:50:35
问题 I have Jersey rest api, but when I try to test it it fails because of I am getting session data there, so the questions is, how can I mock or ignore this session variable, which Jersey can't detect? Here is a request from my test: User response = target("/am/users/" + userId).request().get(new GenericType<User>() { }); Here is my resource: @GET @Path("{userId}") @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") public User getUser(@PathParam("userId") String userId, @Context

JAXRS + JerseyTest testing a REST Service

你离开我真会死。 提交于 2019-12-20 04:49:16
问题 I've created a Rest service with four methods, GET,POST,UPDATE and DELETE. These methods make connections to a Database to retrieve and store data. Now I want to test each method. I've used the Jersey Test Framework for this. And it is working as long as I remove the code what actually makes the call to the database. When I leave the code that makes the call to the database it throws an exception that it could not connect to the database. EDIT: I have done some research and used dependancy

Jersey test - Http Delete method with JSON request

…衆ロ難τιáo~ 提交于 2019-12-11 09:54:47
问题 I am using Jersey Test to test Rest service DELETE method: @DELETE @Path("/myPath") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public MyResponse myMethod(MyRequest myRequest) { I have tried the example below and other methods: Entity<MyRequest> requestEntity = Entity.entity(new MyRequest(arg1, arg2), MediaType.APPLICATION_JSON); target(MY_URI).request(MediaType.APPLICATION_JSON).method("DELETE", requestEntity) and target(MY_URI).request(MediaType.APPLICATION

Issue when test a Jersey rest service using powermock with Jersey Test + TestNg

我是研究僧i 提交于 2019-12-11 06:11:46
问题 A rest service using Jersey developed. Now I want to write some integration tests for this web service but since not every class being used from the web service is already implemented I need to mock some of them. For example I have the following class: public class ServiceA { public String getService() { return null; }} @Path("/myresource") public class ResourceController { @GET @Produces("text/plain") public String getIt() { ServiceA a = new ServiceA(); return a.getService(); }} Then i want

JerseyTest with shiro

≡放荡痞女 提交于 2019-12-11 05:56:25
问题 Instantiating JerseyTest with this class public class NMAAbstractRestTest extends JerseyTest { @Override protected Application configure() { NMAdaptorApplication application = new NMAdaptorApplication(); return application; } } NMAdaptorApplication constructor. public NMAdaptorApplication() { log.info("NM-Adaptor-Application is being initilized...."); register(NMRestExceptionMapper.class); register(ShiroFeature.class); register(NMMarshallingFeature.class); register(new LoggingFeature(java

Jersey 1.19 Test configuration - mock classes

做~自己de王妃 提交于 2019-12-11 04:47:44
问题 I want to test my REST service with: <dependency> <groupId>com.sun.jersey.jersey-test-framework</groupId> <artifactId>jersey-test-framework-grizzly2</artifactId> <version>1.19</version> <scope>test</scope> </dependency> I have configuration class: public class MyServiceTest extends JerseyTest { @Override protected int getPort(int defaultPort) { return 8080; } public static class AppConfig extends DefaultResourceConfig { public AppConfig() { super(MyService.class); } } @Override public