泽西测试相当于卷曲请求

时间:2014-06-11 23:23:01

标签: java unit-testing jersey

首次进入Java Web服务世界。试图为帖子请求编写测试。该帖子在curl中看起来像这样:

url -v -X POST -H 'Content-Type: application/json' -d '{"transaction_zips": ["78732"],"condition": "good"}' http://localhost:8080/PricingService/vin/1GTEC19J37E152026/usedValues

我尝试过:

@Test
public void testVinPricing200() {
    int status = target.path("PricingService/vin/1GTEC19J37E152026/usedValues").request(MediaType.APPLICATION_JSON_TYPE).
            post(Entity.entity("{\"transaction_zips\": [\"78732\"],\"condition\": \"good\"}", MediaType.APPLICATION_JSON)).getStatus();
    assertEquals(200, status);
}

这导致:

Failed tests:   testVinPricing200(com.comp.platform.PricingServiceTest): expected:<200> but was:<406>

所以问题很简单,我显然没有正确发布,我做错了什么?

1 个答案:

答案 0 :(得分:1)

curl请求与junit测试之间的差异junit test您要求的回复类型为MediaType.APPLICATION_JSON_TYPE,但您的webservice不是responding能够JSON通过The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Http状态代码:406

{{1}}