Search in sources :

Example 1 with com.linkedin.restli.examples.greetings.api.myRecord

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;
}
Also used : com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) HashMap(java.util.HashMap) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Example 2 with com.linkedin.restli.examples.greetings.api.myRecord

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" } };
}
Also used : com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) MyItemArray(com.linkedin.restli.examples.greetings.api.MyItemArray) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) com.linkedin.restli.examples.greetings.api.myItem(com.linkedin.restli.examples.greetings.api.myItem) GreetingMap(com.linkedin.restli.examples.greetings.api.GreetingMap) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Aggregations

ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)2 com.linkedin.restli.examples.greetings.api.myRecord (com.linkedin.restli.examples.greetings.api.myRecord)2 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)1 GreetingMap (com.linkedin.restli.examples.greetings.api.GreetingMap)1 MyItemArray (com.linkedin.restli.examples.greetings.api.MyItemArray)1 com.linkedin.restli.examples.greetings.api.myItem (com.linkedin.restli.examples.greetings.api.myItem)1 HashMap (java.util.HashMap)1