2017-04-10 3 views
0

私はジャージテストframeworkと私のジャージ1 -applicationをテストしたいです。ジャージーJUnitのテストフレームワーク - エラーステータス500

は、私はこれをテストしたい:

public class TestMB extends JerseyTest{ 

private WebResource webResource = resource(); 

public TestMB() throws Exception { 
    super("...api..."); 
} 

@Test 
public void testCon() { 

    String responseMsg = webResource.path("/fieldgen/testCon").get(String.class); 
    assertEquals("testcon", responseMsg);  
} 


@Test 
public void getTestObj() { 

    WebResource.Builder mbRes = webResource.path("/fieldgen/getTestObj").accept(MediaType.APPLICATION_JSON); 
    TestObj vr = mbRes.get(TestObj.class); 

    assertEquals(vr, new TestObj("str1", "str2", "str3")); 
} 

最初のテストは大丈夫です:

@Path("fieldgen") 
public class VRApi { 

@Path("/testCon") 
@GET 
@Produces(MediaType.APPLICATION_JSON) 
public String testCon() { 

    return "testcon"; 
} 

@Path("/getTestObj") 
@GET 
@Produces(MediaType.APPLICATION_JSON) 
public TestObj getField() { 

    TestObj tobj= new TestObj ("str1", "str2", "str3"); 
    return tobj; 
} 

は、ここに私のテストクラスです。 第二のテストは失敗します。

A message body writer for Java class modelVR.TestObj, and Java type class 
    modelVR.TestObj, and MIME media type application/json was not found 

私もClientResponseを使用しようとしました。 POMのDEP:

 <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.17.1</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey.jersey-test-framework</groupId> 
     <artifactId>jersey-test-framework-inmemory</artifactId> 
     <version>1.17.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-servlet</artifactId> 
     <version>1.17.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-json</artifactId> 
     <version>1.17.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-core</artifactId> 
     <version>1.17.1</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>3.0-alpha-1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>1.19.3</version> 
    </dependency> 

いただきまし通報しますか?ありがとう。

答えて

0

おそらくJSONへの自動POJOを含んでおり、マッパーを逆に「ジャクソン・データバインド」を逃しています。ジャージのドキュメントhereで説明したように、クライアントでのPOJOマッピング機能を登録しているかどうか

+0

感謝が、それはまだ働いていません。 – Lukasx

0

チェック(たぶん名前はジャクソン1.xの中でわずかに異なっています)。関連するスニペットは以下のとおりです。

ClientConfig clientConfig = new DefaultClientConfig(); 
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); 
Client client = Client.create(clientConfig) 
関連する問題