use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testBody.
@Test
public void testBody() throws IOException {
TestRecord entity = fakeEntity(0);
CreateRequest<TestRecord> request = fakeCreateRequest(entity);
NoOpCallback<EmptyRecord> callback = new NoOpCallback<EmptyRecord>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request, callback).build();
IndividualRequest individualRequest = new IndividualRequest().setMethod(HttpMethod.POST.name()).setHeaders(new StringMap(HEADERS)).setRelativeUrl(BASE_URI).setBody(new IndividualBody(entity.data()));
MultiplexedRequestContent expectedRequests = new MultiplexedRequestContent();
expectedRequests.setRequests(new IndividualRequestMap(ImmutableMap.of("0", individualRequest)));
assertMultiplexedRequestContentEquals(multiplexedRequest.getContent(), expectedRequests);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingsClientAcceptTypes method testCreate.
@SuppressWarnings("deprecation")
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "oldBuildersClientDataDataProvider")
public void testCreate(RestClient restClient, String expectedContentType, GreetingsBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Hello there!");
greeting.setTone(Tone.FRIENDLY);
Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
Response<EmptyRecord> response = restClient.sendRequest(createRequest).getResponse();
Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
long id = createResponse.getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(id, Long.parseLong(stringId));
Request<Greeting> getRequest = builders.get().id(id).build();
Response<Greeting> getResponse = restClient.sendRequest(getRequest).getResponse();
Assert.assertEquals(getResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
Greeting responseGreeting = getResponse.getEntity();
Assert.assertEquals(responseGreeting.getMessage(), greeting.getMessage());
Assert.assertEquals(responseGreeting.getTone(), greeting.getTone());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGroupsClient method testCollectionCreateGetUpdateDeleteId.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateGetUpdateDeleteId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
// find with optional params
Group group = new Group();
String name = "test";
int memberID = 1;
group.setName(name);
group.setOwner(buildGroupMembership(memberID, "a@a.a", "f", "l"));
GroupMembershipParam param = new GroupMembershipParam();
param.setIntParameter(1);
param.setStringParameter("String");
final GroupsRequestBuilders groupBuilders = new GroupsRequestBuilders(requestOptions);
final GroupMembershipsRequestBuilders membershipBuilders = new GroupMembershipsRequestBuilders(requestOptions);
// Create
Response<IdResponse<Integer>> response = getClient().sendRequest(groupBuilders.create().input(group).build()).getResponse();
Assert.assertEquals(response.getStatus(), 201);
Integer createdId = response.getEntity().getId();
Assert.assertNotNull(createdId);
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(createdId.intValue(), Integer.parseInt(stringId));
// Get newly created group and verify name
Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse().getEntity().getName(), name);
// Partial update - change name
String newName = "new name";
group.setName(newName);
PatchRequest<Group> patch = PatchGenerator.diffEmpty(group);
ResponseFuture<EmptyRecord> responseFuture = getClient().sendRequest(groupBuilders.partialUpdate().id(createdId).input(patch).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
// Get updated group and verify name
Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse().getEntity().getName(), newName);
// Delete
responseFuture = getClient().sendRequest(groupBuilders.delete().id(createdId).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
// Verify deleted
try {
getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse();
Assert.fail("Expected RestLiResponseException");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), 404);
}
// Cleanup - delete the owner's membership that was created along with the group
responseFuture = getClient().sendRequest(membershipBuilders.delete().id(buildCompoundKey(memberID, createdId)).build());
Assert.assertEquals(204, responseFuture.getResponse().getStatus());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestRequestCompression method testUpdate.
@Test(dataProvider = "requestData")
public void testUpdate(CompressionConfig requestCompressionConfig, String supportedEncodings, RestliRequestOptions restliRequestOptions, int messageLength, String testHelpHeader) throws RemoteInvocationException, CloneNotSupportedException, InterruptedException, ExecutionException, TimeoutException {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("R2 Netty Scheduler"));
Map<String, CompressionConfig> requestCompressionConfigs = new HashMap<String, CompressionConfig>();
if (requestCompressionConfig != null) {
requestCompressionConfigs.put(SERVICE_NAME, requestCompressionConfig);
}
HttpClientFactory httpClientFactory = new HttpClientFactory(FilterChains.empty(), new NioEventLoopGroup(), true, executor, true, null, false, AbstractJmxManager.NULL_JMX_MANAGER, // The default compression threshold is between small and large.
500, requestCompressionConfigs);
Map<String, String> properties = new HashMap<String, String>();
properties.put(HttpClientFactory.HTTP_REQUEST_CONTENT_ENCODINGS, supportedEncodings);
properties.put(HttpClientFactory.HTTP_SERVICE_NAME, SERVICE_NAME);
TransportClientAdapter clientAdapter1 = new TransportClientAdapter(httpClientFactory.getClient(properties));
RestClient client = new RestClient(clientAdapter1, FILTERS_URI_PREFIX);
RootBuilderWrapper<Long, Greeting> builders = new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders(restliRequestOptions));
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = client.sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
String response1 = greetingResponse.getEntity().getMessage();
Assert.assertNotNull(response1);
// POST
Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
char[] As = new char[messageLength];
Arrays.fill(As, 'A');
String message = new String(As);
greeting.setMessage(message);
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).setHeader(TEST_HELP_HEADER, testHelpHeader).build();
client.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = client.sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, message);
FutureCallback<None> callback1 = new FutureCallback<None>();
client.shutdown(callback1);
callback1.get(30, TimeUnit.SECONDS);
FutureCallback<None> callback2 = new FutureCallback<None>();
httpClientFactory.shutdown(callback2);
callback2.get(30, TimeUnit.SECONDS);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionPartialUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubCollectionPartialUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException, URISyntaxException {
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = getClient().sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
Greeting original = greetingResponse.getEntity();
// PUT
Greeting greeting = new Greeting(original.data().copy());
greeting.setMessage(original.getMessage() + " Again");
PatchRequest<Greeting> patch = PatchGenerator.diff(original, greeting);
Request<EmptyRecord> writeRequest = builders.partialUpdate().id(1L).input(patch).build();
int status = getClient().sendRequest(writeRequest).getResponse().getStatus();
Assert.assertEquals(status, HttpStatus.S_204_NO_CONTENT.getCode());
// GET again, to verify that our PUT worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, greeting.getMessage());
}
Aggregations