Package org.apache.sling.commons.json

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


        String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, props);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);


    //2. Second, import on top of the node from #1 to replace some properties.

        props.clear();
        props.put(SlingPostConstants.RP_OPERATION,
            SlingPostConstants.OPERATION_IMPORT);

        String jsonContent2 = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport_replaceProps.json"));

        props.put(SlingPostConstants.RP_CONTENT, jsonContent2);
        props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
        props.put(SlingPostConstants.RP_REDIRECT_TO, importedNodeUrl);
        props.put(SlingPostConstants.RP_REPLACE, "false");
        props.put(SlingPostConstants.RP_REPLACE_PROPERTIES, "true");
        String importedNodeUrl2 = testClient.createNode(importedNodeUrl, props);
        assertEquals(importedNodeUrl, importedNodeUrl2);

        // assert content at new location
        String content2 = getContent(importedNodeUrl2 + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj2 = new JSONObject(content2);
    assertNotNull(jsonObj2);

    //assert the imported content is there.
        String expectedJsonContent2 = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport_replaceProps.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent2), jsonObj2);
    }
View Full Code Here


            testFile, SlingPostConstants.RP_CONTENT_FILE, null);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert that the versionable node is checked in.
    assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));


    //now try with the checkin value set to false
    testFile.delete();
        props.clear();
        props.put(SlingPostConstants.RP_OPERATION,
            SlingPostConstants.OPERATION_IMPORT);

        String testNodeName2 = "testNode_" + String.valueOf(random.nextInt());
        props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName2);
        testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json"));
        props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
        props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
        props.put(SlingPostConstants.RP_CHECKIN, "false");
        String importedNodeUrl2 = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true,
            testFile, SlingPostConstants.RP_CONTENT_FILE, null);

        // assert content at new location
        String content2 = getContent(importedNodeUrl2 + ".json", CONTENT_TYPE_JSON);

    JSONObject jsonObj2 = new JSONObject(content2);
    assertNotNull(jsonObj2);

    //assert that the versionable node is checked in.
    assertTrue(jsonObj2.getBoolean("jcr:isCheckedOut"));
    }
View Full Code Here

            testFile, SlingPostConstants.RP_CONTENT_FILE, null);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert that the versionable node is checked in.
    assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));


    //2. try an update with the :autoCheckout value set to false
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION,
                    SlingPostConstants.OPERATION_IMPORT));
        postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
        postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
        postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
        postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "false"));
        postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
        assertPostStatus(importedNodeUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, "Expected error from VersionException");

    //3. now try an update with the :autoCheckout value set to true
        postParams.clear();
        postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION,
        SlingPostConstants.OPERATION_IMPORT));
    postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "true"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
    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);

    JSONObject jsonObj2 = new JSONObject(content2);
    assertNotNull(jsonObj2);
   
    //make sure it was really updated
    assertEquals("def2", jsonObj2.getString("abc"));
   
    //assert that the versionable node is checked back in.
    assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));   
    }
View Full Code Here

            testFile, SlingPostConstants.RP_CONTENT_FILE, null);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
    }
View Full Code Here

        assertTrue(importedNodeUrl.endsWith("/nodeName"));

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
    }
View Full Code Here

        String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, props);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
    }
View Full Code Here

        assertTrue(importedNodeUrl.endsWith("/nodeName"));

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
    }
View Full Code Here

            testFile, SlingPostConstants.RP_CONTENT_FILE, null);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
    }
View Full Code Here

        assertTrue(importedNodeUrl.endsWith("/nodeName"));

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
    }
View Full Code Here

        String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, props);

        // assert content at new location
        String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);

    JSONObject jsonObj = new JSONObject(content);
    assertNotNull(jsonObj);

    //assert the imported content is there.
        String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
    assertExpectedJSON(new JSONObject(expectedJsonContent), 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.