Search in sources :

Example 1 with GreetingMap

use of com.linkedin.restli.examples.greetings.api.GreetingMap 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)

Example 2 with GreetingMap

use of com.linkedin.restli.examples.greetings.api.GreetingMap 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) };
}
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)

Example 3 with GreetingMap

use of com.linkedin.restli.examples.greetings.api.GreetingMap in project rest.li by linkedin.

the class TestRestLiValidation method updateFailures.

public static Object[][] updateFailures() {
    MyItemArray myItems = new MyItemArray();
    myItems.add(new myItem().setBar1("bar1"));
    GreetingMap greetingMap = new GreetingMap();
    greetingMap.put("key1", new Greeting());
    return new Object[][] { // Required fields should be present in an update 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/message :: 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" }, // Data schema annotations such as strlen are validated
    { new ValidationDemo().setStringA("012345678901234"), "/stringA :: length of \"012345678901234\" is out of range 1...10" } };
}
Also used : 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

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 GreetingMap (com.linkedin.restli.examples.greetings.api.GreetingMap)3 MyItemArray (com.linkedin.restli.examples.greetings.api.MyItemArray)3 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)3 com.linkedin.restli.examples.greetings.api.myItem (com.linkedin.restli.examples.greetings.api.myItem)3 com.linkedin.restli.examples.greetings.api.myRecord (com.linkedin.restli.examples.greetings.api.myRecord)2