Search in sources :

Example 11 with UpdateEntityStatus

use of com.linkedin.restli.common.UpdateEntityStatus in project rest.li by linkedin.

the class TestReturnEntityWithBatchPartialUpdate method testBatchPartialUpdateEntities.

/**
 * Sends batch partial update requests to the server and ensures that the returned entities for each request are
 * consistent with the expected state of the server's entities.
 *
 * @param patches patches to send for this request
 * @param expectedGreetings expected response entities for this request
 */
@Test(dataProvider = "batchPartialUpdateData")
public void testBatchPartialUpdateEntities(Map<Long, PatchRequest<Greeting>> patches, Map<Long, Greeting> expectedGreetings) throws RemoteInvocationException {
    BatchPartialUpdateEntityRequest<Long, Greeting> request = new PartialUpdateGreetingRequestBuilders().batchPartialUpdateAndGet().inputs(patches).build();
    Response<BatchKVResponse<Long, UpdateEntityStatus<Greeting>>> response = getClient().sendRequest(request).getResponse();
    Assert.assertNotNull(response);
    BatchKVResponse<Long, UpdateEntityStatus<Greeting>> batchKVResponse = response.getEntity();
    Assert.assertNotNull(batchKVResponse);
    Assert.assertTrue(batchKVResponse.getErrors().isEmpty());
    Map<Long, UpdateEntityStatus<Greeting>> greetings = batchKVResponse.getResults();
    Assert.assertNotNull(greetings);
    for (Long key : greetings.keySet()) {
        Assert.assertTrue(expectedGreetings.containsKey(key));
        UpdateEntityStatus<Greeting> updateEntityStatus = greetings.get(key);
        Assert.assertNotNull(updateEntityStatus);
        Assert.assertEquals(updateEntityStatus.getStatus().intValue(), HttpStatus.S_200_OK.getCode());
        Assert.assertTrue(updateEntityStatus.hasEntity());
        Assert.assertFalse(updateEntityStatus.hasError());
        Greeting greeting = updateEntityStatus.getEntity();
        Greeting expectedGreeting = expectedGreetings.get(key);
        Assert.assertNotNull(greeting);
        Assert.assertNotNull(expectedGreeting);
        Assert.assertEquals(greeting.getId(), expectedGreeting.getId());
        Assert.assertEquals(greeting.getMessage(), expectedGreeting.getMessage());
        Assert.assertEquals(greeting.getTone(), expectedGreeting.getTone());
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) PartialUpdateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 12 with UpdateEntityStatus

use of com.linkedin.restli.common.UpdateEntityStatus in project rest.li by linkedin.

the class TestReturnEntityWithBatchPartialUpdate method testBatchPartialUpdateEntitiesWithProjection.

/**
 * Same as {@link this#testBatchPartialUpdateEntities}, except the fields of the returned entities are projected.
 *
 * @param patches patches to send for this request
 * @param expectedGreetings expected response entities for this request
 */
@Test(dataProvider = "batchPartialUpdateData")
public void testBatchPartialUpdateEntitiesWithProjection(Map<Long, PatchRequest<Greeting>> patches, Map<Long, Greeting> expectedGreetings) throws RemoteInvocationException {
    final Greeting.Fields fields = Greeting.fields();
    BatchPartialUpdateEntityRequest<Long, Greeting> request = new PartialUpdateGreetingRequestBuilders().batchPartialUpdateAndGet().inputs(patches).fields(fields.id(), fields.message()).build();
    Response<BatchKVResponse<Long, UpdateEntityStatus<Greeting>>> response = getClient().sendRequest(request).getResponse();
    Assert.assertNotNull(response);
    BatchKVResponse<Long, UpdateEntityStatus<Greeting>> batchKVResponse = response.getEntity();
    Assert.assertNotNull(batchKVResponse);
    Assert.assertTrue(batchKVResponse.getErrors().isEmpty());
    Map<Long, UpdateEntityStatus<Greeting>> greetings = batchKVResponse.getResults();
    Assert.assertNotNull(greetings);
    for (Long key : greetings.keySet()) {
        Assert.assertTrue(expectedGreetings.containsKey(key));
        UpdateEntityStatus<Greeting> updateEntityStatus = greetings.get(key);
        Assert.assertNotNull(updateEntityStatus);
        Assert.assertEquals(updateEntityStatus.getStatus().intValue(), HttpStatus.S_200_OK.getCode());
        Assert.assertTrue(updateEntityStatus.hasEntity());
        Assert.assertFalse(updateEntityStatus.hasError());
        Greeting greeting = updateEntityStatus.getEntity();
        Greeting expectedGreeting = expectedGreetings.get(key);
        Assert.assertNotNull(greeting);
        Assert.assertNotNull(expectedGreeting);
        Assert.assertTrue(greeting.hasId(), "Response record should include an id field.");
        Assert.assertTrue(greeting.hasMessage(), "Response record should include a message field.");
        Assert.assertFalse(greeting.hasTone(), "Response record should not include a tone field due to projection.");
        Assert.assertEquals(greeting.getId(), expectedGreeting.getId());
        Assert.assertEquals(greeting.getMessage(), expectedGreeting.getMessage());
        Assert.assertNull(greeting.getTone(GetMode.NULL), "Response record should have a null tone field due to projection.");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) PartialUpdateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 13 with UpdateEntityStatus

use of com.linkedin.restli.common.UpdateEntityStatus in project rest.li by linkedin.

the class BatchUpdateEntityResponse method deserializeValue.

@Override
protected UpdateEntityStatus<E> deserializeValue(Object valueData) {
    DataMap valueDataMap = (DataMap) valueData;
    E entity = valueDataMap.containsKey(UpdateEntityStatus.ENTITY) ? DataTemplateUtil.wrap(((DataMap) valueData).getDataMap(UpdateEntityStatus.ENTITY), _entityType.getType()) : null;
    return new UpdateEntityStatus<>((DataMap) valueData, entity);
}
Also used : UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) DataMap(com.linkedin.data.DataMap)

Aggregations

UpdateEntityStatus (com.linkedin.restli.common.UpdateEntityStatus)13 Test (org.testng.annotations.Test)7 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)6 PartialUpdateGreetingRequestBuilders (com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders)5 DataMap (com.linkedin.data.DataMap)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 HashMap (java.util.HashMap)4 ErrorResponse (com.linkedin.restli.common.ErrorResponse)3 PatchRequest (com.linkedin.restli.common.PatchRequest)3 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)2 TestRecord (com.linkedin.restli.server.TestRecord)2 Map (java.util.Map)2 PathSpec (com.linkedin.data.schema.PathSpec)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 RequestContext (com.linkedin.r2.message.RequestContext)1 TimingKey (com.linkedin.r2.message.timing.TimingKey)1