@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());
  }
Ejemplo n.º 2
0
  private long createPhoto(PrintWriter respWriter) throws RemoteInvocationException {
    // make create photo request and send with the rest client synchronously
    // response of create request does not have body, therefore use EmptyRecord as template

    // create an instance of photo pragmatically
    // this resembles to photo-create.json
    final LatLong newLatLong = new LatLong().setLatitude(37.42394f).setLongitude(-122.0708f);
    final EXIF newExif = new EXIF().setLocation(newLatLong);
    final Photo newPhoto =
        new Photo().setTitle("New Photo").setFormat(PhotoFormats.PNG).setExif(newExif);

    final Request<EmptyRecord> createReq1 = _photoBuilders.create().input(newPhoto).build();
    final ResponseFuture<EmptyRecord> createFuture1 = _restClient.sendRequest(createReq1);
    // Future.getResource() blocks until server responds
    final Response<EmptyRecord> createResp1 = createFuture1.getResponse();

    // HTTP header Location also shows the relative URI of the created resource
    final long newPhotoId = Long.parseLong(createResp1.getId());
    respWriter.println("New photo ID: " + newPhotoId);

    return newPhotoId;
  }