Search in sources :

Example 1 with Containers

use of com.sun.jersey.samples.storageservice.Containers in project enunciate by stoicflame.

the class TestJerseyStorageService method testContainers.

/**
 * tests the containers.
 */
public void testContainers() throws Exception {
    WebTarget resource = getStorageResource();
    Response response = resource.path("containers").request("application/xml").get();
    assertEquals(200, response.getStatus());
    Containers containers = response.readEntity(Containers.class);
    assertTrue(containers.getContainer() == null || containers.getContainer().isEmpty());
    response = resource.path("containers").request("text/html").get();
    assertEquals(200, response.getStatus());
    response = resource.path("containers/one").request().get();
    assertEquals(404, response.getStatus());
    Container containerOne = new Container();
    response = resource.path("containers/one").request().put(Entity.entity(containerOne, "application/xml"));
    assertEquals(201, response.getStatus());
    response = resource.path("containers").request("application/xml").get();
    assertEquals(200, response.getStatus());
    containers = response.readEntity(Containers.class);
    assertEquals(1, containers.getContainer().size());
    response = resource.path("containers/one").request().get();
    assertEquals(200, response.getStatus());
    containerOne = response.readEntity(Container.class);
    assertEquals("one", containerOne.getName());
    assertNotNull(containerOne.getUri());
    assertTrue(containerOne.getItem() == null || containerOne.getItem().isEmpty());
    String stringItem = "here is a string that we want to store";
    response = resource.path("containers/one/string").request().put(Entity.entity(stringItem, "text/plain"));
    assertEquals(201, response.getStatus());
    response = resource.path("containers/one").request().get();
    assertEquals(200, response.getStatus());
    containerOne = response.readEntity(Container.class);
    assertEquals(1, containerOne.getItem().size());
    assertEquals("text/plain", containerOne.getItem("string").getMimeType());
    response = resource.path("containers/one/string").request().get();
    assertEquals(200, response.getStatus());
    assertEquals(stringItem, response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) Container(com.sun.jersey.samples.storageservice.Container) Containers(com.sun.jersey.samples.storageservice.Containers) WebTarget(javax.ws.rs.client.WebTarget)

Example 2 with Containers

use of com.sun.jersey.samples.storageservice.Containers in project enunciate by stoicflame.

the class TestJerseyStorageService method tearDown.

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    WebTarget resource = getStorageResource();
    Response response = resource.path("containers").request("application/xml").get();
    if (200 == response.getStatus()) {
        Containers containers = response.readEntity(Containers.class);
        if (containers.getContainer() != null) {
            for (Container container : containers.getContainer()) {
                resource.path("containers/" + container.getName()).request().delete();
            }
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Container(com.sun.jersey.samples.storageservice.Container) Containers(com.sun.jersey.samples.storageservice.Containers) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

Container (com.sun.jersey.samples.storageservice.Container)2 Containers (com.sun.jersey.samples.storageservice.Containers)2 WebTarget (javax.ws.rs.client.WebTarget)2 Response (javax.ws.rs.core.Response)2