use of com.linkedin.restli.examples.greetings.api.myRecord in project rest.li by linkedin.
the class ValidationDemoResource method batchGet.
@RestMethod.BatchGet
public Map<Integer, ValidationDemo> batchGet(Set<Integer> ids, @ValidatorParam RestLiDataValidator validator) {
Map<Integer, ValidationDemo> resultMap = new HashMap<Integer, ValidationDemo>();
// Generate entities that are missing a required field
for (Integer id : ids) {
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyRecord(new myRecord());
ValidationDemo validationDemo = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(union);
resultMap.put(id, validationDemo);
}
;
// Validate outgoing data
for (ValidationDemo entity : resultMap.values()) {
ValidationResult result = validator.validateOutput(entity);
check(!result.isValid());
check(result.getMessages().toString().contains("/UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found"));
}
// Fix entities
for (Integer id : ids) {
resultMap.get(id).getUnionFieldWithInlineRecord().getMyRecord().setFoo1(1234);
}
// Validate again
for (ValidationDemo entity : resultMap.values()) {
ValidationResult result = validator.validateOutput(entity);
check(result.isValid());
}
return resultMap;
}
use of com.linkedin.restli.examples.greetings.api.myRecord 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" } };
}
Aggregations