use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestNullGreetingsClient method testNullHttpStatusCreateResponse.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testNullHttpStatusCreateResponse(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
//Forces the server to return a valid CreateResponse but with a null HttpStatus inside of it
final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
final Greeting illGreeting = new Greeting().setMessage("nullHttpStatus").setTone(Tone.INSULTING);
createAndAssertNullMessages(methodBuilderWrapper, illGreeting);
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestStreamingGreetings method fullStreamTest.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void fullStreamTest(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
//Perform a create to the server to store some bytes via an attachment.
final byte[] clientSuppliedBytes = "ClientSupplied".getBytes();
final RestLiTestAttachmentDataSource greetingAttachment = new RestLiTestAttachmentDataSource("1", ByteString.copy(clientSuppliedBytes));
final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
methodBuilderWrapper.appendSingleAttachment(greetingAttachment);
//Provide a header to verify the server's ability to transform the first part into the RestRequest.
methodBuilderWrapper.setHeader("createHeader", "createHeaderValue");
final Greeting greeting = new Greeting().setMessage("A greeting with an attachment");
final Request<EmptyRecord> createRequest = methodBuilderWrapper.input(greeting).build();
try {
final Response<EmptyRecord> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
//Verify that headers propagate properly.
Assert.assertEquals(createResponse.getHeader("createHeader"), "createHeaderValue");
} catch (final RestLiResponseException responseException) {
Assert.fail("We should not reach here!", responseException);
}
//Then perform a GET and verify the bytes are present
try {
final Request<Greeting> getRequest = builders.get().id(1l).setHeader("getHeader", "getHeaderValue").build();
final Response<Greeting> getResponse = getClient().sendRequest(getRequest).getResponse();
Assert.assertEquals(getResponse.getStatus(), 200);
//Verify that headers propagate properly.
Assert.assertEquals(getResponse.getHeader("getHeader"), "getHeaderValue");
Assert.assertEquals(getResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE), RestConstants.HEADER_VALUE_APPLICATION_JSON);
Assert.assertEquals(getResponse.getEntity().getMessage(), "Your greeting has an attachment since you were kind and decided you wanted to read it!");
Assert.assertTrue(getResponse.hasAttachments(), "We must have some response attachments");
RestLiAttachmentReader attachmentReader = getResponse.getAttachmentReader();
final CountDownLatch latch = new CountDownLatch(1);
final GreetingBlobReaderCallback greetingBlobReaderCallback = new GreetingBlobReaderCallback(latch);
attachmentReader.registerAttachmentReaderCallback(greetingBlobReaderCallback);
try {
latch.await(3000, TimeUnit.SECONDS);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().size(), 1);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().get(0), ByteString.copy(clientSuppliedBytes));
} catch (Exception exception) {
Assert.fail();
}
} catch (final RestLiResponseException responseException) {
Assert.fail("We should not reach here!", responseException);
}
}
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 TestRestLiValidationFromClient method testUpdateFailure.
@Test(dataProvider = "provideUpdateFailureData")
public void testUpdateFailure(Object builder, ValidationDemo validationDemo, String errorMessage) {
ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).update().validateInput(validationDemo);
Assert.assertEquals(result.isValid(), false);
Assert.assertTrue(result.getMessages().toString().contains(errorMessage));
}
use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.
the class TestRestLiValidationFromClient method testCreateFailure.
@Test(dataProvider = "provideCreateFailureData")
public void testCreateFailure(Object builder, ValidationDemo validationDemo, String errorMessage) {
ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).create().validateInput(validationDemo);
Assert.assertEquals(result.isValid(), false);
Assert.assertTrue(result.getMessages().toString().contains(errorMessage));
}
Aggregations