Beispiel #1
0
 private static ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> buildComplexKey(
     int memberID, int groupID, int intParam, String stringParam) {
   ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey =
       new ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>(
           new GroupMembershipKey(), new GroupMembershipParam());
   complexKey.getKey().setMemberID(memberID);
   complexKey.getKey().setGroupID(groupID);
   complexKey.getParams().setIntParameter(intParam);
   complexKey.getParams().setStringParameter(stringParam);
   return complexKey;
 }
Beispiel #2
0
  @Test(
      dataProvider =
          com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX
              + "requestComplexBuilderDataProvider")
  public void testComplexKeyBatchCreateGetUpdateDelete(
      ProtocolVersion version,
      RootBuilderWrapper<
              ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>,
              ComplexKeyGroupMembership>
          builders)
      throws RemoteInvocationException {
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey1 =
        buildComplexKey(1, 1, 10, "String1");
    ComplexKeyGroupMembership groupMembership1 =
        buildComplexKeyGroupMembership(
            complexKey1.getKey(), "*****@*****.**", "alfred", "hitchcock");
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey2 =
        buildComplexKey(2, 1, 20, "String2");
    ComplexKeyGroupMembership groupMembership2 =
        buildComplexKeyGroupMembership(
            complexKey2.getKey(), "*****@*****.**", "bruce", "willis");
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey3 =
        buildComplexKey(3, 1, 30, "String3");
    ComplexKeyGroupMembership groupMembership3 =
        buildComplexKeyGroupMembership(
            complexKey3.getKey(), "*****@*****.**", "carole", "bouquet");

    Request<CollectionResponse<CreateStatus>> createRequest =
        builders
            .batchCreate()
            .input(groupMembership1)
            .input(groupMembership2)
            .input(groupMembership3)
            .build();
    Response<CollectionResponse<CreateStatus>> createResponse =
        getClient().sendRequest(createRequest).getResponse();
    Assert.assertEquals(createResponse.getStatus(), 200);

    final RestliRequestOptions requestOptions = builders.getRequestOptions();
    @SuppressWarnings("unchecked")
    Request<
            BatchKVResponse<
                ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>,
                EntityResponse<ComplexKeyGroupMembership>>>
        request =
            new GroupMembershipsComplexRequestBuilders(requestOptions)
                .batchGet()
                .ids(complexKey1, complexKey2, complexKey3)
                .fields(GroupMembership.fields().contactEmail())
                .build();
    BatchKVResponse<
            ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>,
            EntityResponse<ComplexKeyGroupMembership>>
        groupMemberships = getClient().sendRequest(request).getResponse().getEntity();
    Map<
            ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>,
            EntityResponse<ComplexKeyGroupMembership>>
        results = groupMemberships.getResults();
    ComplexKeyGroupMembership groupMembership1_ = results.get(complexKey1).getEntity();
    ComplexKeyGroupMembership groupMembership2_ = results.get(complexKey2).getEntity();
    ComplexKeyGroupMembership groupMembership3_ = results.get(complexKey3).getEntity();
    Assert.assertNotNull(groupMembership1_);
    Assert.assertEquals(groupMembership1_.getContactEmail(), "*****@*****.**");
    Assert.assertNotNull(groupMembership2_);
    Assert.assertEquals(groupMembership2_.getContactEmail(), "*****@*****.**");
    Assert.assertNotNull(groupMembership3_);
    Assert.assertEquals(groupMembership3_.getContactEmail(), "*****@*****.**");

    // Update and verify
    groupMembership1.setContactEmail("*****@*****.**");
    groupMembership2.setContactEmail("*****@*****.**");
    groupMembership3.setContactEmail("*****@*****.**");
    Request<
            BatchKVResponse<
                ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, UpdateStatus>>
        updateRequest =
            builders
                .batchUpdate()
                .input(complexKey1, groupMembership1)
                .input(complexKey2, groupMembership2)
                .input(complexKey3, groupMembership3)
                .build();
    int status = getClient().sendRequest(updateRequest).getResponse().getStatus();
    Assert.assertEquals(status, 200);
  }
Beispiel #3
0
  @Test(
      dataProvider =
          com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX
              + "requestComplexBuilderDataProvider")
  public void testComplexKeyCreateGetUpdateDelete(
      ProtocolVersion version,
      RootBuilderWrapper<
              ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>,
              ComplexKeyGroupMembership>
          builders)
      throws RemoteInvocationException {
    // Create a new complex key resource
    ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey =
        buildComplexKey(1, 1, 10, "String1");
    ComplexKeyGroupMembership groupMembership =
        buildComplexKeyGroupMembership(
            complexKey.getKey(), "*****@*****.**", "alfred", "hitchcock");

    Request<EmptyRecord> createRequest = builders.create().input(groupMembership).build();
    Response<EmptyRecord> createResponse = getClient().sendRequest(createRequest).getResponse();
    Assert.assertEquals(createResponse.getStatus(), 201);

    GroupMembershipParam param = new GroupMembershipParam();
    param.setIntParameter(1);
    param.setStringParameter("1");

    GroupMembershipQueryParam groupMembershipQueryParam1 = new GroupMembershipQueryParam();
    groupMembershipQueryParam1.setIntParameter(1);
    groupMembershipQueryParam1.setStringParameter("1");
    GroupMembershipQueryParam groupMembershipQueryParam2 = new GroupMembershipQueryParam();
    groupMembershipQueryParam2.setIntParameter(2);
    groupMembershipQueryParam2.setStringParameter("2");
    GroupMembershipQueryParamArray queryParamArray =
        new GroupMembershipQueryParamArray(
            Arrays.asList(groupMembershipQueryParam1, groupMembershipQueryParam2));
    // Get the resource back and check state
    Request<ComplexKeyGroupMembership> request =
        builders
            .get()
            .id(complexKey)
            .fields(GroupMembership.fields().contactEmail())
            .setQueryParam("testParam", param)
            .setQueryParam("testParamArray", queryParamArray)
            .build();
    ComplexKeyGroupMembership groupMembership1 =
        getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertNotNull(groupMembership1);
    Assert.assertEquals(groupMembership1.getContactEmail(), "*****@*****.**");

    // Test the same with optional complex parameters
    request = builders.get().id(complexKey).fields(GroupMembership.fields().contactEmail()).build();
    groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertNotNull(groupMembership1);
    Assert.assertEquals(groupMembership1.getContactEmail(), "*****@*****.**");

    // Update contact email and verify
    groupMembership.setContactEmail("*****@*****.**");
    Request<EmptyRecord> updateRequest =
        builders.update().id(complexKey).input(groupMembership).build();
    Response<EmptyRecord> updateResponse = getClient().sendRequest(updateRequest).getResponse();
    Assert.assertEquals(updateResponse.getStatus(), 204);

    groupMembership1 = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(groupMembership1.getContactEmail(), "*****@*****.**");

    // Delete and verify
    Request<EmptyRecord> deleteRequest = builders.delete().id(complexKey).build();
    Response<EmptyRecord> deleteResponse = getClient().sendRequest(deleteRequest).getResponse();
    Assert.assertEquals(deleteResponse.getStatus(), 204);
    try {
      getClient().sendRequest(request).getResponse().getEntity();
    } catch (RestLiResponseException e) {
      Assert.assertEquals(e.getStatus(), 404);
    }
  }