Search in sources :

Example 26 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestSimpleResourceHierarchy method testSubCollectionBatchGetEntity.

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

Example 27 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestNullGreetingsClient method testBatchUpdateUnsupportedNullKeyMap.

/*
   * This test is one of the few areas in this test suite where we don't expect an exception.
   * The purpose of this test is to make sure Rest.li can handle java.util.concurrent.ConcurrentHashMap(s) sent
   * back by resource methods.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchUpdateUnsupportedNullKeyMap(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
    Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(7l, someGreeting).build();
    Response<BatchKVResponse<Long, UpdateStatus>> response = getClient().sendRequest(writeRequest).getResponse();
    Map<Long, ErrorResponse> actualErrors = response.getEntity().getErrors();
    Assert.assertEquals(actualErrors.size(), 0, "Errors map should be empty");
    Map<Long, UpdateStatus> actualResults = response.getEntity().getResults();
    Map<Long, UpdateStatus> expectedResults = new HashMap<Long, UpdateStatus>();
    UpdateStatus updateStatus = new UpdateStatus().setStatus(201);
    expectedResults.put(3l, updateStatus);
    Assert.assertEquals(actualResults, expectedResults, "The results map should be correct");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateStatus(com.linkedin.restli.common.UpdateStatus) HashMap(java.util.HashMap) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 28 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestNullGreetingsClient method testBatchGetUnsupportedNullKeyMap.

/*
   * This test is one of the few areas in this test suite where we don't expect an exception.
   * The purpose of this test is to make sure Rest.li can handle java.util.concurrent.ConcurrentHashMap(s) sent
   * back by resource methods.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchGetRequestBuilderDataProvider")
public void testBatchGetUnsupportedNullKeyMap(final BatchGetEntityRequestBuilder<Long, Greeting> builder) throws RemoteInvocationException, CloneNotSupportedException {
    BatchGetEntityRequest<Long, Greeting> request = builder.ids(ImmutableSet.of(5l)).fields(Greeting.fields().id(), Greeting.fields().message()).build();
    Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = getClient().sendRequest(request).getResponse();
    final Greeting actualGreeting = response.getEntity().getResults().get(0l).getEntity();
    Assert.assertEquals(actualGreeting.getMessage(), "Good morning!", "We should get the correct Greeting back");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 29 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestNullGreetingsClient method sendBatchUpdateAndAssert.

private void sendBatchUpdateAndAssert(final RootBuilderWrapper<Long, Greeting> builders, Long id) throws RemoteInvocationException {
    try {
        final Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
        Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(id, someGreeting).build();
        getClient().sendRequest(writeRequest).getResponse();
    } catch (final RestLiResponseException responseException) {
        assertCorrectInternalServerMessageForNull(responseException, "batch_update");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse)

Example 30 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestGreetingsClient method testBatchPartialUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchPartialUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
    List<Greeting> greetings = generateBatchTestData(3, "BatchPatch", Tone.FRIENDLY);
    @SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
    addIdsToGeneratedGreetings(createdIds, greetings);
    // Patch the created Greetings
    Map<Long, PatchRequest<Greeting>> patchedGreetingsDiffs = new HashMap<Long, PatchRequest<Greeting>>();
    List<Greeting> patchedGreetings = new ArrayList<Greeting>();
    for (Greeting greeting : greetings) {
        Greeting patchedGreeting = new Greeting(greeting.data().copy());
        patchedGreeting.setMessage(patchedGreeting.getMessage().toUpperCase());
        PatchRequest<Greeting> patchRequest = PatchGenerator.diff(greeting, patchedGreeting);
        patchedGreetingsDiffs.put(patchedGreeting.getId(), patchRequest);
        patchedGreetings.add(patchedGreeting);
    }
    // Batch patch
    Request<BatchKVResponse<Long, UpdateStatus>> batchUpdateRequest = builders.batchPartialUpdate().patchInputs(patchedGreetingsDiffs).build();
    Map<Long, UpdateStatus> results = getClient().sendRequest(batchUpdateRequest).getResponse().getEntity().getResults();
    Assert.assertEquals(results.size(), patchedGreetingsDiffs.size());
    for (UpdateStatus status : results.values()) {
        Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
    }
    getAndVerifyBatchTestDataSerially(builders, createdIds, patchedGreetings, null);
    deleteAndVerifyBatchTestDataSerially(builders, createdIds);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateStatus(com.linkedin.restli.common.UpdateStatus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Aggregations

BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)57 Test (org.testng.annotations.Test)40 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)31 EntityResponse (com.linkedin.restli.common.EntityResponse)18 UpdateStatus (com.linkedin.restli.common.UpdateStatus)15 HashSet (java.util.HashSet)13 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)11 Message (com.linkedin.restli.examples.greetings.api.Message)11 ArrayList (java.util.ArrayList)11 CompoundKey (com.linkedin.restli.common.CompoundKey)10 DataMap (com.linkedin.data.DataMap)8 HashMap (java.util.HashMap)8 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)7 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)6 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)5 BatchResponse (com.linkedin.restli.common.BatchResponse)5 CollectionResponse (com.linkedin.restli.common.CollectionResponse)5 PatchRequest (com.linkedin.restli.common.PatchRequest)4 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)4 RequestContext (com.linkedin.r2.message.RequestContext)3