@Test
public void testPutDomain() throws Exception {

  TimelineDomain domain = new TimelineDomain();
  domain.setId("test_domain_id");
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
      response.getType().toString());
  assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
  response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertResponseStatusCode(Status.OK, response.getStatusInfo());
  // Verify the domain exists
  response = r.path("ws").path("v1").path("timeline")
      .path("domain").path("test_domain_id")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
      response.getType().toString());
  domain = response.getEntity(TimelineDomain.class);
  Assert.assertNotNull(domain);
  Assert.assertEquals("test_domain_id", domain.getId());
  Assert.assertEquals("tester", domain.getOwner());
  Assert.assertEquals(null, domain.getDescription());
  // Update the domain
  domain.setDescription("test_description");
  response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertResponseStatusCode(Status.OK, response.getStatusInfo());
  // Verify the domain is updated
  response = r.path("ws").path("v1").path("timeline")
      .path("domain").path("test_domain_id")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
      response.getType().toString());
  domain = response.getEntity(TimelineDomain.class);
  Assert.assertNotNull(domain);
  Assert.assertEquals("test_domain_id", domain.getId());
  Assert.assertEquals("test_description", domain.getDescription());
}