use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestRestLiValidationFromClient method testCreateSuccess.
@Test(dataProvider = "provideCreateSuccessData")
public void testCreateSuccess(Object builder, ValidationDemo validationDemo) {
ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).create().validateInput(validationDemo);
Assert.assertEquals(result.isValid(), true);
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestStreamingGreetings method resourceMethodDoesNotAcceptAttachments.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void resourceMethodDoesNotAcceptAttachments(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
//Resource method does not desire request attachments. Assert that all the attachments are drained and that a 400
//bad request is observed.
final RestLiTestAttachmentDataSource greetingAttachment = new RestLiTestAttachmentDataSource("1", ByteString.copyString("clientData", Charset.defaultCharset()));
RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, Object> methodBuilderWrapper = builders.action("actionNoAttachmentsAllowed");
methodBuilderWrapper.appendSingleAttachment(greetingAttachment);
final Request<Object> request = methodBuilderWrapper.build();
try {
getClient().sendRequest(request).getResponse().getEntity();
Assert.fail();
} catch (final RestLiResponseException responseException) {
Assert.assertEquals(responseException.getStatus(), 400);
Assert.assertEquals(responseException.getServiceErrorMessage(), "Resource method endpoint invoked does not accept any request attachments.");
}
//Then verify the response and request attachments were fully absorbed.
Assert.assertTrue(greetingAttachment.finished());
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestRestLiValidationFromClient method testPartialUpdateFailure.
@Test(dataProvider = "providePartialUpdateFailureData")
public void testPartialUpdateFailure(Object builder, String patch, String errorMessage) {
PatchRequest<ValidationDemo> patchRequest = PatchBuilder.buildPatchFromString(patch);
ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).partialUpdate().validateInput(patchRequest);
Assert.assertEquals(result.isValid(), false);
Assert.assertEquals(result.getMessages().toString(), errorMessage);
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestGreetingsClient method createBatchTestDataSerially.
/**
* Creates batch data.
*
* @param greetings the greetings that we want to create
*
* @return the ids of the created Greetings
* @throws RemoteInvocationException
*/
private List<Long> createBatchTestDataSerially(RootBuilderWrapper<Long, Greeting> builders, List<Greeting> greetings) throws RemoteInvocationException {
List<Long> createdIds = new ArrayList<Long>();
for (Greeting greeting : greetings) {
RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilder = builders.create();
Long createdId;
if (createBuilder.isRestLi2Builder()) {
Object objBuilder = createBuilder.getBuilder();
@SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(greeting).build();
Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
createdId = response.getEntity().getId();
} else {
Request<EmptyRecord> request = createBuilder.input(greeting).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
createdId = createResponse.getId();
}
createdIds.add(createdId);
}
return createdIds;
}
Aggregations