Search in sources :

Example 1 with Photo

use of com.linkedin.restli.example.Photo in project rest.li by linkedin.

the class TestPhotoResource method testBatchGet.

@Test
public void testBatchGet() {
    final String[] titles = { "1", "2", "3" };
    final long[] ids = new long[titles.length];
    for (int i = 0; i < titles.length; i++) ids[i] = createPhoto(titles[i]);
    // validate all data are correct
    Set<Long> batchIds = new HashSet<Long>();
    batchIds.add(ids[1]);
    batchIds.add(ids[2]);
    Map<Long, Photo> batchPhotos = _res.batchGet(batchIds);
    Assert.assertEquals(batchPhotos.size(), 2);
    for (// go through {1,2}
    int i = 1; // go through {1,2}
    i < titles.length; // go through {1,2}
    i++) {
        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);
    }
}
Also used : EXIF(com.linkedin.restli.example.EXIF) LatLong(com.linkedin.restli.example.LatLong) Photo(com.linkedin.restli.example.Photo) LatLong(com.linkedin.restli.example.LatLong) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Photo

use of com.linkedin.restli.example.Photo in project rest.li by linkedin.

the class TestPhotoResource method testResourceFind.

@Test
public void testResourceFind() {
    _res.purge();
    createPhoto("InEdible");
    createPhoto("InEdible");
    createPhoto("InEdible", PhotoFormats.BMP);
    final PagingContext pc = new PagingContext(0, 4);
    final PagingContext pc2 = new PagingContext(0, 2);
    final List<Photo> foundByTitle = _res.find(pc, "InEdible", null);
    Assert.assertEquals(foundByTitle.size(), 3);
    final List<Photo> foundByFormat = _res.find(pc, null, PhotoFormats.BMP);
    Assert.assertEquals(foundByFormat.size(), 1);
    final List<Photo> foundByTitleAndFormat = _res.find(pc, "InEdible", PhotoFormats.PNG);
    Assert.assertEquals(foundByTitleAndFormat.size(), 2);
    final List<Photo> foundTwo = _res.find(pc2, null, null);
    Assert.assertEquals(foundTwo.size(), 2);
    // testResourcePurge() assumes there is at least one photo
    createPhoto();
}
Also used : PagingContext(com.linkedin.restli.server.PagingContext) Photo(com.linkedin.restli.example.Photo) Test(org.testng.annotations.Test)

Example 3 with Photo

use of com.linkedin.restli.example.Photo in project rest.li by linkedin.

the class TestPhotoResource method createPhoto.

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();
}
Also used : EXIF(com.linkedin.restli.example.EXIF) CreateResponse(com.linkedin.restli.server.CreateResponse) LatLong(com.linkedin.restli.example.LatLong) Photo(com.linkedin.restli.example.Photo) LatLong(com.linkedin.restli.example.LatLong)

Example 4 with Photo

use of com.linkedin.restli.example.Photo in project rest.li by linkedin.

the class TestPhotoResource method testResourceUpdate.

@Test
public void testResourceUpdate() {
    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);
}
Also used : EXIF(com.linkedin.restli.example.EXIF) UpdateResponse(com.linkedin.restli.server.UpdateResponse) LatLong(com.linkedin.restli.example.LatLong) Photo(com.linkedin.restli.example.Photo) LatLong(com.linkedin.restli.example.LatLong) Test(org.testng.annotations.Test)

Example 5 with Photo

use of com.linkedin.restli.example.Photo in project rest.li by linkedin.

the class TestPhotoResource method testResourcePartialUpdate.

@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);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) LatLong(com.linkedin.restli.example.LatLong) Photo(com.linkedin.restli.example.Photo) Test(org.testng.annotations.Test)

Aggregations

Photo (com.linkedin.restli.example.Photo)11 LatLong (com.linkedin.restli.example.LatLong)5 Test (org.testng.annotations.Test)5 EXIF (com.linkedin.restli.example.EXIF)4 UpdateResponse (com.linkedin.restli.server.UpdateResponse)4 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 DataProcessingException (com.linkedin.data.transform.DataProcessingException)1 Album (com.linkedin.restli.example.Album)1 BatchResult (com.linkedin.restli.server.BatchResult)1 CreateResponse (com.linkedin.restli.server.CreateResponse)1 PagingContext (com.linkedin.restli.server.PagingContext)1 Finder (com.linkedin.restli.server.annotations.Finder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1