Exemple #1
0
  @Test(
      dataProvider =
          com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX
              + "requestMembershipsBuilderDataProvider")
  public void testAssociationCreateGetDelete(
      ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders)
      throws RemoteInvocationException {
    // Setup - create group memberships
    CompoundKey key1 = buildCompoundKey(1, 1);
    GroupMembership groupMembership1 =
        buildGroupMembership(null, "*****@*****.**", "Alfred", "Hitchcock");

    Response<EmptyRecord> response =
        getClient()
            .sendRequest(membershipBuilders.update().id(key1).input(groupMembership1).build())
            .getResponse();
    Assert.assertEquals(response.getStatus(), 204);

    // Get membership
    Request<GroupMembership> getRequest =
        membershipBuilders.get().id(key1).fields(GroupMembership.fields().contactEmail()).build();
    GroupMembership groupMembership = getClient().sendRequest(getRequest).getResponse().getEntity();
    Assert.assertEquals(groupMembership.getContactEmail(), "*****@*****.**");

    // Delete the newly created group membership
    Response<EmptyRecord> deleteResponse =
        getClient().sendRequest(membershipBuilders.delete().id(key1).build()).getResponse();
    Assert.assertEquals(deleteResponse.getStatus(), 204);

    // Make sure it is gone
    try {
      getClient().sendRequest(getRequest).getResponse();
    } catch (RestLiResponseException e) {
      Assert.assertEquals(e.getStatus(), 404);
    }
  }
Exemple #2
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);
    }
  }