Search in sources :

Example 1 with AlbumEntry

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

the class TestAlbumEntryResource method testBadUpdatePhotoId.

@Test(expectedExceptions = RestLiServiceException.class)
public void testBadUpdatePhotoId() {
    // photo 100 doesn't exist
    CompoundKey key = new CompoundKey().append("photoId", 100L).append("albumId", 1L);
    AlbumEntry entry = new AlbumEntry().setAddTime(4);
    _entryRes.update(key, entry);
}
Also used : AlbumEntry(com.linkedin.restli.example.AlbumEntry) CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Example 2 with AlbumEntry

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

the class TestAlbumEntryResource method testBadUpdateAlbumId.

@Test(expectedExceptions = RestLiServiceException.class)
public void testBadUpdateAlbumId() {
    // album 100 doesn't exist
    CompoundKey key = new CompoundKey().append("photoId", 1L).append("albumId", 100L);
    AlbumEntry entry = new AlbumEntry().setAddTime(4);
    _entryRes.update(key, entry);
}
Also used : AlbumEntry(com.linkedin.restli.example.AlbumEntry) CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Example 3 with AlbumEntry

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

the class TestAlbumEntryResource method makeData.

private void makeData() {
    _entries = new AlbumEntry[] { new AlbumEntry().setAddTime(1), new AlbumEntry().setAddTime(2), new AlbumEntry().setAddTime(3), new AlbumEntry().setAddTime(4), new AlbumEntry().setAddTime(5) };
    _keys = new CompoundKey[] { new CompoundKey().append("photoId", 1L).append("albumId", 1L), new CompoundKey().append("photoId", 2L).append("albumId", 1L), new CompoundKey().append("photoId", 3L).append("albumId", 1L), new CompoundKey().append("photoId", 1L).append("albumId", 2L), new CompoundKey().append("photoId", 4L).append("albumId", 2L) };
    for (int i = 0; i < _entries.length; i++) {
        final UpdateResponse uResp = _entryRes.update(_keys[i], _entries[i]);
        Assert.assertEquals(uResp.getStatus(), HttpStatus.S_204_NO_CONTENT);
    }
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) AlbumEntry(com.linkedin.restli.example.AlbumEntry) CompoundKey(com.linkedin.restli.common.CompoundKey)

Example 4 with AlbumEntry

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

the class AlbumEntryResource method search.

/**
   * Find all entries matching the given album and photo IDs. <code>null</code> is treated
   * as a wildcard.
   * 
   * @param albumId provides the id to match for albums to match,  if not provided, it is treated as a wildcard
   * @param photoId provides the id to match for photos to match,  if not provided, it is treated as a wildcard
   * @return a list of {@link AlbumEntry} matching the  given parameters
   */
@Finder("search")
public List<AlbumEntry> search(@Optional @QueryParam("albumId") Long albumId, @Optional @QueryParam("photoId") Long photoId) {
    List<AlbumEntry> result = new ArrayList<AlbumEntry>();
    for (Map.Entry<CompoundKey, AlbumEntry> entry : _db.getData().entrySet()) {
        CompoundKey key = entry.getKey();
        // (treat all values as a match)
        if (albumId != null && !key.getPart("albumId").equals(albumId))
            continue;
        if (photoId != null && !key.getPart("photoId").equals(photoId))
            continue;
        result.add(entry.getValue());
    }
    return result;
}
Also used : AlbumEntry(com.linkedin.restli.example.AlbumEntry) CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Finder(com.linkedin.restli.server.annotations.Finder)

Example 5 with AlbumEntry

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

the class TestAlbumEntryResource method testBadUpdateIdsInEntry.

@Test(expectedExceptions = RestLiServiceException.class)
public void testBadUpdateIdsInEntry() {
    // shouldn't be able to put IDs in update entry
    CompoundKey key = new CompoundKey().append("photoId", 1L).append("albumId", 1L);
    AlbumEntry entry = new AlbumEntry().setAddTime(4).setPhotoId(1);
    _entryRes.update(key, entry);
}
Also used : AlbumEntry(com.linkedin.restli.example.AlbumEntry) CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Aggregations

CompoundKey (com.linkedin.restli.common.CompoundKey)5 AlbumEntry (com.linkedin.restli.example.AlbumEntry)5 Test (org.testng.annotations.Test)3 UpdateResponse (com.linkedin.restli.server.UpdateResponse)1 Finder (com.linkedin.restli.server.annotations.Finder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1