Search in sources :

Example 6 with CreateResponse

use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testCollectionCreate.

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

Example 7 with CreateResponse

use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.

the class TestGreetingsClientAcceptTypes method testCreate.

@SuppressWarnings("deprecation")
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "oldBuildersClientDataDataProvider")
public void testCreate(RestClient restClient, String expectedContentType, GreetingsBuilders builders) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
    Response<EmptyRecord> response = restClient.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));
    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) EmptyRecord(com.linkedin.restli.common.EmptyRecord) CreateResponse(com.linkedin.restli.client.response.CreateResponse) Test(org.testng.annotations.Test)

Example 8 with CreateResponse

use of com.linkedin.restli.client.response.CreateResponse 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<>();
    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 9 with CreateResponse

use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testCreate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "buildersClientDataDataProvider")
public void testCreate(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
    Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
    Response<EmptyRecord> response = restClient.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));
    Request<Greeting> getRequest = builders.get().id(id).build();
    Response<Greeting> getResponse = restClient.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) GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) Test(org.testng.annotations.Test)

Aggregations

CreateResponse (com.linkedin.restli.client.response.CreateResponse)9 EmptyRecord (com.linkedin.restli.common.EmptyRecord)7 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)6 IdResponse (com.linkedin.restli.common.IdResponse)4 Test (org.testng.annotations.Test)4 CreateIdRequestBuilder (com.linkedin.restli.client.CreateIdRequestBuilder)2 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)2 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)2 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)1 Message (com.linkedin.restli.examples.greetings.api.Message)1 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)1 CustomTypes2Builders (com.linkedin.restli.examples.greetings.client.CustomTypes2Builders)1 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)1 SubgreetingsBuilders (com.linkedin.restli.examples.greetings.client.SubgreetingsBuilders)1 ResponseImpl (com.linkedin.restli.internal.client.ResponseImpl)1 HttpCookie (java.net.HttpCookie)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1