Search in sources :

Example 1 with CustomTypes2Builders

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

the class TestCustomTypesRequestBuilders method testTypeRefParam.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2CreateBuilderDataProvider")
public void testTypeRefParam(ProtocolVersion version, String expectedUri) throws IOException, RestException {
    CreateRequest<Greeting> request = new CustomTypes2Builders().create().unionRefParamParam(UnionRefInline.create(10)).build();
    checkRequestBuilder(request, ResourceMethod.CREATE, CreateResponseDecoder.class, expectedUri, null, version);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypes2Builders(com.linkedin.restli.examples.greetings.client.CustomTypes2Builders) Test(org.testng.annotations.Test)

Example 2 with CustomTypes2Builders

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

the class TestCustomTypesClient method testCollectionBatchCreate.

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

Example 3 with CustomTypes2Builders

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

the class TestCustomTypesClient method testCollectionCreate.

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

Example 4 with CustomTypes2Builders

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

the class TestCustomTypesClient method testCollectionBatchGet.

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

Example 5 with CustomTypes2Builders

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

the class TestCustomTypesClient method testCollectionBatchGetKV.

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

Aggregations

CustomTypes2Builders (com.linkedin.restli.examples.greetings.client.CustomTypes2Builders)6 Test (org.testng.annotations.Test)6 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)5 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)5 BatchResponse (com.linkedin.restli.common.BatchResponse)2 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)1 CreateResponse (com.linkedin.restli.client.response.CreateResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)1 CreateStatus (com.linkedin.restli.common.CreateStatus)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 HashSet (java.util.HashSet)1