Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONObject


        // Response contains an array of objects identified by
        // their INFO_TYPE, extract the tests
        // based on this vlaue
        for(int i = 0 ; i < json.length(); i++) {
            final JSONObject obj = json.getJSONObject(i);
            if("test".equals(obj.getString("INFO_TYPE"))) {
                children.add(new SlingRemoteTest(testClass, obj));
            }
        }
       
        log.info("Server-side tests executed as {} at {} with path {}",
View Full Code Here


        assertJavascript(testMultiText2, json, "out.println(data.multiText[1])");
    }

    public void testTextJson() throws Exception {
        final String json = getContent(displayUrl + "/text.json", CONTENT_TYPE_JSON);
        final JSONObject obj = new JSONObject(json);
        assertEquals(testText, obj.get("text"));
    }
View Full Code Here

        assertEquals(testText, data);
    }

    public void testMultiValuedTextJson() throws Exception {
        final String json = getContent(displayUrl + "/multiText.json", CONTENT_TYPE_JSON);
        final JSONObject obj = new JSONObject(json);
        assertEquals("[\"" + testMultiText1 + "\",\""+ testMultiText2 + "\"]", obj.get("multiText").toString());
    }
View Full Code Here

    /**
     * Test fix for SLING-1733 - BundleResourceProvider fails to find resources when multiple bundles have the same Sling-Bundle-Resources path
     */
    public void testBundleContentParentFromMultipleBundles() throws IOException, JSONException {
        final String content = getContent(HTTP_BASE_URL + "/system.1.json", CONTENT_TYPE_JSON);
        JSONObject jsonObj = new JSONObject(content);

        //provided by the servlets.post bundle
        assertTrue("Expected sling.js in the /system folder", jsonObj.has("sling.js"));

        //provided by the launchpad.test-services bundle
        assertTrue("Expected sling-1733.txt in the /system folder", jsonObj.has("sling-1733.txt"));
    }
View Full Code Here

        assertEquals(200, status);
        assertTrue(get.getResponseHeader("Content-Type").getValue().startsWith(CONTENT_TYPE_JSON));

        // the json data
        String jsonString = get.getResponseBodyAsString();
        JSONObject json = new JSONObject(jsonString);

        assertEquals("sling:redirect", json.get("sling:resourceType"));
        assertEquals("/index.html", json.get("sling:target"));
    }
View Full Code Here

        assertEquals(200, status);
        assertTrue(get.getResponseHeader("Content-Type").getValue().startsWith(CONTENT_TYPE_JSON));

        // the json data
        String jsonString = get.getResponseBodyAsString();
        JSONObject json = new JSONObject(jsonString);

        assertEquals("sling:redirect", json.get("sling:resourceType"));
    }
View Full Code Here

    //fetch the JSON for the acl to verify the settings.
    String getUrl = testFolderUrl + ".acl.json";

    String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JSONObject jsonObject = new JSONObject(json);
    assertEquals(1, jsonObject.length());
   
    JSONObject aceObject = jsonObject.optJSONObject(testUserId);
    assertNotNull(aceObject);
   
    String principalString = aceObject.optString("principal");
    assertEquals(testUserId, principalString);

          int order = aceObject.optInt("order");
          assertEquals(0, order);

    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    assertEquals("jcr:read", grantedArray.getString(0));

    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals(1, deniedArray.length());
    assertEquals("jcr:write", deniedArray.getString(0));
  }
View Full Code Here

        executor.assertContentType("application/json");
        String content = executor.getContent();
        final JSONArray json = new JSONArray(new JSONTokener(content));

        for(int i = 0 ; i < json.length(); i++) {
            final JSONObject obj = json.getJSONObject(i);
            if("test".equals(obj.getString("INFO_TYPE"))) {
                r.testCount++;
                if(obj.has("failure")) {
                    r.failures.add(obj.get("failure").toString());
                }
            }
        }

        return r;
View Full Code Here

    //fetch the user profile json to verify the settings
    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
    H.assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
    String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JSONObject jsonObj = new JSONObject(json);
    assertEquals("My Updated Test User", jsonObj.getString("displayName"));
    assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
  }
View Full Code Here

    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
    Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
    String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

    //make sure the json response can be parsed as a JSON object
    JSONObject jsonObj = new JSONObject(json);
    assertNotNull(jsonObj);
 
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.