Search in sources :

Example 11 with IdResponse

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

the class TestSimpleResourceHierarchy method testSubCollectionCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    final SubgreetingsRequestBuilders builders = new SubgreetingsRequestBuilders(requestOptions);
    //POST
    CreateIdRequest<Long, Greeting> createRequest = builders.create().input(greeting).build();
    Response<IdResponse<Long>> response = getClient().sendRequest(createRequest).getResponse();
    Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    long id = response.getEntity().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) IdResponse(com.linkedin.restli.common.IdResponse) SubgreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsRequestBuilders) Test(org.testng.annotations.Test)

Example 12 with IdResponse

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

the class TestComplexKeysResource method testCreateMainNewBuilders.

@SuppressWarnings("deprecation")
private void testCreateMainNewBuilders(CreateIdRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> createRequestBuilder, GetRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> getRequestBuilder) throws RemoteInvocationException {
    final String messageText = "newMessage";
    Message message = new Message();
    message.setMessage(messageText);
    Request<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> request = createRequestBuilder.input(message).build();
    ResponseFuture<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> future = getClient().sendRequest(request);
    Response<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> response = future.getResponse();
    try {
        response.getId();
        Assert.fail("getId() for a complex key is not allowed!");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    Assert.assertEquals(response.getStatus(), 201);
    IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>> entity = response.getEntity();
    ComplexResourceKey<TwoPartKey, TwoPartKey> id = entity.getId();
    Assert.assertEquals(id, getComplexKey(messageText, messageText));
    // attempt to get the record you just created
    @SuppressWarnings("unchecked") Request<Message> getRequest = getRequestBuilder.id(id).build();
    ResponseFuture<Message> getFuture = getClient().sendRequest(getRequest);
    Response<Message> getResponse = getFuture.getResponse();
    Assert.assertEquals(getResponse.getEntity().getMessage(), messageText);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) Message(com.linkedin.restli.examples.greetings.api.Message) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Example 13 with IdResponse

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

the class TestGreetingsClient method createBatchTestDataSerially.

/**
   * Creates batch data.
   *
   * @param greetings the greetings that we want to create
   *
   * @return the ids of the created Greetings
   * @throws RemoteInvocationException
   */
private List<Long> createBatchTestDataSerially(RootBuilderWrapper<Long, Greeting> builders, List<Greeting> greetings) throws RemoteInvocationException {
    List<Long> createdIds = new ArrayList<Long>();
    for (Greeting greeting : greetings) {
        RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilder = builders.create();
        Long createdId;
        if (createBuilder.isRestLi2Builder()) {
            Object objBuilder = createBuilder.getBuilder();
            @SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
            CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(greeting).build();
            Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
            createdId = response.getEntity().getId();
        } else {
            Request<EmptyRecord> request = createBuilder.input(greeting).build();
            Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
            @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
            createdId = createResponse.getId();
        }
        createdIds.add(createdId);
    }
    return createdIds;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) CreateResponse(com.linkedin.restli.client.response.CreateResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ArrayList(java.util.ArrayList) CreateIdRequestBuilder(com.linkedin.restli.client.CreateIdRequestBuilder)

Example 14 with IdResponse

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

the class TestGreetingsClientAcceptTypes method testCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testCreateId(RestClient restClient, String expectedContentType, GreetingsRequestBuilders builders) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    CreateIdRequest<Long, Greeting> createRequest = builders.create().input(greeting).build();
    Response<IdResponse<Long>> response = restClient.sendRequest(createRequest).getResponse();
    Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    long id = response.getEntity().getId();
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(id, Long.parseLong(stringId));
    Request<Greeting> getRequest = builders.get().id(id).build();
    Response<Greeting> getResponse = restClient.sendRequest(getRequest).getResponse();
    Assert.assertEquals(getResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
    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) IdResponse(com.linkedin.restli.common.IdResponse) Test(org.testng.annotations.Test)

Example 15 with IdResponse

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

the class TestCustomTypesClient method testCollectionCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    CreateIdRequest<CustomLong, Greeting> request = new CustomTypes2RequestBuilders(requestOptions).create().input(new Greeting().setId(10)).build();
    Response<IdResponse<CustomLong>> response = getClient().sendRequest(request).getResponse();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
    Assert.assertEquals(response.getEntity().getId(), new CustomLong(10L));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) CustomTypes2RequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Test(org.testng.annotations.Test)

Aggregations

IdResponse (com.linkedin.restli.common.IdResponse)16 Test (org.testng.annotations.Test)10 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)9 CreateResponse (com.linkedin.restli.client.response.CreateResponse)4 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)4 EmptyRecord (com.linkedin.restli.common.EmptyRecord)4 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)3 CreateIdRequestBuilder (com.linkedin.restli.client.CreateIdRequestBuilder)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 Group (com.linkedin.restli.examples.groups.api.Group)2 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)2 GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)2 GroupsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupsRequestBuilders)2 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)2 CreateResponse (com.linkedin.restli.server.CreateResponse)2 ResourceContext (com.linkedin.restli.server.ResourceContext)2 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)2 DataMap (com.linkedin.data.DataMap)1 UriBuilder (com.linkedin.jersey.api.uri.UriBuilder)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1