球衣测试框架文档不起作用
jersey test framework documentation doesn't work
正在尝试构建一个 hello world 球衣测试。 https://jersey.java.net/documentation/2.5.1/test-framework.html 让它看起来很简单,但是当按照文档覆盖配置方法时不起作用。
来自文档
package api;
import static org.junit.Assert.assertEquals;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.junit.Test;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
public class JerseyTester extends JerseyTest {
@Path("hello")
public static class HelloResource {
@GET
public String getHello() {
return "Hello World!";
}
}
@Override
protected Application configure() {
return new ResourceConfig(HelloResource.class);
}
@Test
public void testHelloWorld() {
WebResource webResource = resource();
String responseMsg = webResource.path("helloworld").get(String.class);
assertEquals("Hello World", responseMsg);
}
}
问题是配置方法覆盖不起作用 - 我收到错误:"The return type is incompatible with JerseyTest.configure()"。我还收到错误消息:"Cannot instantiate the type ResourceConfig" - 当文档明确说明要实例化它时怎么会这样?!
这太基础了,我不知道为什么它不起作用。我只是想在测试中获得一个朴素的球衣端点。
这是我的依赖项:
dependencies {
compile 'javax.ws.rs:jsr311-api:1.1.1'
compile 'com.sun.jersey:jersey-server:1.19'
compile 'com.sun.jersey:jersey-core:1.19'
compile 'com.sun.jersey:jersey-client:1.19'
compile 'com.sun.jersey:jersey-servlet:1.19'
compile 'com.sun.jersey:jersey-json:1.19'
compile 'com.yammer.metrics:metrics-core:2.2.0'
compile 'com.yammer.metrics:metrics-servlet:2.2.0'
compile 'com.yammer.metrics:metrics-jersey:2.2.0'
compile 'com.yammer.metrics:metrics-graphite:2.2.0'
compile 'log4j:log4j:1.2.16'
testCompile 'junit:junit-dep:4.10'
testCompile 'com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly2:1.19'
testCompile 'org.slf4j:slf4j-simple:1.6.1'
}
是的,您看错了文档。您正在查看的文档适用于 Jersey 2.x。但是您正在使用 Jersey 1.x。您可以查看 1.x, but there's not much going on there. Best thing to do is look at the source code tests for examples. You can also see another example at the bottom of
的文档
正在尝试构建一个 hello world 球衣测试。 https://jersey.java.net/documentation/2.5.1/test-framework.html 让它看起来很简单,但是当按照文档覆盖配置方法时不起作用。
来自文档
package api;
import static org.junit.Assert.assertEquals;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.junit.Test;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
public class JerseyTester extends JerseyTest {
@Path("hello")
public static class HelloResource {
@GET
public String getHello() {
return "Hello World!";
}
}
@Override
protected Application configure() {
return new ResourceConfig(HelloResource.class);
}
@Test
public void testHelloWorld() {
WebResource webResource = resource();
String responseMsg = webResource.path("helloworld").get(String.class);
assertEquals("Hello World", responseMsg);
}
}
问题是配置方法覆盖不起作用 - 我收到错误:"The return type is incompatible with JerseyTest.configure()"。我还收到错误消息:"Cannot instantiate the type ResourceConfig" - 当文档明确说明要实例化它时怎么会这样?!
这太基础了,我不知道为什么它不起作用。我只是想在测试中获得一个朴素的球衣端点。
这是我的依赖项:
dependencies {
compile 'javax.ws.rs:jsr311-api:1.1.1'
compile 'com.sun.jersey:jersey-server:1.19'
compile 'com.sun.jersey:jersey-core:1.19'
compile 'com.sun.jersey:jersey-client:1.19'
compile 'com.sun.jersey:jersey-servlet:1.19'
compile 'com.sun.jersey:jersey-json:1.19'
compile 'com.yammer.metrics:metrics-core:2.2.0'
compile 'com.yammer.metrics:metrics-servlet:2.2.0'
compile 'com.yammer.metrics:metrics-jersey:2.2.0'
compile 'com.yammer.metrics:metrics-graphite:2.2.0'
compile 'log4j:log4j:1.2.16'
testCompile 'junit:junit-dep:4.10'
testCompile 'com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly2:1.19'
testCompile 'org.slf4j:slf4j-simple:1.6.1'
}
是的,您看错了文档。您正在查看的文档适用于 Jersey 2.x。但是您正在使用 Jersey 1.x。您可以查看 1.x, but there's not much going on there. Best thing to do is look at the source code tests for examples. You can also see another example at the bottom of