Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAX-RS Junit错误_Java_Spring_Junit_Jersey_Jax Rs - Fatal编程技术网

Java JAX-RS Junit错误

Java JAX-RS Junit错误,java,spring,junit,jersey,jax-rs,Java,Spring,Junit,Jersey,Jax Rs,我试图为jax-rsapi运行unittest,但出现了一个错误。我的实施的一些细节: 控制器 @Path("/webservices") @Produces(MediaType.APPLICATION_JSON) public class AController { public AController() { ApplicationContext applicationContext = new AnnotationConfigApplicationContext(

我试图为jax-rsapi运行unittest,但出现了一个错误。我的实施的一些细节:

控制器

@Path("/webservices")
@Produces(MediaType.APPLICATION_JSON)
public class AController {

    public AController() {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
                AConfiguration.class);
        AutowireCapableBeanFactory acbFactory = applicationContext
                .getAutowireCapableBeanFactory();
        acbFactory.autowireBean(this);
    }

    @GET
    public Response getAll() {
                         something hier...
测试:

public class AControllerTest {

    private static final int PORT = 8080;
    private static final String LOCALHOST = "http://localhost";
    private static final String GLOBAL_PATH = "/thesis/webservices/";

    private static final URI URI = getBaseURI();

    private HttpServer httpServer;
    private Client client;

    private static URI getBaseURI() {
        return UriBuilder.fromUri(LOCALHOST).port(PORT).build();
    }

    @Before
    public void setUp() throws IllegalArgumentException, NullPointerException,
            IOException {
        httpServer = com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory
                .createHttpServer(URI);
        httpServer.start();
    }

    @Test
    public void testGetAll() {

        client = Client.create(new DefaultClientConfig());
        WebResource webResource = client.resource(getBaseURI());
        ClientResponse response = webResource.path(GLOBAL_PATH)
                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(200, response.getStatus());
    }

    @After()
    public void stopServer() {
        httpServer.stop();
    }
}
pom.xml中的我的
论文

运行测试时,出现以下错误:

Failed tests:   testGetAll(AControllerTest): expected:<200> but was:<404>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.466s
[INFO] Finished at: Mon Mar 30 22:23:05 CEST 2015
[INFO] Final Memory: 18M/133M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project thesis: There are test failures.
[ERROR] 
[ERROR] Please refer to pathto/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project thesis: There are test failures.
测试失败:testGetAll(AControllerTest):应为:但为:
测试运行:1,失败:1,错误:0,跳过:0
[信息]------------------------------------------------------------------------
[信息]生成失败
[信息]------------------------------------------------------------------------
[信息]总时间:16.466s
[信息]完成时间:2015年3月30日星期一22:23:05 CEST
[信息]最终内存:18M/133M
[信息]------------------------------------------------------------------------
[错误]未能执行目标org.apache.maven.plugins:maven surefire plugin:2.10:test(默认测试)项目论文:存在测试失败。
[错误]
[错误]请参阅pathto/target/surefire报告以了解单个测试结果。
[错误]->[帮助1]
org.apache.maven.lifecycle.LifecycleExecutionException:未能执行目标org.apache.maven.plugins:maven surefire plugin:2.10:项目测试(默认测试):有测试失败。
有人知道这个问题吗?
谢谢:-)

我解决了。我更改了/webservices的路径,它可以正常工作。谢谢

好吧,你的成绩是404,预期是200。我建议你检查一下你是否在你认为你是的端点上提供服务你指的是哪个端点?我用commando调用了请求(GET),但没有收到错误。一开始,您的控制器似乎映射到了
/webservices
,但您正在向
/thesis/webservices/
发送请求。您需要将grizzly服务器映射到
/thesis
,或者将请求路径更改为
/webservices