首次进入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>
所以问题很简单,我显然没有正确发布,我做错了什么?
答案 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}}