Search in sources :

Example 16 with ValidationDemo

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

the class TestResLiValidationWithProjection method testNoProjection.

@Test
public void testNoProjection() throws RemoteInvocationException {
    RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<Integer, ValidationDemo>(new AutoValidationWithProjectionBuilders());
    Request<CollectionResponse<ValidationDemo>> request = wrapper.findBy("searchWithProjection").build();
    try {
        _restClientAuto.sendRequest(request).getResponse();
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), "ERROR :: /validationDemoNext/UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/stringA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /validationDemoNext/ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/MapWithTyperefs/foo/message :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/MapWithTyperefs/foo/tone :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/stringB :: field is required but not found and has no default value\n" + "ERROR :: /includedA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found and has no default value\n" + "ERROR :: /ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value\n" + "ERROR :: /MapWithTyperefs/foo/message :: field is required but not found and has no default value\n" + "ERROR :: /MapWithTyperefs/foo/tone :: field is required but not found and has no default value\n" + "ERROR :: /stringA :: field is required but not found and has no default value\n");
    }
}
Also used : AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 17 with ValidationDemo

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

the class TestResLiValidationWithProjection method provideProjectionWithValidFieldsBuilders.

@DataProvider
private Object[][] provideProjectionWithValidFieldsBuilders() throws DataProcessingException {
    List<PathSpec> spec = Arrays.asList(ValidationDemo.fields().stringB(), ValidationDemo.fields().includedB(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), ValidationDemo.fields().MapWithTyperefs().values().id(), ValidationDemo.fields().validationDemoNext().intB());
    RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<Integer, ValidationDemo>(new AutoValidationWithProjectionBuilders());
    Request<CollectionResponse<ValidationDemo>> findRequest = wrapper.findBy("searchWithProjection").fields(spec.toArray(new PathSpec[spec.size()])).build();
    Request<ValidationDemo> getRequest = wrapper.get().id(1).fields(spec.toArray(new PathSpec[spec.size()])).build();
    Request<CollectionResponse<ValidationDemo>> getAllRequest = wrapper.getAll().fields(spec.toArray(new PathSpec[spec.size()])).build();
    // Valid input for CreateAndGet
    ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
    unionField.setMyEnum(myEnum.FOOFOO);
    ValidationDemo validDemo = new ValidationDemo().setStringB("b").setUnionFieldWithInlineRecord(unionField);
    Request<IdEntityResponse<Integer, ValidationDemo>> createAndGetRequest = wrapper.createAndGet().input(validDemo).fields(spec.toArray(new PathSpec[spec.size()])).build();
    Request<BatchCreateIdEntityResponse<Integer, ValidationDemo>> batchCreateAndGetRequest = wrapper.batchCreateAndGet().inputs(Arrays.asList(validDemo)).fields(spec.toArray(new PathSpec[spec.size()])).build();
    return new Object[][] { { findRequest, HttpStatus.S_200_OK }, { getRequest, HttpStatus.S_200_OK }, { getAllRequest, HttpStatus.S_200_OK }, { createAndGetRequest, HttpStatus.S_201_CREATED }, { batchCreateAndGetRequest, HttpStatus.S_200_OK } };
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) PathSpec(com.linkedin.data.schema.PathSpec) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) DataProvider(org.testng.annotations.DataProvider)

Example 18 with ValidationDemo

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

the class AutomaticValidationDemoResource method batchUpdate.

@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchPatchRequest<Integer, ValidationDemo> entityUpdates) {
    Map<Integer, UpdateResponse> results = new HashMap<Integer, UpdateResponse>();
    Map<Integer, RestLiServiceException> errors = new HashMap<Integer, RestLiServiceException>();
    for (Map.Entry<Integer, PatchRequest<ValidationDemo>> entry : entityUpdates.getData().entrySet()) {
        Integer key = entry.getKey();
        PatchRequest<ValidationDemo> patch = entry.getValue();
        results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
    }
    return new BatchUpdateResult<Integer, ValidationDemo>(results, errors);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) HashMap(java.util.HashMap) Map(java.util.Map) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Example 19 with ValidationDemo

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

the class AutomaticValidationDemoResource method batchGet.

@RestMethod.BatchGet
public BatchResult<Integer, ValidationDemo> batchGet(Set<Integer> ids) {
    Map<Integer, ValidationDemo> resultMap = new HashMap<Integer, ValidationDemo>();
    Map<Integer, RestLiServiceException> errorMap = new HashMap<Integer, RestLiServiceException>();
    // Generate entities that are missing a required field
    for (Integer id : ids) {
        if (id == 0) {
            errorMap.put(id, new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST));
        } else if (id == 1) {
            ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
            union.setMyRecord(new myRecord().setFoo1(100).setFoo2(200));
            resultMap.put(id, new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(union));
        } else {
            ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
            union.setMyRecord(new myRecord());
            ValidationDemo validationDemo = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(union);
            resultMap.put(id, validationDemo);
        }
    }
    ;
    return new BatchResult<Integer, ValidationDemo>(resultMap, errorMap);
}
Also used : com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) HashMap(java.util.HashMap) BatchResult(com.linkedin.restli.server.BatchResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Example 20 with ValidationDemo

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

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