throws Exception
{
RestResponse response;
// #1 all fields
RestRequest request1 = buildRequest("/test?fields=f1,f2,f3", acceptTypeData.acceptHeaders, protocolVersion);
Status status = buildStatusWithFields("f1", "f2", "f3");
response = _responseHandler.buildResponse(request1,
buildRoutingResult(request1, acceptTypeData.acceptHeaders),
status);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[] {"f1", "f2", "f3"}, new String[0]);
// #2 some fields
RestRequest request2 = buildRequest("/test?fields=f1,f3", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request2,
buildRoutingResult(request2, acceptTypeData.acceptHeaders),
status);
assertTrue(status.data().containsKey("f2"));
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[] {"f1", "f3"}, new String[] {"f2"});
// #3 no fields
RestRequest request3 = buildRequest("/test?fields=", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request3,
buildRoutingResult(request3, acceptTypeData.acceptHeaders),
status);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[]{}, new String[]{"f1", "f2", "f3"});
assertTrue(status.data().containsKey("f1"));
assertTrue(status.data().containsKey("f2"));
assertTrue(status.data().containsKey("f3"));
// #4 fields not in schema
RestRequest request4 = buildRequest("/test?fields=f1,f99", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request4,
buildRoutingResult(request4, acceptTypeData.acceptHeaders),
status);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);