use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestCustomDocumentationHandler method testOptionsJson.
@Test
public void testOptionsJson() throws RemoteInvocationException {
Request<OptionsResponse> optionsRequest = new GreetingsRequestBuilders().options().addParam("format", RestLiDocumentationRenderer.DocumentationFormat.JSON.toString().toLowerCase()).build();
OptionsResponse optionsResponse = getClient().sendRequest(optionsRequest).getResponse().getEntity();
Assert.assertEquals(1, optionsResponse.getResourceSchemas().size());
Assert.assertNotNull(optionsResponse.getResourceSchemas().get("com.linkedin.restli.examples.greetings.client.greetings"));
Assert.assertEquals(optionsResponse.getDataSchemas().size(), 10);
List<String> expectedModels = new ArrayList<>(Arrays.asList("com.linkedin.restli.examples.greetings.api.Greeting", "com.linkedin.restli.examples.greetings.api.SearchMetadata", "com.linkedin.restli.examples.groups.api.TransferOwnershipRequest", "com.linkedin.restli.examples.greetings.api.Empty", "com.linkedin.restli.examples.greetings.api.Tone"));
List<String> expectedCustomModels = expectedModels.stream().map(name -> name + CUSTOM_SUFFIX).collect(Collectors.toList());
expectedModels.addAll(expectedCustomModels);
Assert.assertTrue(optionsResponse.getDataSchemas().keySet().containsAll(expectedModels));
for (String schema : expectedModels) {
NamedDataSchema dataSchema = (NamedDataSchema) optionsResponse.getDataSchemas().get(schema);
Assert.assertEquals(dataSchema.getFullName(), schema);
}
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestDocumentationHandler method testOptionsJson.
@Test
public void testOptionsJson() throws RemoteInvocationException {
Request<OptionsResponse> optionsRequest = new GreetingsRequestBuilders().options().addParam("format", RestLiDocumentationRenderer.DocumentationFormat.JSON.toString().toLowerCase()).build();
OptionsResponse optionsResponse = getClient().sendRequest(optionsRequest).getResponse().getEntity();
Assert.assertEquals(1, optionsResponse.getResourceSchemas().size());
Assert.assertNotNull(optionsResponse.getResourceSchemas().get("com.linkedin.restli.examples.greetings.client.greetings"));
Assert.assertEquals(5, optionsResponse.getDataSchemas().size());
List<String> expectedModels = Arrays.asList("com.linkedin.restli.examples.greetings.api.Greeting", "com.linkedin.restli.examples.greetings.api.SearchMetadata", "com.linkedin.restli.examples.groups.api.TransferOwnershipRequest", "com.linkedin.restli.examples.greetings.api.Empty", "com.linkedin.restli.examples.greetings.api.Tone");
Assert.assertTrue(optionsResponse.getDataSchemas().keySet().containsAll(expectedModels));
for (String schema : expectedModels) {
NamedDataSchema dataSchema = (NamedDataSchema) optionsResponse.getDataSchemas().get(schema);
Assert.assertEquals(dataSchema.getFullName(), schema);
}
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestRootBuilderWrapper method testBuilderVersion.
@Test
public void testBuilderVersion() {
RootBuilderWrapper<Long, Greeting> rootBuilderWrapper1 = new RootBuilderWrapper<>(new GreetingsBuilders());
RootBuilderWrapper<Long, Greeting> rootBuilderWrapper2 = new RootBuilderWrapper<>(new GreetingsRequestBuilders());
Assert.assertFalse(rootBuilderWrapper1.areRestLi2Builders());
Assert.assertTrue(rootBuilderWrapper2.areRestLi2Builders());
Assert.assertFalse(rootBuilderWrapper1.get().isRestLi2Builder());
Assert.assertTrue(rootBuilderWrapper2.get().isRestLi2Builder());
RootBuilderWrapper<Long, Greeting> dummyBuilder = new RootBuilderWrapper<>(new MyRequestBuilders());
Assert.assertFalse(dummyBuilder.areRestLi2Builders());
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestRequestCompression method testUpdate.
@Test(dataProvider = "requestData", retryAnalyzer = ThreeRetries.class)
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<>();
if (requestCompressionConfig != null) {
requestCompressionConfigs.put(SERVICE_NAME, requestCompressionConfig);
}
HttpClientFactory httpClientFactory = new HttpClientFactory.Builder().setFilterChain(FilterChains.empty()).setEventLoopGroup(new NioEventLoopGroup()).setShutDownFactory(true).setScheduleExecutorService(executor).setShutdownScheduledExecutorService(true).setCallbackExecutor(null).setShutdownCallbackExecutor(false).setJmxManager(AbstractJmxManager.NULL_JMX_MANAGER).setRequestCompressionThresholdDefault(500).setRequestCompressionConfigs(requestCompressionConfigs).build();
Map<String, String> properties = new HashMap<>();
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<>(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<>();
client.shutdown(callback1);
callback1.get(30, TimeUnit.SECONDS);
FutureCallback<None> callback2 = new FutureCallback<>();
httpClientFactory.shutdown(callback2);
callback2.get(30, TimeUnit.SECONDS);
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testBatchGetEntity.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
public void testBatchGetEntity(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new GreetingsRequestBuilders(requestOptions).batchGet().ids(ids).build();
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = restClient.sendRequest(request).getResponse();
BatchKVResponse<Long, EntityResponse<Greeting>> batchResponse = response.getEntity();
Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Aggregations