Search in sources :

Example 31 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project jersey by jersey.

the class BookmarksResource method getBookmarksAsJsonArray.

@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONArray getBookmarksAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (BookmarkEntity bookmarkEntity : getBookmarks()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI bookmarkUri = ub.path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
        uriArray.put(bookmarkUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) BookmarkEntity(org.glassfish.jersey.examples.bookmark.entity.BookmarkEntity) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project jersey by jersey.

the class UsersResource method getUsersAsJsonArray.

@GET
@Produces("application/json")
public JSONArray getUsersAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (UserEntity userEntity : getUsers()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI userUri = ub.path(userEntity.getUserid()).build();
        uriArray.put(userUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UserEntity(org.glassfish.jersey.examples.bookmark.entity.UserEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project jersey by jersey.

the class BookmarkTest method step1_getUsers.

@Test
public void step1_getUsers() {
    final JSONArray users = target().path("resources/users/").request("application/json").get(JSONArray.class);
    assertTrue(users != null);
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 34 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project jersey by jersey.

the class BookmarkTest method step3_getUsers2.

@Test
public void step3_getUsers2() {
    final JSONArray users = target().path("resources/users/").request("application/json").get(JSONArray.class);
    assertTrue(users != null);
    assertTrue(users.length() == 1);
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 35 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project jersey by jersey.

the class BookmarkTest method step5_getUserBookmarkList.

// ugly.. but separation into separate test cases would be probably uglier
@Test
public void step5_getUserBookmarkList() {
    boolean thrown = false;
    try {
        JSONObject user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
        assertTrue(user != null);
        final WebTarget webTarget = client().target(user.getString("bookmarks"));
        JSONObject bookmark = new JSONObject();
        bookmark.put("uri", "http://java.sun.com").put("sdesc", "test desc").put("ldesc", "long test description");
        webTarget.request().post(Entity.entity(bookmark, "application/json"));
        JSONArray bookmarks = webTarget.request("application/json").get(JSONArray.class);
        assertTrue(bookmarks != null);
        int bookmarksSize = bookmarks.length();
        String testBookmarkUrl = bookmarks.getString(0);
        final WebTarget bookmarkResource = client().target(testBookmarkUrl);
        bookmark = bookmarkResource.request("application/json").get(JSONObject.class);
        assertTrue(bookmark != null);
        bookmarkResource.request().delete();
        bookmarks = target().path("resources/users/testuid/bookmarks").request("application/json").get(JSONArray.class);
        assertTrue(bookmarks != null);
        assertTrue(bookmarks.length() == (bookmarksSize - 1));
    } catch (Exception e) {
        e.printStackTrace();
        thrown = true;
    }
    assertFalse(thrown);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebTarget(javax.ws.rs.client.WebTarget) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

JSONArray (org.codehaus.jettison.json.JSONArray)338 JSONObject (org.codehaus.jettison.json.JSONObject)280 Test (org.junit.Test)123 WebResource (com.sun.jersey.api.client.WebResource)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)64 JSONException (org.codehaus.jettison.json.JSONException)64 ArrayList (java.util.ArrayList)38 Test (org.testng.annotations.Test)30 Map (java.util.Map)23 HashMap (java.util.HashMap)22 Vertex (com.tinkerpop.blueprints.Vertex)20 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)20 Produces (javax.ws.rs.Produces)17 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)14 GET (javax.ws.rs.GET)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 IOException (java.io.IOException)12 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)12 HashSet (java.util.HashSet)10 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)9