Search in sources :

Example 1 with GreetingsBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.

the class TestGreetingsClient method testOldCookbookInBatch.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testOldCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
    final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
    // GET
    final BatchGetRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
    Request<BatchResponse<Greeting>> request = batchGetBuilder.ids(1L).build();
    ResponseFuture<BatchResponse<Greeting>> future = getClient().sendRequest(request);
    Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
    // PUT
    Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get("1").data().copy());
    greeting.setMessage("This is a new message!");
    Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
    getClient().sendRequest(writeRequest).getResponse();
    // GET again, to verify that our POST worked.
    Request<BatchResponse<Greeting>> request2 = builders.batchGet().ids(1L).build();
    ResponseFuture<BatchResponse<Greeting>> future2 = getClient().sendRequest(request2);
    greetingResponse = future2.get();
    Greeting repeatedGreeting = new Greeting();
    repeatedGreeting.setMessage("Hello Hello");
    repeatedGreeting.setTone(Tone.SINCERE);
    Request<CollectionResponse<CreateStatus>> request3 = builders.batchCreate().inputs(Arrays.asList(repeatedGreeting, repeatedGreeting)).build();
    CollectionResponse<CreateStatus> statuses = getClient().sendRequest(request3).getResponse().getEntity();
    for (CreateStatus status : statuses.getElements()) {
        Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
        @SuppressWarnings("deprecation") String id = status.getId();
        Assert.assertNotNull(id);
    }
}
Also used : CreateStatus(com.linkedin.restli.common.CreateStatus) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchResponse(com.linkedin.restli.common.BatchResponse) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) Test(org.testng.annotations.Test)

Example 2 with GreetingsBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testBatchGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
public void testBatchGet(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
    Request<BatchResponse<Greeting>> request = new GreetingsBuilders(requestOptions).batchGet().ids(ids).build();
    Response<BatchResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
    BatchResponse<Greeting> batchResponse = response.getEntity();
    Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Also used : GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchResponse(com.linkedin.restli.common.BatchResponse) Test(org.testng.annotations.Test)

Example 3 with GreetingsBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.

the class TestCompressionServer method testOldCookbookInBatch.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCookbookDataProvider")
public void testOldCookbookInBatch(RestClient client, RestliRequestOptions requestOptions) throws Exception {
    final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
    // GET
    Greeting greetingResult = getOldCookbookBatchGetResult(client, requestOptions);
    // POST
    Greeting greeting = new Greeting(greetingResult.data().copy());
    greeting.setMessage("This is a new message!");
    Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
    client.sendRequest(writeRequest).getResponse();
    // GET again, to verify that our POST worked.
    getOldCookbookBatchGetResult(client, requestOptions);
    // batch Create
    Greeting repeatedGreeting = new Greeting();
    repeatedGreeting.setMessage("Hello Hello");
    repeatedGreeting.setTone(Tone.SINCERE);
    List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
    Request<CollectionResponse<CreateStatus>> batchCreateRequest = builders.batchCreate().inputs(entities).build();
    List<CreateStatus> statuses = client.sendRequest(batchCreateRequest).getResponse().getEntity().getElements();
    for (CreateStatus status : statuses) {
        Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
        @SuppressWarnings("deprecation") String id = status.getId();
        Assert.assertNotNull(id);
    }
}
Also used : GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) CreateStatus(com.linkedin.restli.common.CreateStatus) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 4 with GreetingsBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.

the class TestRootBuilderWrapper method testBuilderVersion.

@Test
public void testBuilderVersion() {
    RootBuilderWrapper<Long, Greeting> rootBuilderWrapper1 = new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders());
    RootBuilderWrapper<Long, Greeting> rootBuilderWrapper2 = new RootBuilderWrapper<Long, Greeting>(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<Long, Greeting>(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 5 with GreetingsBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.

the class TestRootBuilderWrapper method testWrapperMethodNameGeneration.

@Test
public void testWrapperMethodNameGeneration() {
    RootBuilderWrapper<Long, Greeting> rootBuilderWrapper1 = new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders());
    RootBuilderWrapper<Long, Greeting> rootBuilderWrapper2 = new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders());
    rootBuilderWrapper1.findBy("searchWithTones").addQueryParam("tones", Tone.FRIENDLY);
    rootBuilderWrapper1.findBy("searchWithTones").setParam("Tones", new Tone[3]);
    rootBuilderWrapper1.findBy("SearchWithTones").addQueryParam("Tones", Tone.FRIENDLY);
    rootBuilderWrapper1.findBy("SearchWithTones").setParam("tones", new Tone[3]);
    rootBuilderWrapper1.action("someAction").setParam("a", 5);
    rootBuilderWrapper2.action("someAction").setParam("a", 5);
    rootBuilderWrapper1.action("SomeAction").setParam("A", 5);
    rootBuilderWrapper2.action("SomeAction").setParam("A", 5);
}
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)

Aggregations

GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)11 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)9 Test (org.testng.annotations.Test)9 BatchResponse (com.linkedin.restli.common.BatchResponse)5 RestClient (com.linkedin.restli.client.RestClient)3 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)3 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)3 HashMap (java.util.HashMap)3 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 CreateStatus (com.linkedin.restli.common.CreateStatus)2 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)1 Client (com.linkedin.r2.transport.common.Client)1 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)1 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)1 NamedThreadFactory (com.linkedin.r2.util.NamedThreadFactory)1 CreateResponse (com.linkedin.restli.client.response.CreateResponse)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 DataProvider (org.testng.annotations.DataProvider)1