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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations