Search in sources :

Example 1 with CustomTypes2RequestBuilders

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

the class TestCustomTypesClient method testCollectionBatchCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionBatchCreateId(RestliRequestOptions options) throws RemoteInvocationException {
    CustomTypes2RequestBuilders builders = new CustomTypes2RequestBuilders(options);
    BatchCreateIdRequest<CustomLong, Greeting> request = builders.batchCreate().input(new Greeting().setId(1)).input(new Greeting().setId(2)).build();
    Response<BatchCreateIdResponse<CustomLong>> response = getClient().sendRequest(request).getResponse();
    List<CreateIdStatus<CustomLong>> results = response.getEntity().getElements();
    Set<CustomLong> expectedKeys = new HashSet<>();
    expectedKeys.add(new CustomLong(1L));
    expectedKeys.add(new CustomLong(2L));
    for (CreateIdStatus<CustomLong> status : results) {
        Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
        Assert.assertTrue(expectedKeys.contains(status.getKey()));
        @SuppressWarnings("deprecation") String id = status.getId();
        Assert.assertEquals(BatchResponse.keyToString(status.getKey(), ProtocolVersionUtil.extractProtocolVersion(response.getHeaders())), id);
        expectedKeys.remove(status.getKey());
    }
    Assert.assertTrue(expectedKeys.isEmpty());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypes2RequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with CustomTypes2RequestBuilders

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

the class TestCustomTypesClient method testCollectionBatchGetEntity.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionBatchGetEntity(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Request<BatchKVResponse<CustomLong, EntityResponse<Greeting>>> request = new CustomTypes2RequestBuilders(requestOptions).batchGet().ids(new CustomLong(1L), new CustomLong(2L), new CustomLong(3L)).build();
    Map<CustomLong, EntityResponse<Greeting>> greetings = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertEquals(greetings.size(), 3);
    Assert.assertEquals(greetings.get(new CustomLong(1L)).getEntity().getId().longValue(), 1L);
    Assert.assertEquals(greetings.get(new CustomLong(2L)).getEntity().getId().longValue(), 2L);
    Assert.assertEquals(greetings.get(new CustomLong(3L)).getEntity().getId().longValue(), 3L);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EntityResponse(com.linkedin.restli.common.EntityResponse) CustomTypes2RequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 3 with CustomTypes2RequestBuilders

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

the class TestCustomTypesClient method testCollectionCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    CreateIdRequest<CustomLong, Greeting> request = new CustomTypes2RequestBuilders(requestOptions).create().input(new Greeting().setId(10)).build();
    Response<IdResponse<CustomLong>> response = getClient().sendRequest(request).getResponse();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
    Assert.assertEquals(response.getEntity().getId(), new CustomLong(10L));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) CustomTypes2RequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Test(org.testng.annotations.Test)

Example 4 with CustomTypes2RequestBuilders

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

the class TestCustomTypesRequestBuilders method testCollectionBatchGetEntityKey.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2BatchDataProvider")
public void testCollectionBatchGetEntityKey(ProtocolVersion version, String expectedUri) throws IOException, RestException {
    Request<BatchKVResponse<CustomLong, EntityResponse<Greeting>>> request = new CustomTypes2RequestBuilders().batchGet().ids(new CustomLong(1L), new CustomLong(2L), new CustomLong(3L)).build();
    checkRequestBuilder(request, ResourceMethod.BATCH_GET, BatchEntityResponseDecoder.class, expectedUri, null, version);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypes2RequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Aggregations

CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)4 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)4 CustomTypes2RequestBuilders (com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders)4 Test (org.testng.annotations.Test)4 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)2 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)1 EntityResponse (com.linkedin.restli.common.EntityResponse)1 IdResponse (com.linkedin.restli.common.IdResponse)1 HashSet (java.util.HashSet)1