Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Google app engine 运行Jersey的单元测试时出错+;GAE服务_Google App Engine_Junit_Jersey - Fatal编程技术网

Google app engine 运行Jersey的单元测试时出错+;GAE服务

Google app engine 运行Jersey的单元测试时出错+;GAE服务,google-app-engine,junit,jersey,Google App Engine,Junit,Jersey,我已经实现了一些Restful服务,并使用GoogleAppEngine作为数据库部分。 每件事都很好,我已经用cURL测试过了。问题是我需要创造 类似服务的一组单元测试 以下是我得到的错误信息: Jan 23, 2012 10:10:42 AM com.sun.jersey.api.core.ScanningResourceConfig init INFO: No provider classes found. Jan 23, 2012 10:10:42 AM com.sun.jers

我已经实现了一些Restful服务,并使用GoogleAppEngine作为数据库部分。 每件事都很好,我已经用cURL测试过了。问题是我需要创造 类似服务的一组单元测试

以下是我得到的错误信息:

    Jan 23, 2012 10:10:42 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Jan 23, 2012 10:10:42 AM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer <init>
INFO: Creating low level InMemory test container configured at the base URI http://localhost:9998/
Jan 23, 2012 10:10:42 AM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer start
INFO: Starting low level InMemory test container
Jan 23, 2012 10:10:42 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
Jan 23, 2012 10:10:43 AM com.sun.jersey.spi.inject.Errors processErrorMessages
WARNING: The following warnings have been detected with resource and/or provider classes:
  WARNING: A HTTP GET method, public void org.mycompany.myservices.Cache.flush(java.lang.String), MUST return a non-void type.
Jan 23, 2012 10:10:43 AM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer stop
INFO: Stopping low level InMemory test container
以及我遇到的测试用例:

public class BuildingTest extends JerseyTest {

    private String token ="DQAAAMMAAAB9ApLCubrBvuac0Y6lF8TH8FPXY5WzAhkwrqZv6tL0l9pu_xcY_9mVa1Q-sqTDlMXWUGoo8coYZGh8H2L2b_597O6StOyZ7N3uD-6v5HLNgPDWjj6YXl_X_LyEGM97z3JbSFire3J2Aw5Rag09BEweSMEjV-7TX3lqvtipWYJwQNWlSKpDl4F3TxBj-bWQulvFQ_wonLKze227Le3D_gB0JRofe3L5RkxBClkR6VKIx5s9fEbzupFz6t9hmKoNUTdRa14CgrQSaxXiPMO7J6G9";

    @Override
    protected AppDescriptor configure() {
    this.setTestContainerFactory(new InMemoryTestContainerFactory() );
    return new WebAppDescriptor.Builder("org.mycompany.myservices")
    .contextPath("/").build(); }

    @Test
    public void put() {
        Building building = new Building();
        building.setBuildingId("test_id_1.0x");
        building.setTeamId("weakId");
        building.setBuildingStatus(2);
        building.setRunId((long) 1110705);

        Client client = Client.create(); 
        WebResource webResource = client.resource("http://localhost:9998/");
        RunBean resultBean = webResource
            .path("rest/building")
            .header("Authorization", token)
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(RunBean.class,building);
        assertEquals(((Building)resultBean).getBuildingId(), building.getBuildingId());

    }
}

您不能使用内存测试容器工厂并创建到localhost:someport的连接。在这种情况下,插座甚至没有打开。使用client()调用获取客户机或使用其他容器(例如grizzly2)
public class BuildingTest extends JerseyTest {

    private String token ="DQAAAMMAAAB9ApLCubrBvuac0Y6lF8TH8FPXY5WzAhkwrqZv6tL0l9pu_xcY_9mVa1Q-sqTDlMXWUGoo8coYZGh8H2L2b_597O6StOyZ7N3uD-6v5HLNgPDWjj6YXl_X_LyEGM97z3JbSFire3J2Aw5Rag09BEweSMEjV-7TX3lqvtipWYJwQNWlSKpDl4F3TxBj-bWQulvFQ_wonLKze227Le3D_gB0JRofe3L5RkxBClkR6VKIx5s9fEbzupFz6t9hmKoNUTdRa14CgrQSaxXiPMO7J6G9";

    @Override
    protected AppDescriptor configure() {
    this.setTestContainerFactory(new InMemoryTestContainerFactory() );
    return new WebAppDescriptor.Builder("org.mycompany.myservices")
    .contextPath("/").build(); }

    @Test
    public void put() {
        Building building = new Building();
        building.setBuildingId("test_id_1.0x");
        building.setTeamId("weakId");
        building.setBuildingStatus(2);
        building.setRunId((long) 1110705);

        Client client = Client.create(); 
        WebResource webResource = client.resource("http://localhost:9998/");
        RunBean resultBean = webResource
            .path("rest/building")
            .header("Authorization", token)
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(RunBean.class,building);
        assertEquals(((Building)resultBean).getBuildingId(), building.getBuildingId());

    }
}