Exemplo n.º 1
0
  @Test(
      dataProvider =
          com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX
              + "requestGroupsBuilderDataProvider")
  public void testDefaultValue(RootBuilderWrapper<Integer, Group> groupBuilders)
      throws RemoteInvocationException {
    // use server side default value for the RecordTemplate
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").build()).getResponse();

    try {
      // specifying an instance of the RecordTemplate which mismatches the default will fail the
      // request
      final GroupMembershipParam newValue = new GroupMembershipParam();
      newValue.setIntParameter(0);
      newValue.setStringParameter("fail");
      getClient()
          .sendRequest(
              groupBuilders.findBy("ComplexCircuit").setQueryParam("record", newValue).build())
          .getResponse();
      Assert.fail(
          "Expect exception when specifying the \"record\" query parameter different from the default");
    } catch (RestLiResponseException e) {
      Assert.assertEquals(e.getStatus(), 500);
    }
  }
Exemplo n.º 2
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);
    }
  }
Exemplo n.º 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);
    }
  }
Exemplo n.º 4
0
  @Test(
      dataProvider =
          com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX
              + "requestOptionsDataProvider")
  public void testCollectionCreateGetUpdateDeleteId(RestliRequestOptions requestOptions)
      throws RemoteInvocationException {
    // find with optional params
    Group group = new Group();
    String name = "test";
    int memberID = 1;
    group.setName(name);
    group.setOwner(buildGroupMembership(memberID, "[email protected]", "f", "l"));
    GroupMembershipParam param = new GroupMembershipParam();
    param.setIntParameter(1);
    param.setStringParameter("String");

    final GroupsRequestBuilders groupBuilders = new GroupsRequestBuilders(requestOptions);
    final GroupMembershipsRequestBuilders membershipBuilders =
        new GroupMembershipsRequestBuilders(requestOptions);

    // Create
    Response<IdResponse<Integer>> response =
        getClient().sendRequest(groupBuilders.create().input(group).build()).getResponse();
    Assert.assertEquals(response.getStatus(), 201);
    Integer createdId = response.getEntity().getId();
    Assert.assertNotNull(createdId);
    @SuppressWarnings("deprecation")
    String stringId = response.getId();
    Assert.assertEquals(createdId.intValue(), Integer.parseInt(stringId));

    // Get newly created group and verify name

    Assert.assertEquals(
        getClient()
            .sendRequest(groupBuilders.get().id(createdId).build())
            .getResponse()
            .getEntity()
            .getName(),
        name);

    // Partial update - change name
    String newName = "new name";
    group.setName(newName);
    PatchRequest<Group> patch = PatchGenerator.diffEmpty(group);
    ResponseFuture<EmptyRecord> responseFuture =
        getClient().sendRequest(groupBuilders.partialUpdate().id(createdId).input(patch).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());

    // Get updated group and verify name
    Assert.assertEquals(
        getClient()
            .sendRequest(groupBuilders.get().id(createdId).build())
            .getResponse()
            .getEntity()
            .getName(),
        newName);

    // Delete
    responseFuture = getClient().sendRequest(groupBuilders.delete().id(createdId).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());

    // Verify deleted
    try {
      getClient().sendRequest(groupBuilders.get().id(createdId).build()).getResponse();
      Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
      Assert.assertEquals(e.getStatus(), 404);
    }

    // Cleanup - delete the owner's membership that was created along with the group
    responseFuture =
        getClient()
            .sendRequest(
                membershipBuilders.delete().id(buildCompoundKey(memberID, createdId)).build());
    Assert.assertEquals(204, responseFuture.getResponse().getStatus());
  }