Search in sources :

Example 16 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testPostsWithCharset.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testPostsWithCharset(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<Greeting> request = builders.<Greeting>action("SomeAction").id(1L).setActionParam("A", 1).setActionParam("B", "").setActionParam("C", new TransferOwnershipRequest()).setActionParam("D", new TransferOwnershipRequest()).setActionParam("E", 3).setHeader("Content-Type", "application/json; charset=UTF-8").build();
    Response<Greeting> response = getClient().sendRequest(request).getResponse();
    Greeting actionGreeting = response.getEntity();
    Assert.assertEquals(actionGreeting.getMessage(), "This is a newly created greeting");
    Greeting createGreeting = new Greeting();
    createGreeting.setMessage("Hello there!");
    createGreeting.setTone(Tone.FRIENDLY);
    Request<EmptyRecord> createRequest = builders.create().input(createGreeting).setHeader("Content-Type", "application/json; charset=UTF-8").build();
    Response<EmptyRecord> emptyRecordResponse = getClient().sendRequest(createRequest).getResponse();
    Assert.assertNull(emptyRecordResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) TransferOwnershipRequest(com.linkedin.restli.examples.groups.api.TransferOwnershipRequest) Test(org.testng.annotations.Test)

Example 17 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestCustomTypesClient method testCollectionSubResourceGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request4BuilderDataProvider")
public void testCollectionSubResourceGet(RootBuilderWrapper<CustomLong, Greeting> builders) throws RemoteInvocationException {
    Long id2 = 2L;
    Long id4 = 4L;
    Request<Greeting> request = builders.get().setPathKey("customTypes2Id", new CustomLong(id2)).id(new CustomLong(id4)).build();
    Greeting result = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(result.getId(), new Long(id2 * id4));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomNonNegativeLong(com.linkedin.restli.examples.custom.types.CustomNonNegativeLong) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Test(org.testng.annotations.Test)

Example 18 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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 19 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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 20 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)250 Test (org.testng.annotations.Test)195 CollectionResponse (com.linkedin.restli.common.CollectionResponse)59 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)33 EmptyRecord (com.linkedin.restli.common.EmptyRecord)33 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)20 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)18 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)12 EntityResponse (com.linkedin.restli.common.EntityResponse)12 BatchResponse (com.linkedin.restli.common.BatchResponse)11 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)11 IdResponse (com.linkedin.restli.common.IdResponse)10 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)10 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)9 ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)8 Response (com.linkedin.restli.client.Response)8 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)8 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8