Package org.apache.sling.commons.json

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


            }
            final String content = IOUtils.toString(response.getEntity().getContent(), encoding);
           
            // Start level is in the props array, with key="Start Level"
            final JSONObject status = new JSONObject(content);
            final JSONArray props = status.getJSONArray("data").getJSONObject(0).getJSONArray("props");
            final String KEY = "key";
            final String SL = "Start Level";
            boolean found = false;
            for(int i=0; i < props.length(); i++) {
                final JSONObject o = props.getJSONObject(i);
                if(o.has(KEY) && SL.equals(o.getString(KEY))) {
                    found = true;
                    assertEquals("Expecting the start level that we set", "99", o.getString("value"));
                }
            }
View Full Code Here


        // Execute tests from the failingtests bundle and verify response
        final Request r = getRequestBuilder().buildPostRequest(JUNIT_SERVLET_PATH
                + "/org.apache.sling.testing.samples.failingtests.json").withCredentials(getServerUsername(), getServerPassword());
        getRequestExecutor().execute(r).assertStatus(200);
       
        final JSONArray json = new JSONArray(new JSONTokener((getRequestExecutor().getContent())));
       
        assertEquals(
                "initializationError(org.apache.sling.testing.samples.failingtests.EmptyTest): No runnable methods",
                getFailure(json, "org.apache.sling.testing.samples.failingtests.EmptyTest")
        );
View Full Code Here

        return getContent(url + "/" + name + ".txt", CONTENT_TYPE_PLAIN);
    }

    private String[] getPropertyArray(String url, String name) throws Exception {
        JSONObject jo = new JSONObject(getContent(url + "/" + name + ".json", CONTENT_TYPE_JSON));
        JSONArray arr = jo.getJSONArray(name);
        String[] result = new String[arr.length()];
        for (int i = 0; i < arr.length(); i++) {
            result[i] = arr.getString(i);
        }
        return result;
    }
View Full Code Here

        assertTrue("jcr:mixinTypes expected after setting them", json.has("jcr:mixinTypes"));
       
        Object mixObject = json.get("jcr:mixinTypes");
        assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JSONArray);
       
        JSONArray mix = (JSONArray) mixObject;
        assertTrue("jcr:mixinTypes must have a single entry", mix.length() == 1);
        assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.get(0));

        // remove mixin
        props.clear();
        props.put("jcr:mixinTypes@Delete", "-");
        testClient.createNode(location, props);
View Full Code Here

        assertTrue(object instanceof JSONObject);
          assertExpectedJSON((JSONObject)object, (JSONObject)object2);
      } else if (object instanceof JSONArray) {
        //compare the array
        assertTrue(object2 instanceof JSONArray);
        JSONArray actualArray = (JSONArray)object2;
        Set<Object> actualValuesSet = new HashSet<Object>();
        for (int i=0; i < actualArray.length(); i++) {
          actualValuesSet.add(actualArray.get(i));
        }

        JSONArray expectedArray = (JSONArray)object;
        for (int i=0; i < expectedArray.length(); i++) {
          assertTrue(actualValuesSet.contains(expectedArray.get(i)));
        }
        } else {
          assertEquals("Value of key: " + key, object, object2);
        }
      }
View Full Code Here

    postParams.add(new NameValuePair(":http-equiv-accept", "application/json,*/*;q=0.9"));
        HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
       
        String responseBodyAsString = post.getResponseBodyAsString();
    JSONObject responseJSON = new JSONObject(responseBodyAsString);
        JSONArray changes = responseJSON.getJSONArray("changes");
        JSONObject checkoutChange = changes.getJSONObject(0);
        assertEquals("checkout", checkoutChange.getString("type"));
   
        // assert content at new location
        String content2 = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

View Full Code Here

                "org.apache.sling.junit.scriptable.ScriptableTestsProvider",
                null,
                "json"
                );
        executor.assertContentType("application/json");
        final JSONArray json = new JSONArray(new JSONTokener((executor.getContent())));
       
        int testsCount = 0;
        final List<String> failures = new ArrayList<String>();
        for(int i = 0 ; i < json.length(); i++) {
            final JSONObject obj = json.getJSONObject(i);
            if("test".equals(obj.getString("INFO_TYPE"))) {
                testsCount++;
                if(obj.has("failure")) {
                    failures.add(obj.get("failure").toString());
                }
View Full Code Here

                    try {
                        json.put("success", false);
                        JSONObject messages = new JSONObject();
                        for (Map.Entry<String, List<String>> entry : vr.getFailureMessages().entrySet()) {
                            String key = entry.getKey();
                            JSONArray errors = new JSONArray();
                            for (String message : entry.getValue()) {
                                errors.put(message);
                            }
                            messages.put(key, errors);
                        }
                        json.put("messages", messages);
                        response.getWriter().print(json.toString());
View Full Code Here

    public String prettyPrint(JSONObject jo, Options opt) throws JSONException {
        int n = jo.length();
        if (n == 0) {
            return "{}";
        }
        final JSONArray children = new JSONArray();
        Iterator<String> keys = jo.keys();
        StringBuilder sb = new StringBuilder("{");
        int newindent = opt.initialIndent + opt.indent;
        String o;
        if (n == 1) {
            o = keys.next();
            final Object v = jo.get(o);
            if(!skipChildObject(children, opt, o, v)) {
                sb.append(quote(o));
                sb.append(": ");
                sb.append(valueToString(v, opt));
            }
        } else {
            while (keys.hasNext()) {
                o = keys.next();
                final Object v = jo.get(o);
                if(skipChildObject(children, opt, o, v)) {
                    continue;
                }
                if (sb.length() > 1) {
                    sb.append(",\n");
                } else {
                    sb.append('\n');
                }
                indent(sb, newindent);
                sb.append(quote(o.toString()));
                sb.append(": ");
                sb.append(valueToString(v,
                        options().withIndent(opt.indent).withInitialIndent(newindent)));
            }
            if (sb.length() > 1) {
                sb.append('\n');
                indent(sb, newindent);
            }
        }
       
        /** Render children if any were skipped (in "children in arrays" mode) */
        if(children.length() > 0) {
            if (sb.length() > 1) {
                sb.append(",\n");
            } else {
                sb.append('\n');
            }
View Full Code Here

                testParameters.getTestClassesSelector(),
                testParameters.getTestMethodSelector(),
                "json"
                );
        executor.assertContentType("application/json");
        final JSONArray json = new JSONArray(new JSONTokener((executor.getContent())));

        // 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));
            }
        }
       
View Full Code Here

TOP

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

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.