Jersey 1.19 测试配置 - 模拟 类
Jersey 1.19 Test configuration - mock classes
我想测试我的 REST 服务:
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly2</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
我有配置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 WebAppDescriptor configure() {
return new WebAppDescriptor.Builder()
.initParam(WebComponent.RESOURCE_CONFIG_CLASS,
AppConfig.class.getName())
.build();
}
public MyServiceTest(){
}
}
MyService.java 是注入了 DAO 和其他服务的 REST 端点。 MyService.java 中有它们的设置器用于模拟目的。如何为 MyService 实例提供 set/mocked 相关的 classes?
它适用于
public static class AppConfig extends DefaultResourceConfig {
public AppConfig() {
MyService myService = new MyService();
MyDAO myDAO = mock(MyDAO.class);
myService.setMyDAO(myDAO);
getSingletons().add(new ExceptionMapperProvider());
getSingletons().add(myService);
}
}
我想测试我的 REST 服务:
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly2</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
我有配置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 WebAppDescriptor configure() {
return new WebAppDescriptor.Builder()
.initParam(WebComponent.RESOURCE_CONFIG_CLASS,
AppConfig.class.getName())
.build();
}
public MyServiceTest(){
}
}
MyService.java 是注入了 DAO 和其他服务的 REST 端点。 MyService.java 中有它们的设置器用于模拟目的。如何为 MyService 实例提供 set/mocked 相关的 classes?
它适用于
public static class AppConfig extends DefaultResourceConfig {
public AppConfig() {
MyService myService = new MyService();
MyDAO myDAO = mock(MyDAO.class);
myService.setMyDAO(myDAO);
getSingletons().add(new ExceptionMapperProvider());
getSingletons().add(myService);
}
}