Search in sources :

Example 6 with CustomLong

use of com.linkedin.restli.examples.custom.types.CustomLong in project rest.li by linkedin.

the class TestCustomTypesClient method testBatchUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request3BuilderDataProvider")
public void testBatchUpdate(RootBuilderWrapper<CompoundKey, Greeting> builders) throws RemoteInvocationException {
    Long lo = 5L;
    Long date = 13L;
    CustomTypes3Builders.Key key = new CustomTypes3Builders.Key().setLongId(new CustomLong(lo)).setDateId(new Date(date));
    RequestBuilder<? extends Request<BatchKVResponse<CompoundKey, UpdateStatus>>> batchUpdateRequest = builders.batchUpdate().input(key, new Greeting().setId(1).setMessage("foo")).getBuilder();
    BatchKVResponse<CompoundKey, UpdateStatus> response = getClient().sendRequest(batchUpdateRequest).getResponse().getEntity();
    Assert.assertEquals(response.getResults().keySet().size(), 1);
    CompoundKey expected = new CompoundKey();
    expected.append("dateId", new Date(date));
    expected.append("longId", new CustomLong(lo));
    Assert.assertEquals(response.getResults().keySet().iterator().next(), expected);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypes3Builders(com.linkedin.restli.examples.greetings.client.CustomTypes3Builders) UpdateStatus(com.linkedin.restli.common.UpdateStatus) CompoundKey(com.linkedin.restli.common.CompoundKey) CustomNonNegativeLong(com.linkedin.restli.examples.custom.types.CustomNonNegativeLong) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CompoundKey(com.linkedin.restli.common.CompoundKey) Date(java.util.Date) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 7 with CustomLong

use of com.linkedin.restli.examples.custom.types.CustomLong 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 8 with CustomLong

use of com.linkedin.restli.examples.custom.types.CustomLong 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<CustomLong>();
    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) ByteString(com.linkedin.data.ByteString) CustomTypes2Builders(com.linkedin.restli.examples.greetings.client.CustomTypes2Builders) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with CustomLong

use of com.linkedin.restli.examples.custom.types.CustomLong 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<CustomLong>();
    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) ByteString(com.linkedin.data.ByteString) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with CustomLong

use of com.linkedin.restli.examples.custom.types.CustomLong in project rest.li by linkedin.

the class TestCustomTypesClient method testCustomLongArrayOBO.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testCustomLongArrayOBO(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> request = builders.findBy("CustomLongArray").addQueryParam("Ls", new CustomLong(1L)).addQueryParam("Ls", new CustomLong(2L)).build();
    List<Greeting> elements = getClient().sendRequest(request).getResponse().getEntity().getElements();
    Assert.assertEquals(elements.size(), 0);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Test(org.testng.annotations.Test)

Aggregations

CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)23 Test (org.testng.annotations.Test)22 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)19 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)6 CustomNonNegativeLong (com.linkedin.restli.examples.custom.types.CustomNonNegativeLong)5 CustomTypes2Builders (com.linkedin.restli.examples.greetings.client.CustomTypes2Builders)5 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 CustomTypes2RequestBuilders (com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders)4 Date (java.util.Date)4 ByteString (com.linkedin.data.ByteString)3 CompoundKey (com.linkedin.restli.common.CompoundKey)3 UpdateStatus (com.linkedin.restli.common.UpdateStatus)3 CustomTypes3Builders (com.linkedin.restli.examples.greetings.client.CustomTypes3Builders)3 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 BatchResponse (com.linkedin.restli.common.BatchResponse)2 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CreateResponse (com.linkedin.restli.client.response.CreateResponse)1 CreateStatus (com.linkedin.restli.common.CreateStatus)1