use of com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders in project rest.li by linkedin.
the class TestRestLiValidation method testBatchGetAutoWithException.
@Test
public void testBatchGetAutoWithException() throws RemoteInvocationException {
// The resource returns an error for id=0 but a normal result for id=1
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyRecord(new myRecord().setFoo1(100).setFoo2(200));
ValidationDemo expectedResult = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(union);
BatchGetRequest<ValidationDemo> request = new AutoValidationDemosBuilders().batchGet().ids(0, 1).build();
Response<BatchResponse<ValidationDemo>> response = _restClientAuto.sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals((int) response.getEntity().getErrors().get("0").getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
Assert.assertEquals(response.getEntity().getResults().get("1"), expectedResult);
BatchGetEntityRequest<Integer, ValidationDemo> request2 = new AutoValidationDemosRequestBuilders().batchGet().ids(0, 1).build();
Response<BatchKVResponse<Integer, EntityResponse<ValidationDemo>>> response2 = _restClientAuto.sendRequest(request2).getResponse();
Assert.assertEquals(response2.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals((int) response2.getEntity().getErrors().get(0).getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
Assert.assertEquals(response2.getEntity().getResults().get(1).getEntity(), expectedResult);
}
use of com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders in project rest.li by linkedin.
the class TestRestLiValidation method testBatchGetAuto.
@Test
public void testBatchGetAuto() throws RemoteInvocationException {
final List<Integer> ids = Arrays.asList(11, 22, 33);
final String errorMessage = ", ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 " + ":: field is required but not found and has no default value\n";
try {
BatchGetRequest<ValidationDemo> request = new AutoValidationDemosBuilders().batchGet().ids(ids).build();
_restClientAuto.sendRequest(request).getResponse();
Assert.fail("Expected RestLiResponseException");
} catch (RestLiResponseException e) {
for (Integer id : ids) {
Assert.assertTrue(e.getServiceErrorMessage().contains("Key: " + id.toString() + errorMessage));
}
}
try {
BatchGetEntityRequest<Integer, ValidationDemo> request2 = new AutoValidationDemosRequestBuilders().batchGet().ids(ids).build();
_restClientAuto.sendRequest(request2).getResponse();
Assert.fail("Expected RestLiResponseException");
} catch (RestLiResponseException e) {
for (Integer id : ids) {
Assert.assertTrue(e.getServiceErrorMessage().contains("Key: " + id.toString() + errorMessage));
}
}
}
Aggregations