Search in sources :

Example 36 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)

Example 37 with EmptyRecord

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

the class TestGreetingsClient method testCookbook.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public //test cookbook example from quickstart wiki
void testCookbook(RootBuilderWrapper<Long, Greeting> builders) throws Exception {
    // GET
    Request<Greeting> request = builders.get().id(1L).build();
    ResponseFuture<Greeting> future = getClient().sendRequest(request);
    Response<Greeting> greetingResponse = future.getResponse();
    Assert.assertNotNull(greetingResponse.getEntity().getMessage());
    // POST
    Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
    final String NEW_MESSAGE = "This is a new message!";
    greeting.setMessage(NEW_MESSAGE);
    Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
    getClient().sendRequest(writeRequest).getResponse();
    // GET again, to verify that our POST worked.
    Request<Greeting> request2 = builders.get().id(1L).build();
    ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
    greetingResponse = future2.get();
    Assert.assertEquals(greetingResponse.getEntity().getMessage(), NEW_MESSAGE);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Test(org.testng.annotations.Test)

Example 38 with EmptyRecord

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

the class TestGreetingsClient method testUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public //test update on retrieved entity
void testUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException, URISyntaxException {
    // GET
    Request<Greeting> request = builders.get().id(1L).build();
    ResponseFuture<Greeting> future = getClient().sendRequest(request);
    Response<Greeting> greetingResponse = future.getResponse();
    String response1 = greetingResponse.getEntity().getMessage();
    Assert.assertNotNull(response1);
    // POST
    Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
    greeting.setMessage(response1 + "Again");
    Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
    getClient().sendRequest(writeRequest).getResponse();
    // GET again, to verify that our POST worked.
    Request<Greeting> request2 = builders.get().id(1L).build();
    ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
    String response2 = future2.getResponse().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 39 with EmptyRecord

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

the class TestGreetingsClient method testCreateWithNullId.

@SuppressWarnings("deprecation")
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testCreateWithNullId(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<EmptyRecord> request = builders.create().input(new Greeting().setId(1L).setMessage("foo")).setQueryParam("isNullId", true).build();
    Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
    Assert.assertNull(response.getId());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Test(org.testng.annotations.Test)

Example 40 with EmptyRecord

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

the class TestSimpleResourceHierarchy method testSubsubsimpleResourcePartialUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubSubBuilderDataProvider")
public void testSubsubsimpleResourcePartialUpdate(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Message1");
    greeting.setTone(Tone.SINCERE);
    greeting.setId(1L);
    PatchRequest<Greeting> patch = PatchGenerator.diffEmpty(greeting);
    // PUT
    Request<EmptyRecord> writeRequest = builders.partialUpdate().setPathKey("subgreetingsId", 1L).input(patch).build();
    getClient().sendRequest(writeRequest).getResponse();
    // GET again, to verify that our POST worked.
    Request<Greeting> request = builders.get().setPathKey("subgreetingsId", 1L).build();
    Response<Greeting> response = getClient().sendRequest(request).getResponse();
    greeting = response.getEntity();
    Assert.assertEquals(greeting.getTone(), Tone.SINCERE);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) 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