Search in sources :

Example 26 with UpdateStatus

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

the class TestParseqBasedFluentClientApi method testComplexKey_batchDelete.

@Test
public void testComplexKey_batchDelete() throws Exception {
    String messageText = "m1";
    Message message = new Message();
    message.setMessage(messageText);
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    ComplexResourceKey<TwoPartKey, TwoPartKey> createResponse = complexKeyClient.create(message).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    String messageText2 = "m2";
    message.setMessage(messageText2);
    createResponse = complexKeyClient.create(message).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(messageText, messageText);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(messageText2, messageText2);
    ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<>();
    ids.add(key1);
    ids.add(key2);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> deleteResponse = complexKeyClient.batchDelete(new HashSet<>(ids)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(deleteResponse.size(), ids.size());
    Assert.assertEquals(deleteResponse.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(deleteResponse.get(key2).getStatus().intValue(), 204);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResponse = complexKeyClient.batchGet(new HashSet<>(ids)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(getResponse.get(key1).getError().getStatus().intValue(), 404);
    Assert.assertEquals(getResponse.get(key2).getError().getStatus().intValue(), 404);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) EntityResponse(com.linkedin.restli.common.EntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Example 27 with UpdateStatus

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

the class TestGroupsClient method testAssociationBatchCreateGetUpdatePatchDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProvider")
public void testAssociationBatchCreateGetUpdatePatchDelete(ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders) throws RemoteInvocationException {
    // Setup - batch create two group memberships
    CompoundKey key1 = buildCompoundKey(1, 1);
    CompoundKey key2 = buildCompoundKey(2, 1);
    GroupMembership groupMembership1 = buildGroupMembership(null, "alfred@test.linkedin.com", "Alfred", "Hitchcock");
    GroupMembership groupMembership2 = buildGroupMembership(null, "bruce@test.linkedin.com", "Bruce", "Willis");
    Map<CompoundKey, UpdateStatus> results = getClient().sendRequest(membershipBuilders.batchUpdate().input(key1, groupMembership1).input(key2, groupMembership2).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(results.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(results.get(key2).getStatus().intValue(), 204);
    // BatchGet memberships
    final RestliRequestOptions requestOptions = membershipBuilders.getRequestOptions();
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> request = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail()).build();
    Map<CompoundKey, EntityResponse<GroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertTrue(groupMemberships.containsKey(key1));
    Assert.assertEquals(groupMemberships.get(key1).getEntity().getContactEmail(), "alfred@test.linkedin.com");
    Assert.assertTrue(groupMemberships.containsKey(key2));
    Assert.assertEquals(groupMemberships.get(key2).getEntity().getContactEmail(), "bruce@test.linkedin.com");
    // Batch partial update
    GroupMembership patchedGroupMembership1 = buildGroupMembership(null, "ALFRED@test.linkedin.com", "ALFRED", "Hitchcock");
    GroupMembership patchedGroupMembership2 = buildGroupMembership(null, "BRUCE@test.linkedin.com", "BRUCE", "Willis");
    Map<CompoundKey, PatchRequest<GroupMembership>> patchInputs = new HashMap<>();
    patchInputs.put(key1, PatchGenerator.diff(groupMembership1, patchedGroupMembership1));
    patchInputs.put(key2, PatchGenerator.diff(groupMembership2, patchedGroupMembership2));
    Map<CompoundKey, UpdateStatus> patchResults = getClient().sendRequest(membershipBuilders.batchPartialUpdate().patchInputs(patchInputs).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(patchResults.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(patchResults.get(key2).getStatus().intValue(), 204);
    // Batch get to make sure our patch applied
    Request<BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>>> batchGetRequest = new GroupMembershipsRequestBuilders(requestOptions).batchGet().ids(key1, key2).fields(GroupMembership.fields().contactEmail(), GroupMembership.fields().firstName()).build();
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> entity = getClient().sendRequest(batchGetRequest).getResponse().getEntity();
    Assert.assertEquals(entity.getErrors().size(), 0);
    Assert.assertEquals(entity.getResults().size(), 2);
    Assert.assertEquals(entity.getResults().get(key1).getEntity().getContactEmail(), "ALFRED@test.linkedin.com");
    Assert.assertEquals(entity.getResults().get(key1).getEntity().getFirstName(), "ALFRED");
    Assert.assertEquals(entity.getResults().get(key2).getEntity().getContactEmail(), "BRUCE@test.linkedin.com");
    Assert.assertEquals(entity.getResults().get(key2).getEntity().getFirstName(), "BRUCE");
    // GetAll memberships
    Request<CollectionResponse<GroupMembership>> getAllRequest = membershipBuilders.getAll().paginate(1, 2).fields(GroupMembership.fields().contactEmail()).build();
    List<GroupMembership> elements = getClient().sendRequest(getAllRequest).getResponse().getEntity().getElements();
    Assert.assertEquals(elements.size(), 1);
    // Delete the newly created group memberships
    Map<CompoundKey, UpdateStatus> deleteResult = getClient().sendRequest(membershipBuilders.batchDelete().ids(key1, key2).build()).getResponse().getEntity().getResults();
    Assert.assertEquals(deleteResult.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(deleteResult.get(key2).getStatus().intValue(), 204);
    // Make sure they are gone
    BatchKVResponse<CompoundKey, EntityResponse<GroupMembership>> getResponse = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(getResponse.getResults().size(), getResponse.getErrors().size());
    Assert.assertTrue(getResponse.getErrors().containsKey(key1));
    Assert.assertTrue(getResponse.getErrors().containsKey(key2));
    Assert.assertEquals(getResponse.getErrors().get(key1).getStatus().intValue(), 404);
    Assert.assertEquals(getResponse.getErrors().get(key2).getStatus().intValue(), 404);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) RestliRequestOptions(com.linkedin.restli.client.RestliRequestOptions) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) CollectionResponse(com.linkedin.restli.common.CollectionResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) Test(org.testng.annotations.Test)

Example 28 with UpdateStatus

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

the class TestCustomTypesClient method testCollectionBatchPartialUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2BuilderDataProvider")
public void testCollectionBatchPartialUpdate(RootBuilderWrapper<CustomLong, Greeting> builders) throws RemoteInvocationException {
    RequestBuilder<? extends Request<BatchKVResponse<CustomLong, UpdateStatus>>> request = builders.batchPartialUpdate().input(new CustomLong(1L), new PatchRequest<>()).input(new CustomLong(2L), new PatchRequest<>()).getBuilder();
    Map<CustomLong, UpdateStatus> statuses = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertEquals(statuses.size(), 2);
    Assert.assertEquals(statuses.get(new CustomLong(1L)).getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
    Assert.assertEquals(statuses.get(new CustomLong(2L)).getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 29 with UpdateStatus

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

the class TestCustomTypesClient method testBatchUpdateForChainedRefs.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestChainedTyperefsBuilderDataProvider")
public void testBatchUpdateForChainedRefs(RootBuilderWrapper<CompoundKey, Greeting> builders) throws RemoteInvocationException {
    Long lo = 29L;
    Long date = 10L;
    ChainedTyperefsBuilders.Key key = new ChainedTyperefsBuilders.Key().setAge(new CustomNonNegativeLong(lo)).setBirthday(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(1, response.getResults().keySet().size());
    CompoundKey expected = new CompoundKey();
    expected.append("birthday", new Date(date));
    expected.append("age", new CustomNonNegativeLong(lo));
    CompoundKey result = response.getResults().keySet().iterator().next();
    Assert.assertEquals(result, expected);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) 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) ChainedTyperefsBuilders(com.linkedin.restli.examples.greetings.client.ChainedTyperefsBuilders) CompoundKey(com.linkedin.restli.common.CompoundKey) CustomNonNegativeLong(com.linkedin.restli.examples.custom.types.CustomNonNegativeLong) Date(java.util.Date) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 30 with UpdateStatus

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

the class TestCustomTypesClient method testCollectionBatchUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2BuilderDataProvider")
public void testCollectionBatchUpdate(RootBuilderWrapper<CustomLong, Greeting> builders) throws RemoteInvocationException {
    RequestBuilder<? extends Request<BatchKVResponse<CustomLong, UpdateStatus>>> request = builders.batchUpdate().input(new CustomLong(1L), new Greeting().setId(1)).input(new CustomLong(2L), new Greeting().setId(2)).getBuilder();
    Map<CustomLong, UpdateStatus> statuses = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertEquals(statuses.size(), 2);
    Assert.assertEquals(statuses.get(new CustomLong(1L)).getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
    Assert.assertEquals(statuses.get(new CustomLong(2L)).getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateStatus(com.linkedin.restli.common.UpdateStatus) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Aggregations

UpdateStatus (com.linkedin.restli.common.UpdateStatus)42 HashMap (java.util.HashMap)27 Test (org.testng.annotations.Test)22 Map (java.util.Map)18 DataMap (com.linkedin.data.DataMap)16 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)15 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)12 ArrayList (java.util.ArrayList)11 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)8 BatchResponse (com.linkedin.restli.common.BatchResponse)7 CompoundKey (com.linkedin.restli.common.CompoundKey)7 EntityResponse (com.linkedin.restli.common.EntityResponse)7 PatchRequest (com.linkedin.restli.common.PatchRequest)6 BatchResponseEntry (com.linkedin.restli.internal.server.response.BatchResponseEnvelope.BatchResponseEntry)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)5 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 Message (com.linkedin.restli.examples.greetings.api.Message)5 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)5 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)5