Search in sources :

Example 26 with EmptyRecord

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

the class TestGroupsRequestBuilders method testSubResourceCreate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestContactsBuilderDataProviderNonEntity")
public void testSubResourceCreate(URIDetails expectedURIDetails) throws IOException, RestException {
    GroupContact contact = new GroupContact();
    contact.setContactID(3);
    contact.setGroupID(1);
    contact.setMemberID(3);
    contact.setFirstName("Laura");
    contact.setLastName("Smith");
    contact.setIsPreapproved(true);
    contact.setIsInvited(true);
    Request<EmptyRecord> oldRequest = new ContactsBuilders().create().groupIdKey(1).input(contact).build();
    checkRequestBuilder(oldRequest, ResourceMethod.CREATE, CreateResponseDecoder.class, expectedURIDetails, contact);
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) ContactsBuilders(com.linkedin.restli.examples.groups.client.ContactsBuilders) GroupContact(com.linkedin.restli.examples.groups.api.GroupContact) Test(org.testng.annotations.Test)

Example 27 with EmptyRecord

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

the class TestComplexKeysResource method testBatchDeleteMain.

private void testBatchDeleteMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, EmptyRecord> createRequestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
    String messageText = "m1";
    Message message = new Message();
    message.setMessage(messageText);
    Request<EmptyRecord> createRequest = createRequestBuilder.input(message).build();
    ResponseFuture<EmptyRecord> createFuture = getClient().sendRequest(createRequest);
    Response<EmptyRecord> createResponse = createFuture.getResponse();
    Assert.assertEquals(createResponse.getStatus(), 201);
    String messageText2 = "m2";
    message.setMessage(messageText2);
    createRequest = createRequestBuilder.input(message).build();
    createFuture = getClient().sendRequest(createRequest);
    createResponse = createFuture.getResponse();
    Assert.assertEquals(createResponse.getStatus(), 201);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(messageText, messageText);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(messageText2, messageText2);
    ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
    ids.add(key1);
    ids.add(key2);
    final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.ids(ids).build();
    final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
    final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
    for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
        Assert.assertEquals(resp.getValue().getStatus().intValue(), 204);
    }
    Assert.assertNotNull(response.getResults().get(key1));
    Assert.assertNotNull(response.getResults().get(key2));
    Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetRequest = batchGetRequestBuilder.ids(ids).build();
    ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetFuture = getClient().sendRequest(batchGetRequest);
    BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> batchGetResponse = batchGetFuture.getResponse().getEntity();
    Assert.assertEquals(batchGetResponse.getResults().size(), batchGetResponse.getErrors().size());
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) EmptyRecord(com.linkedin.restli.common.EmptyRecord) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Map(java.util.Map) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap)

Example 28 with EmptyRecord

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

the class TestGreetingClientContentTypes method testUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataDataProvider")
public void testUpdate(RestClient restClient, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
    // GET
    Request<Greeting> request = builders.get().id(1L).build();
    Response<Greeting> greetingResponse1 = restClient.sendRequest(request).getResponse();
    String response1 = greetingResponse1.getEntity().getMessage();
    Assert.assertNotNull(response1);
    // POST
    Greeting greeting = new Greeting(greetingResponse1.getEntity().data().copy());
    greeting.setMessage(response1 + "Again");
    Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
    Response<EmptyRecord> updateResponse = restClient.sendRequest(writeRequest).getResponse();
    Assert.assertNull(updateResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    // GET again, to verify that our POST worked.
    Request<Greeting> request2 = builders.get().id(1L).build();
    Response<Greeting> greetingResponse2 = restClient.sendRequest(request2).getResponse();
    String response2 = greetingResponse2.getEntity().getMessage();
    Assert.assertEquals(response2, response1 + "Again");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Test(org.testng.annotations.Test)

Example 29 with EmptyRecord

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

the class TestGreetingClientContentTypes method testPostsWithCharset.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testPostsWithCharset(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<Greeting> request = builders.<Greeting>action("SomeAction").id(1L).setActionParam("A", 1).setActionParam("B", "").setActionParam("C", new TransferOwnershipRequest()).setActionParam("D", new TransferOwnershipRequest()).setActionParam("E", 3).setHeader("Content-Type", "application/json; charset=UTF-8").build();
    Response<Greeting> response = getClient().sendRequest(request).getResponse();
    Greeting actionGreeting = response.getEntity();
    Assert.assertEquals(actionGreeting.getMessage(), "This is a newly created greeting");
    Greeting createGreeting = new Greeting();
    createGreeting.setMessage("Hello there!");
    createGreeting.setTone(Tone.FRIENDLY);
    Request<EmptyRecord> createRequest = builders.create().input(createGreeting).setHeader("Content-Type", "application/json; charset=UTF-8").build();
    Response<EmptyRecord> emptyRecordResponse = getClient().sendRequest(createRequest).getResponse();
    Assert.assertNull(emptyRecordResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) TransferOwnershipRequest(com.linkedin.restli.examples.groups.api.TransferOwnershipRequest) Test(org.testng.annotations.Test)

Example 30 with EmptyRecord

use of com.linkedin.restli.common.EmptyRecord 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)

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