编辑:此解决方案仅适用于 Jersey 1.x,因此已经过时了。
它指的是http://geek.riffpie.com/unit-testing-restful-jersey-services-glued-together-with-spring/库。
如果您使用 Spring,您可以扩展 AbstractSpringAwareJerseyTest 而不是 JerseyTest,并注入您需要的任何内容。
根据要求,一小段代码:
public class MyClassTest extends AbstractSpringAwareJerseyTest{
@Autowired
private LdapSetupAndTearDown ldapSetupAndTearDown;
@Before
public void setUp2() throws Exception {
ldapSetupAndTearDown.setUp();
}
@After
public void tearDown2() throws Exception {
ldapSetupAndTearDown.tearDown();
}
public MyClassTest () throws Exception {
super(new WebAppDescriptor.Builder()
.contextPath("JSONUserServiceTest")
.contextParam("contextConfigLocation",
"classpath:/ctx-config-test.xml,classpath:/ctx-core.xml, classpath:/ctx-jmx-test.xml, classpath:ctx-jersey.xml, classpath:ctx-ldap.xml, classpath:ctx-ldap-test.xml")
.servletClass(SpringServlet.class).contextListenerClass(ContextLoaderListener.class).build());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2843 次 |
| 最近记录: |