@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"); }
@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()); }
@Test( dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider") public void testPostsWithCharset(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException { RestClient restClient = new RestClient(CLIENT, URI_PREFIX); 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 = restClient.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 = restClient.sendRequest(createRequest).getResponse(); Assert.assertNull(emptyRecordResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE)); }