Search in sources :

Example 11 with JSONObject

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

the class BookmarkTest method step4_updateUser.

@Test
public void step4_updateUser() {
    boolean thrown = false;
    try {
        JSONObject user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
        user.put("password", "NEW PASSWORD").put("email", "NEW@EMAIL.NET").put("username", "UPDATED TEST USER");
        target().path("resources/users/testuid").request().put(Entity.entity(user, "application/json"));
        user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
        assertEquals(user.get("username"), "UPDATED TEST USER");
        assertEquals(user.get("email"), "NEW@EMAIL.NET");
        assertEquals(user.get("password"), "NEW PASSWORD");
    } catch (Exception e) {
        e.printStackTrace();
        thrown = true;
    }
    assertFalse(thrown);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 12 with JSONObject

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

the class BookmarkTest method step4_updateUser.

@Test
public void step4_updateUser() {
    boolean thrown = false;
    try {
        JSONObject user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
        user.put("password", "NEW PASSWORD").put("email", "NEW@EMAIL.NET").put("username", "UPDATED TEST USER");
        target().path("resources/users/testuid").request().put(Entity.entity(user, "application/json"));
        user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
        assertEquals(user.get("username"), "UPDATED TEST USER");
        assertEquals(user.get("email"), "NEW@EMAIL.NET");
        assertEquals(user.get("password"), "NEW PASSWORD");
    } catch (Exception e) {
        e.printStackTrace();
        thrown = true;
    }
    assertFalse(thrown);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 13 with JSONObject

use of org.codehaus.jettison.json.JSONObject 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)

Example 14 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TopCLI method getJSONObject.

private JSONObject getJSONObject(URLConnection conn) throws IOException, JSONException {
    try (InputStream in = conn.getInputStream()) {
        String encoding = conn.getContentEncoding();
        encoding = encoding == null ? "UTF-8" : encoding;
        String body = IOUtils.toString(in, encoding);
        JSONObject obj = new JSONObject(body);
        JSONObject clusterInfo = obj.getJSONObject("clusterInfo");
        return clusterInfo;
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) InputStream(java.io.InputStream)

Example 15 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class LogsCLI method getAMContainerInfoForRMWebService.

protected List<JSONObject> getAMContainerInfoForRMWebService(Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException {
    Client webServiceClient = Client.create();
    String webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(conf);
    WebResource webResource = webServiceClient.resource(webAppAddress);
    ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps").path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts");
    JSONArray requests = json.getJSONArray("appAttempt");
    List<JSONObject> amContainersList = new ArrayList<JSONObject>();
    for (int i = 0; i < requests.length(); i++) {
        amContainersList.add(requests.getJSONObject(i));
    }
    return amContainersList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Client(com.sun.jersey.api.client.Client)

Aggregations

JSONObject (org.codehaus.jettison.json.JSONObject)1464 Test (org.junit.Test)457 JSONException (org.codehaus.jettison.json.JSONException)411 ClientResponse (com.sun.jersey.api.client.ClientResponse)402 JSONArray (org.codehaus.jettison.json.JSONArray)385 WebResource (com.sun.jersey.api.client.WebResource)308 Test (org.testng.annotations.Test)263 BaseTest (org.xdi.oxauth.BaseTest)200 Parameters (org.testng.annotations.Parameters)191 Response (javax.ws.rs.core.Response)185 Builder (javax.ws.rs.client.Invocation.Builder)173 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)173 HashMap (java.util.HashMap)133 IOException (java.io.IOException)94 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)88 ArrayList (java.util.ArrayList)86 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)81 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)73 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)69 Map (java.util.Map)62