use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestResLiValidationWithProjection method testProjectionWithInvalidFields.
@Test
public void testProjectionWithInvalidFields() throws RemoteInvocationException {
RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<Integer, ValidationDemo>(new AutoValidationWithProjectionBuilders());
Request<CollectionResponse<ValidationDemo>> request = wrapper.findBy("searchWithProjection").fields(//invalid
ValidationDemo.fields().stringA(), ValidationDemo.fields().stringB(), //invalid
ValidationDemo.fields().includedA(), //invalid
ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo1(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), //invalid
ValidationDemo.fields().ArrayWithInlineRecord().items().bar2(), ValidationDemo.fields().MapWithTyperefs().values().id(), //invalid
ValidationDemo.fields().MapWithTyperefs().values().tone(), //invalid
ValidationDemo.fields().validationDemoNext().stringA()).build();
try {
_restClientAuto.sendRequest(request).getResponse();
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getServiceErrorMessage(), "ERROR :: /validationDemoNext/stringA :: length of \"invalid, length is larger than the max\" is out of range 1...10\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/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");
}
}
use of com.linkedin.restli.test.util.RootBuilderWrapper 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");
}
}
use of com.linkedin.restli.test.util.RootBuilderWrapper 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 } };
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestDebugRequestHandlers method createNewGreetingOnTheServer.
private Long createNewGreetingOnTheServer(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Greeting newGreeting = new Greeting().setMessage("New Greeting!").setTone(Tone.FRIENDLY);
RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilderWrapper = builders.create();
Long createdId;
if (createBuilderWrapper.isRestLi2Builder()) {
Object objBuilder = createBuilderWrapper.getBuilder();
@SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(newGreeting).build();
Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
createdId = response.getEntity().getId();
} else {
Request<EmptyRecord> request = createBuilderWrapper.input(newGreeting).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
createdId = createResponse.getId();
}
return createdId;
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestCustomContextData method testUpdateCustomData.
@Test
public void testUpdateCustomData() throws RemoteInvocationException, IOException {
List<Filter> filters = Arrays.asList(new TestFilter());
init(filters);
RootBuilderWrapper<Long, Greeting> builders = new RootBuilderWrapper<>(new GreetingsBuilders());
final Request<Object> req = builders.action("modifyCustomContext").build();
Response<Object> response = getClient().sendRequest(req).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
}
Aggregations