Search in sources :

Example 1 with Album

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

the class TestMockHttpServerFactory method runTest.

/**
   * Starts the server, makes a request, runs assertions, stops the server
   *
   * @param server the test server
   * @throws IOException
   * @throws RemoteInvocationException
   */
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();
}
Also used : Album(com.linkedin.restli.example.Album) Photo(com.linkedin.restli.example.Photo)

Example 2 with Album

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

the class AlbumResource method update.

// update an existing photo with given entity
@Override
public UpdateResponse update(Long key, Album entity) {
    final Album currPhoto = _db.getData().get(key);
    if (currPhoto == null) {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
    // disallow changing entity ID and URN
    if (entity.hasId() || entity.hasUrn()) {
        throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "Album ID is not acceptable in request");
    }
    // make sure the ID in the entity is consistent with the key in the database
    entity.setId(key);
    entity.setUrn(String.valueOf(key));
    _db.getData().put(key, entity);
    return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) Album(com.linkedin.restli.example.Album)

Aggregations

Album (com.linkedin.restli.example.Album)2 Photo (com.linkedin.restli.example.Photo)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1 UpdateResponse (com.linkedin.restli.server.UpdateResponse)1