use of com.linkedin.restli.examples.greetings.api.ValidationDemo 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));
}
}
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method createAndGetFailureData.
public static Object[][] createAndGetFailureData() {
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyEnum(myEnum.BARBAR);
ValidationDemo validationDemo = new ValidationDemo().setStringB("some string").setUnionFieldWithInlineRecord(unionField);
return new Object[][] { { validationDemo, "ERROR :: /stringA :: field is required but not found and has no default value\n" } };
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method createSuccessData.
public static Object[] createSuccessData() {
ValidationDemo.UnionFieldWithInlineRecord unionField1 = new ValidationDemo.UnionFieldWithInlineRecord();
unionField1.setMyEnum(myEnum.FOOFOO);
ValidationDemo validationDemo1 = new ValidationDemo().setStringB("some string").setUnionFieldWithInlineRecord(unionField1);
ValidationDemo.UnionFieldWithInlineRecord unionField2 = new ValidationDemo.UnionFieldWithInlineRecord();
unionField2.setMyRecord(new myRecord());
MyItemArray myItems = new MyItemArray();
myItems.add(new myItem().setBar2("bar2"));
// ReadOnly fields can be missing even if they are required.
ValidationDemo validationDemo2 = new ValidationDemo().setStringB("bbb").setUnionFieldWithInlineRecord(unionField2).setArrayWithInlineRecord(myItems).setValidationDemoNext(new ValidationDemo().setStringA("aaa"));
return new Object[] { validationDemo1, validationDemo2 };
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method testBatchGet.
@Test
public void testBatchGet() throws RemoteInvocationException {
BatchGetRequest<ValidationDemo> request = new ValidationDemosBuilders().batchGet().ids(1, 2, 3).build();
Response<BatchResponse<ValidationDemo>> response = _restClientManual.sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
BatchGetEntityRequest<Integer, ValidationDemo> request2 = new ValidationDemosRequestBuilders().batchGet().ids(1, 2, 3).build();
Response<BatchKVResponse<Integer, EntityResponse<ValidationDemo>>> response2 = _restClientManual.sendRequest(request2).getResponse();
Assert.assertEquals(response2.getStatus(), HttpStatus.S_200_OK.getCode());
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidationFromClient method testInvalidOutputEntityValidation.
@Test
public void testInvalidOutputEntityValidation() {
RestLiDataValidator validator = new RestLiDataValidator(Collections.<String, List<String>>emptyMap(), ValidationDemo.class, ResourceMethod.GET);
try {
validator.validateOutput(null);
Assert.fail("Expected IllegalArgumentException.");
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Record template is null.");
}
try {
validator.validateOutput(new ValidationDemo(null));
Assert.fail("Expected IllegalArgumentException.");
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Record template does not have data.");
}
}
Aggregations