use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method testBatchCreateManualFailure.
@Test(dataProvider = "batchCreateFailureData")
public void testBatchCreateManualFailure(List<ValidationDemo> validationDemos, List<String> errorMessages) throws RemoteInvocationException {
Response<CollectionResponse<CreateStatus>> response = _restClientManual.sendRequest(new RootBuilderWrapper<Integer, ValidationDemo>(new ValidationDemosBuilders()).batchCreate().inputs(validationDemos).build()).getResponse();
List<CreateStatus> results = response.getEntity().getElements();
int i = 0;
for (CreateStatus result : results) {
Assert.assertEquals((int) result.getStatus(), HttpStatus.S_422_UNPROCESSABLE_ENTITY.getCode());
Assert.assertTrue(result.getError().getMessage().contains(errorMessages.get(i++)));
}
response = _restClientManual.sendRequest(new RootBuilderWrapper<Integer, ValidationDemo>(new ValidationDemosRequestBuilders()).batchCreate().inputs(validationDemos).build()).getResponse();
@SuppressWarnings("unchecked") List<CreateIdStatus<Integer>> results2 = ((BatchCreateIdResponse<Integer>) (Object) response.getEntity()).getElements();
i = 0;
for (CreateIdStatus<Integer> result : results2) {
Assert.assertEquals((int) result.getStatus(), HttpStatus.S_422_UNPROCESSABLE_ENTITY.getCode());
Assert.assertTrue(result.getError().getMessage().contains(errorMessages.get(i++)));
}
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method batchCreateAndGetFailures.
private static Object[][] batchCreateAndGetFailures() {
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyEnum(myEnum.FOOFOO);
return new Object[][] { { new ValidationDemo().setStringB("b1").setUnionFieldWithInlineRecord(unionField), "ERROR :: /UnionFieldWithInlineRecord :: field is required but not found and has no default value" }, { new ValidationDemo().setStringB("b2").setUnionFieldWithInlineRecord(unionField), "ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 " + ":: field is required but not found and has no default value" } };
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method createFailures.
public static Object[][] createFailures() {
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyRecord(new myRecord().setFoo1(111));
MyItemArray myItems = new MyItemArray();
myItems.add(new myItem().setBar1("bar1"));
GreetingMap greetingMap = new GreetingMap();
greetingMap.put("key1", new Greeting());
return new Object[][] { // ReadOnly fields should not be specified in a create request, whether they are required or optional
{ new ValidationDemo().setStringA("aaa"), "/stringA :: ReadOnly field present in a create request" }, { new ValidationDemo().setIntA(1234), "/intA :: ReadOnly field present in a create request" }, { new ValidationDemo().setUnionFieldWithInlineRecord(unionField), "/UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: ReadOnly field present in a create request" }, { new ValidationDemo().setArrayWithInlineRecord(myItems), "/ArrayWithInlineRecord/0/bar1 :: ReadOnly field present in a create request" }, { new ValidationDemo().setValidationDemoNext(new ValidationDemo().setStringB("stringB")), "/validationDemoNext/stringB :: ReadOnly field present in a create request" }, { new ValidationDemo().setValidationDemoNext(new ValidationDemo().setUnionFieldWithInlineRecord(unionField)), "/validationDemoNext/UnionFieldWithInlineRecord :: ReadOnly field present in a create request" }, // A field that is CreateOnly and required has to be present in a create request
{ new ValidationDemo(), "/stringB :: field is required but not found and has no default value" }, { new ValidationDemo().setStringB("bbb"), "/UnionFieldWithInlineRecord :: field is required but not found and has no default value" }, // Required fields without Rest.li data annotations should be present in a create request
{ new ValidationDemo().setArrayWithInlineRecord(myItems), "/ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value" }, { new ValidationDemo().setMapWithTyperefs(greetingMap), "/MapWithTyperefs/key1/id :: field is required but not found and has no default value" }, { new ValidationDemo().setValidationDemoNext(new ValidationDemo()), "/validationDemoNext/stringA :: field is required but not found and has no default value" }, { new ValidationDemo(), "/UnionFieldWithInlineRecord :: field is required but not found and has no default value" } };
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method updateSuccesses.
public static Object[] updateSuccesses() {
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyRecord(new myRecord().setFoo1(1));
ValidationDemo validationDemo1 = new ValidationDemo().setStringA("aaa").setStringB("bbb").setUnionFieldWithInlineRecord(unionField);
ValidationDemo.UnionFieldWithInlineRecord unionField2 = new ValidationDemo.UnionFieldWithInlineRecord();
unionField2.setMyEnum(myEnum.BARBAR);
MyItemArray array = new MyItemArray();
array.add(new myItem().setBar1("BAR1").setBar2("BAR2"));
array.add(new myItem().setBar1("BAR11").setBar2("BAR22"));
GreetingMap map = new GreetingMap();
map.put("key1", new Greeting().setId(1).setMessage("msg").setTone(Tone.FRIENDLY));
return new Object[] { // All required fields have to be present, regardless of ReadOnly or CreateOnly annotations
validationDemo1, new ValidationDemo().setStringA("aaa").setStringB("bbb").setUnionFieldWithInlineRecord(unionField2).setIntA(1234).setIntB(5678).setArrayWithInlineRecord(array).setMapWithTyperefs(map).setValidationDemoNext(validationDemo1) };
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidation method testCreateAndGetAutoSuccess.
@Test(dataProvider = "provideCreateAndGetSuccessData")
@SuppressWarnings("unchecked")
public void testCreateAndGetAutoSuccess(RestClient restClient, Object builder, ValidationDemo validationDemo) throws RemoteInvocationException {
Request<IdEntityResponse<Integer, ValidationDemo>> createRequest = new RootBuilderWrapper<Integer, ValidationDemo>(builder).createAndGet().input(validationDemo).build();
Response<IdEntityResponse<Integer, ValidationDemo>> response = restClient.sendRequest(createRequest).getResponse();
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyEnum(myEnum.FOOFOO);
ValidationDemo expected = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(unionField);
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(response.getEntity().getEntity(), expected);
}
Aggregations