Search in sources :

Example 6 with EmptyRecord

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

the class TestSimpleResourceHierarchy method testSubCollectionCreate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    final SubgreetingsBuilders builders = new SubgreetingsBuilders(requestOptions);
    //POST
    Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
    Response<EmptyRecord> response = getClient().sendRequest(createRequest).getResponse();
    Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
    long id = createResponse.getId();
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(id, Long.parseLong(stringId));
    //GET again to verify that the create has worked.
    Request<Greeting> getRequest = builders.get().id(id).build();
    Response<Greeting> getResponse = getClient().sendRequest(getRequest).getResponse();
    Greeting responseGreeting = getResponse.getEntity();
    Assert.assertEquals(responseGreeting.getMessage(), greeting.getMessage());
    Assert.assertEquals(responseGreeting.getTone(), greeting.getTone());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) CreateResponse(com.linkedin.restli.client.response.CreateResponse) SubgreetingsBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsBuilders) Test(org.testng.annotations.Test)

Example 7 with EmptyRecord

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

the class TestGroupsClient method testComplexKeyCreateGetUpdateDelete.

@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@test.linkedin.com", "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(), "alfred@test.linkedin.com");
    // 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(), "alfred@test.linkedin.com");
    // Update contact email and verify
    groupMembership.setContactEmail("alphred@test.linkedin.com");
    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(), "alphred@test.linkedin.com");
    // 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);
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) GroupMembershipQueryParamArray(com.linkedin.restli.examples.groups.api.GroupMembershipQueryParamArray) GroupMembershipQueryParam(com.linkedin.restli.examples.groups.api.GroupMembershipQueryParam) Test(org.testng.annotations.Test)

Example 8 with EmptyRecord

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

the class TestGroupsClient method testCollectionCreateGetUpdateDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateGetUpdateDelete(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, "a@a.a", "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);
    @SuppressWarnings("unchecked") IdResponse<Integer> createResponse = response.getEntity();
    Assert.assertNotNull(createResponse.getId());
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(createResponse.getId().intValue(), Integer.parseInt(stringId));
    // Get newly created group and verify name
    Integer createdId = createResponse.getId();
    Assert.assertEquals(getClient().sendRequest(groupBuilders.get().id(createResponse.getId()).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());
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) EmptyRecord(com.linkedin.restli.common.EmptyRecord) IdResponse(com.linkedin.restli.common.IdResponse) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 9 with EmptyRecord

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

the class TestNullGreetingsClient method testNullCreateResponse.

/*
   * Tests for nulls in CreateResponse
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testNullCreateResponse(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    //Forces the server to return a null CreateResponse
    final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
    final Greeting illGreeting = new Greeting().setMessage("nullCreateResponse").setTone(Tone.INSULTING);
    createAndAssertNullMessages(methodBuilderWrapper, illGreeting);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) Test(org.testng.annotations.Test)

Example 10 with EmptyRecord

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

the class TestNullGreetingsClient method testNullHttpStatusCreateResponse.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testNullHttpStatusCreateResponse(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    //Forces the server to return a valid CreateResponse but with a null HttpStatus inside of it
    final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
    final Greeting illGreeting = new Greeting().setMessage("nullHttpStatus").setTone(Tone.INSULTING);
    createAndAssertNullMessages(methodBuilderWrapper, illGreeting);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) Test(org.testng.annotations.Test)

Aggregations

EmptyRecord (com.linkedin.restli.common.EmptyRecord)75 Test (org.testng.annotations.Test)62 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)33 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)15 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)12 RestException (com.linkedin.r2.message.rest.RestException)11 BeforeTest (org.testng.annotations.BeforeTest)10 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)9 CompoundKey (com.linkedin.restli.common.CompoundKey)9 RequestExecutionReport (com.linkedin.restli.server.RequestExecutionReport)9 RequestExecutionReportBuilder (com.linkedin.restli.server.RequestExecutionReportBuilder)9 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)9 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)8 CreateResponse (com.linkedin.restli.client.response.CreateResponse)7 HashMap (java.util.HashMap)7 RecordTemplate (com.linkedin.data.template.RecordTemplate)6 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)6 Key (com.linkedin.restli.server.Key)6 RoutingException (com.linkedin.restli.server.RoutingException)6 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)6