Exemplo n.º 1
0
  public void testResponseError() {
    startServer(HttpMethodResponseErrorResource.class);
    WebResource r = createClient().resource(getUri().path("test").build());

    testResponseError(r.get(ClientResponse.class));
    testResponseError(r.post(ClientResponse.class));
    testResponseError(r.put(ClientResponse.class));
    testResponseError(r.delete(ClientResponse.class));
  }
Exemplo n.º 2
0
  public void testAll() {
    startServer(HttpMethodResource.class);
    WebResource r = createClient().resource(getUri().path("test").build());
    assertEquals("GET", r.get(String.class));

    assertEquals("POST", r.post(String.class, "POST"));

    assertEquals("PUT", r.put(String.class, "PUT"));

    assertEquals("DELETE", r.delete(String.class));
  }
Exemplo n.º 3
0
  // ugly.. but separation into separate test cases would be probably uglier
  @Test
  public void getUserBookmarkList() {
    boolean thrown = false;

    try {
      WebResource webResource = resource();
      JSONObject user =
          webResource
              .path("resources/users/testuid")
              .accept("application/json")
              .get(JSONObject.class);
      assertTrue(user != null);

      webResource = client().resource(user.getString("bookmarks"));

      JSONObject bookmark = new JSONObject();
      bookmark
          .put("uri", "http://java.sun.com")
          .put("sdesc", "test desc")
          .put("ldesc", "long test description");
      webResource.type("application/json").post(bookmark);

      JSONArray bookmarks = webResource.accept("application/json").get(JSONArray.class);
      assertTrue(bookmarks != null);
      int bookmarksSize = bookmarks.length();

      String testBookmarkUrl = bookmarks.getString(0);
      WebResource bookmarkResource = client().resource(testBookmarkUrl);

      bookmark = bookmarkResource.accept("application/json").get(JSONObject.class);
      assertTrue(bookmark != null);

      bookmarkResource.delete();

      bookmarks =
          resource()
              .path("resources/users/testuid/bookmarks")
              .accept("application/json")
              .get(JSONArray.class);
      assertTrue(bookmarks != null);
      assertTrue(bookmarks.length() == (bookmarksSize - 1));

    } catch (Exception e) {
      e.printStackTrace();
      thrown = true;
    }

    assertFalse(thrown);
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testDeleteResource() {
    WebResource wr = resource().path(getResourcePath());
    T r = createTestResource();

    T res =
        (T)
            wr.type(MediaType.APPLICATION_XML)
                .accept(MediaType.APPLICATION_XML)
                .post(r.getClass(), r);
    Assert.assertNotNull("Resource not created", res);

    wr = resource().path(getResourcePath() + "/" + getResourceId(res));
    ClientResponse response = wr.delete(ClientResponse.class);
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
    response = wr.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
  }
 @Test
 public void testAddAndDelete() {
   Client client = Client.create();
   client.addFilter(new HTTPBasicAuthFilter("*****@*****.**", "123456"));
   WebResource webResource = client.resource(URL + "/add");
   MultivaluedMap<String, String> requestEntity = new MultivaluedMapImpl();
   requestEntity.add("gasAcctId", "22");
   requestEntity.add("reading", "50");
   requestEntity.add("readDate", new Date().toString());
   ClientResponse response =
       webResource
           .accept(MediaType.TEXT_PLAIN)
           .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
           .post(ClientResponse.class, requestEntity);
   assertEquals(201, response.getStatus());
   int readingId = Integer.valueOf(response.getEntity(String.class));
   System.out.println(readingId);
   // delete test resource
   WebResource webResource1 = client.resource(URL + "/delete/" + readingId);
   ClientResponse response1 = webResource1.delete(ClientResponse.class);
   assertEquals(200, response1.getStatus());
 }
 public void terminateService(String serviceId) {
   WebResource r = client.resource(base_url + "/vms/" + serviceId);
   r.delete();
 }
Exemplo n.º 7
0
 public void testDelete() {
   startServer(HttpMethodResource.class);
   WebResource r = createClient().resource(getUri().path("test").build());
   assertEquals("DELETE", r.delete(String.class));
 }