Search in sources :

Example 1 with GreetingsRequestBuilders

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);
    }
}
Also used : AfterClass(org.testng.annotations.AfterClass) Arrays(java.util.Arrays) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) BeforeClass(org.testng.annotations.BeforeClass) RestLiJSONDocumentationRenderer(com.linkedin.restli.docgen.RestLiJSONDocumentationRenderer) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) DefaultDocumentationRequestHandler(com.linkedin.restli.docgen.DefaultDocumentationRequestHandler) RestLiConfig(com.linkedin.restli.server.RestLiConfig) IOException(java.io.IOException) Test(org.testng.annotations.Test) DataSchemaResolver(com.linkedin.data.schema.DataSchemaResolver) RestLiResourceRelationship(com.linkedin.restli.docgen.RestLiResourceRelationship) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DataMap(com.linkedin.data.DataMap) RestLiDocumentationRenderer(com.linkedin.restli.docgen.RestLiDocumentationRenderer) List(java.util.List) Assert(org.testng.Assert) Request(com.linkedin.restli.client.Request) Map(java.util.Map) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) OptionsResponse(com.linkedin.restli.common.OptionsResponse) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayList(java.util.ArrayList) OptionsResponse(com.linkedin.restli.common.OptionsResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with GreetingsRequestBuilders

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);
    }
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) OptionsResponse(com.linkedin.restli.common.OptionsResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 3 with GreetingsRequestBuilders

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());
}
Also used : GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) Test(org.testng.annotations.Test)

Example 4 with GreetingsRequestBuilders

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) HashMap(java.util.HashMap) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) FutureCallback(com.linkedin.common.callback.FutureCallback) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestClient(com.linkedin.restli.client.RestClient) None(com.linkedin.common.util.None) CompressionConfig(com.linkedin.r2.filter.CompressionConfig) Test(org.testng.annotations.Test)

Example 5 with GreetingsRequestBuilders

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());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EntityResponse(com.linkedin.restli.common.EntityResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) Test(org.testng.annotations.Test)

Aggregations

GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)16 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)14 Test (org.testng.annotations.Test)11 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)4 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)4 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)3 IdResponse (com.linkedin.restli.common.IdResponse)3 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)3 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)2 RestClient (com.linkedin.restli.client.RestClient)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2 OptionsResponse (com.linkedin.restli.common.OptionsResponse)2 HashMap (java.util.HashMap)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 DataMap (com.linkedin.data.DataMap)1 DataSchemaResolver (com.linkedin.data.schema.DataSchemaResolver)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)1