Package com.linkedin.restli.example

Examples of com.linkedin.restli.example.Photo


  private void runTest(HttpServer server)
      throws IOException, RemoteInvocationException
  {
    server.start();

    Photo photoEntity = REST_CLIENT.sendRequest(PHOTOS_BUILDERS.get().id(1L).build()).getResponseEntity();
    Assert.assertEquals(photoEntity.getTitle(), "Photo 1");

    Album albumEntity = REST_CLIENT.sendRequest(ALBUMS_BUILDERS.get().id(1L).build()).getResponseEntity();
    Assert.assertEquals(albumEntity.getTitle(), "Awesome Album #1");

    server.stop();
View Full Code Here


      final long id = _currId.incrementAndGet();
      final PhotoFormats[] formats = PhotoFormats.values();

      final LatLong ll = new LatLong().setLatitude(r.nextFloat() * 180 - 90).setLongitude(r.nextFloat() * 180 - 90);
      final EXIF e = new EXIF().setLocation(ll);
      final Photo p = new Photo().setId(id)
          .setUrn(String.valueOf(id))
          .setTitle("Photo " + id)
          .setFormat(formats[r.nextInt(formats.length)])
          .setExif(e);

      _data.put(p.getId(), p);
    }
  }
View Full Code Here

  // update an existing photo with given entity
  @Override
  public UpdateResponse update(Long key, Photo entity)
  {
    final Photo currPhoto = _db.getData().get(key);
    if (currPhoto == null)
    {
      return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
View Full Code Here

  // allow partial update to an existing photo
  @Override
  public UpdateResponse update(Long key, PatchRequest<Photo> patchRequest)
  {
    final Photo p = _db.getData().get(key);
    if (p == null)
    {
      return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }

    try
    {
      PatchApplier.applyPatch(p, patchRequest);
    }
    catch (DataProcessingException e)
    {
      return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
    }
    // photo's id and URN should not be changed
    p.setId(key);
    p.setUrn(String.valueOf(key));
    _db.getData().put(key, p);

    return new UpdateResponse(HttpStatus.S_202_ACCEPTED);
  }
View Full Code Here

  private Long createPhoto(String title, PhotoFormats format)
  {
      final LatLong l = new LatLong().setLatitude(7.0f).setLongitude(27.0f);
      final EXIF e = new EXIF().setIsFlash(true).setLocation(l);
      final Photo p = new Photo().setTitle(title).setFormat(format).setExif(e);
      final CreateResponse cResp = _res.create(p);
      Assert.assertTrue(cResp.hasId());
      return (Long) cResp.getId();
  }
View Full Code Here

    // because the test function will take arbitrary order
    // always create a photo and operate on that photo for a test function
    final Long id = createPhoto();

    // validate all data are correct
    final Photo p = _res.get(id);
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getId(), id);
    Assert.assertTrue(p.hasExif());
    final EXIF e = p.getExif();
    Assert.assertTrue(e.hasLocation());
    final LatLong l = e.getLocation();
    Assert.assertEquals(l.getLatitude(), 7.0f);
    Assert.assertEquals(l.getLongitude(), 27.0f);
  }
View Full Code Here

    Assert.assertEquals(batchPhotos.size(), 2);

    for (int i = 1; i < titles.length; i++) // go through {1,2}
    {
      final Photo p = batchPhotos.get(ids[i]);
      Assert.assertNotNull(p);
      Assert.assertEquals(p.getTitle(), titles[i]);
      Assert.assertEquals(p.getId().longValue(), ids[i]);
      Assert.assertTrue(p.hasExif());
      final EXIF e = p.getExif();
      Assert.assertTrue(e.hasLocation());
      final LatLong l = e.getLocation();
      Assert.assertEquals(l.getLatitude(), 7.0f);
      Assert.assertEquals(l.getLongitude(), 27.0f);
    }
View Full Code Here

  {
    final Long id = createPhoto();

    final LatLong l1 = new LatLong().setLongitude(-27.0f);
    final EXIF e1 = new EXIF().setLocation(l1);
    final Photo p1 = new Photo().setExif(e1);
    final UpdateResponse uResp = _res.update(id, p1);
    Assert.assertEquals(uResp.getStatus(), HttpStatus.S_204_NO_CONTENT);

    // validate data is changed to correct value
    final Photo p2 = _res.get(id);
    Assert.assertNotNull(p2.hasExif());
    final EXIF e2 = p2.getExif();
    Assert.assertNotNull(e2.hasLocation());
    final LatLong l2 = e2.getLocation();
    Assert.assertEquals(l2.getLongitude(), -27.0f);
  }
View Full Code Here

  @Test
  public void testResourcePartialUpdate()
  {
    final Long id = createPhoto("PartialTestPhoto");
    final String newTitle = "The New Title";
    final Photo p = new Photo().setTitle(newTitle);
    final PatchRequest<Photo> patch = PatchGenerator.diffEmpty(p);
    final UpdateResponse uResp = _res.update(id, patch);

    final Photo updatedPhoto = _res.get(id);
    Assert.assertEquals(updatedPhoto.getTitle(), newTitle);
    Assert.assertEquals(uResp.getStatus(), HttpStatus.S_202_ACCEPTED);
  }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.example.Photo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.