Search in sources :

Example 21 with ValidationDemo

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));
        }
    }
}
Also used : AutoValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders) AutoValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 22 with ValidationDemo

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

Example 23 with ValidationDemo

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

Example 24 with ValidationDemo

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());
}
Also used : ValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.ValidationDemosBuilders) AutoValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders) BatchResponse(com.linkedin.restli.common.BatchResponse) AutoValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders) ValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.ValidationDemosRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 25 with ValidationDemo

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.");
    }
}
Also used : RestLiDataValidator(com.linkedin.restli.common.validation.RestLiDataValidator) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Aggregations

ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)32 Test (org.testng.annotations.Test)13 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)11 com.linkedin.restli.examples.greetings.api.myRecord (com.linkedin.restli.examples.greetings.api.myRecord)7 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)7 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)7 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)5 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 MyItemArray (com.linkedin.restli.examples.greetings.api.MyItemArray)4 com.linkedin.restli.examples.greetings.api.myItem (com.linkedin.restli.examples.greetings.api.myItem)4 AutoValidationDemosBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders)4 AutoValidationDemosRequestBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders)4 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)4 UpdateResponse (com.linkedin.restli.server.UpdateResponse)4 Map (java.util.Map)4 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)3 RestLiDataValidator (com.linkedin.restli.common.validation.RestLiDataValidator)3 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 GreetingMap (com.linkedin.restli.examples.greetings.api.GreetingMap)3