Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 47330 invoked from network); 27 Jun 2010 19:37:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 Jun 2010 19:37:49 -0000 Received: (qmail 6678 invoked by uid 500); 27 Jun 2010 19:37:49 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 6616 invoked by uid 500); 27 Jun 2010 19:37:49 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 6609 invoked by uid 99); 27 Jun 2010 19:37:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Jun 2010 19:37:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Jun 2010 19:37:44 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0658C2388A4B; Sun, 27 Jun 2010 19:36:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r958411 [2/2] - in /sling/trunk: bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/ bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ bundles/jcr/contentloader/src/main/java/org/apa... Date: Sun, 27 Jun 2010 19:36:50 -0000 To: commits@sling.apache.org From: enorman@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100627193651.0658C2388A4B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java (added) +++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java Sun Jun 27 19:36:49 2010 @@ -0,0 +1,544 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.launchpad.webapp.integrationtest.servlets.post; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import org.apache.sling.commons.json.JSONArray; +import org.apache.sling.commons.json.JSONException; +import org.apache.sling.commons.json.JSONObject; +import org.apache.sling.commons.testing.integration.HttpTestBase; +import org.apache.sling.commons.testing.integration.NameValuePairList; +import org.apache.sling.servlets.post.SlingPostConstants; + +/** Test content import via the MicrojaxPostServlet */ +public class PostServletImportTest extends HttpTestBase { + + public static final String TEST_BASE_PATH = "/sling-import-tests"; + static Random random = new Random(); + + File testFile; + + /* (non-Javadoc) + * @see org.apache.sling.commons.testing.integration.HttpTestBase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + if (testFile != null) { + //cleanup temp file + testFile.delete(); + } + super.tearDown(); + } + + static String getStreamAsString(InputStream is) throws IOException { + final StringBuilder content = new StringBuilder(); + final byte [] buffer = new byte[16384]; + int n = 0; + while( (n = is.read(buffer, 0, buffer.length)) > 0) { + content.append(new String(buffer, 0, n)); + } + return content.toString(); + } + + private File getTestFile(InputStream inputStream) throws IOException { + File tempFile = File.createTempFile("file-to-upload", null, new File("target")); + FileOutputStream outputStream = new FileOutputStream(tempFile); + byte[] bbuf = new byte[16384]; //16k + int len; + while ((len = inputStream.read(bbuf)) != -1) { + outputStream.write(bbuf, 0, len); + } + outputStream.flush(); + outputStream.close(); + return tempFile; + } + + protected void assertExpectedJSON(JSONObject expectedJson, JSONObject actualJson) throws JSONException { + Iterator keys = expectedJson.keys(); + while (keys.hasNext()) { + String key = keys.next(); + + Object object = expectedJson.get(key); + Object object2 = actualJson.get(key); + if (object instanceof JSONObject) { + 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 actualValuesSet = new HashSet(); + 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(object, object2); + } + } + } + + + /** + * Test import operation which replaces existing content + */ + public void testImportReplace() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + //add node that will get replaced + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put("propTest", "propTestValue"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath + "/" + testNodeName, props); + + //import with the replace option to replace the existing node. + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + props.put(SlingPostConstants.RP_NODE_NAME, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "json"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + props.put(SlingPostConstants.RP_REPLACE, "true"); + String importedNodeUrl2 = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + testFile, SlingPostConstants.RP_CONTENT_FILE, null); + + //the new node should have the same path as the replaced node + assertEquals(importedNodeUrl, importedNodeUrl2); + + // assert content at new location + String content = getContent(importedNodeUrl2 + ".3.json", CONTENT_TYPE_JSON); + + JSONObject jsonObj = new JSONObject(content); + assertNotNull(jsonObj); + assertNull(jsonObj.optString("propTest", null)); //test property should be gone. + + //assert the imported content is there. + String jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + /** + * Test import operation which checks in versionable nodes. + */ + public void testImportCheckinNodes() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "json"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + props.put(SlingPostConstants.RP_CHECKIN, "true"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + 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, 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")); + } + + /** + * Test import operation for a posted json file + */ + public void testImportJSONFromFile() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "json"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + /** + * Test import operation for a posted json file without the optional name + */ + public void testImportJSONFromFileWithoutOptionalName() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.json")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "json"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + testFile, SlingPostConstants.RP_CONTENT_FILE, null); + + //make sure the name is what was inside the file. + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + /** + * Test import operation for a posted json string + */ + public void testImportJSONFromRequestParam() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + String jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + props.put(SlingPostConstants.RP_CONTENT, jsonContent); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "json"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + 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. + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + /** + * Test import operation for a posted json string without the optional name + */ + public void testImportJSONFromRequestParamWithoutOptionalName() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.json")); + props.put(SlingPostConstants.RP_CONTENT, jsonContent); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "json"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, props); + + //make sure the name is what was inside the file. + 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. + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + public void testImportXMLFromFile() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.xml")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "xml"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + public void testImportXMLFromFileWithoutOptionalName() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.xml")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "xml"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + testFile, SlingPostConstants.RP_CONTENT_FILE, null); + + //make sure the name is what was inside the file. + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + public void testImportXMLFromRequestParam() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + String xmlContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.xml")); + props.put(SlingPostConstants.RP_CONTENT, xmlContent); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "xml"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + public void testImportXMLFromRequestParamWithoutOptionalName() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String xmlContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.xml")); + props.put(SlingPostConstants.RP_CONTENT, xmlContent); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "xml"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, props); + + //make sure the name is what was inside the file. + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + + public void testImportZipFromFile() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.zip")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "zip"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimportzip.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + public void testImportJarFromFile() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testNode_" + String.valueOf(random.nextInt()); + props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.jar")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "jar"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimportzip.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + + + public void testImportJCRXMLFromFile() throws IOException, JSONException { + final String testPath = TEST_BASE_PATH; + Map props = new HashMap(); + String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props); + urlsToDelete.add(testNode); + + props.clear(); + props.put(SlingPostConstants.RP_OPERATION, + SlingPostConstants.OPERATION_IMPORT); + + String testNodeName = "testnode_1287021810"; + props.put(SlingPostConstants.RP_NODE_NAME, testNodeName); + testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.jcr.xml")); + props.put(SlingPostConstants.RP_CONTENT_TYPE, "jcr.xml"); + props.put(SlingPostConstants.RP_REDIRECT_TO, testPath + "/*"); + String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, + 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 jsonContent = (String)getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.json")); + assertExpectedJSON(new JSONObject(jsonContent), jsonObj); + } + +} \ No newline at end of file Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jar URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jar?rev=958411&view=auto ============================================================================== Binary file - no diff available. Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jcr.xml URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jcr.xml?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jcr.xml (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jcr.xml Sun Jun 27 19:36:49 2010 @@ -0,0 +1,29 @@ + + + + nt:unstructured + + + mix:referenceable + + + b8318fed-6b96-46d9-baa0-72a313160d24 + + + propOneValue + + + + nt:unstructured + + + true + + + \ No newline at end of file Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.jcr.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.json URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.json?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.json (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.json Sun Jun 27 19:36:49 2010 @@ -0,0 +1,10 @@ +{ + "jcr:primaryType": "nt:unstructured", + "jcr:mixinTypes": [ + "mix:referenceable" + ], + "propOne" : "propOneValue", + "childOne" : { + "childPropOne" : true + } +} \ No newline at end of file Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.xml URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.xml?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.xml (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.xml Sun Jun 27 19:36:49 2010 @@ -0,0 +1,24 @@ + + nt:unstructured + + mix:referenceable + + + + propOne + propOneValue + String + + + + + childOne + + + childPropOne + true + Boolean + + + + Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.zip URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.zip?rev=958411&view=auto ============================================================================== Binary file - no diff available. Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport.zip ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.json URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.json?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.json (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.json Sun Jun 27 19:36:49 2010 @@ -0,0 +1,12 @@ +{ + "name" : "nodeName", + "jcr:primaryType": "nt:unstructured", + "jcr:mixinTypes": [ + "mix:referenceable" + ], + "propOne" : "propOneValue", + + "childOne" : { + "childPropOne" : true + } +} \ No newline at end of file Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.xml URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.xml?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.xml (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.xml Sun Jun 27 19:36:49 2010 @@ -0,0 +1,26 @@ + + nodeName + nt:unstructured + + mix:referenceable + + + + propOne + propOneValue + String + + + + + childOne + + + childPropOne + true + Boolean + + + + + Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport2.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json Sun Jun 27 19:36:49 2010 @@ -0,0 +1,7 @@ +{ + "jcr:primaryType": "nt:unstructured", + "jcr:mixinTypes": [ + "mix:referenceable", + "mix:versionable" + ] +} \ No newline at end of file Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimportzip.json URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimportzip.json?rev=958411&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimportzip.json (added) +++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimportzip.json Sun Jun 27 19:36:49 2010 @@ -0,0 +1,18 @@ +{ + "jcr:createdBy":"admin", + "jcr:primaryType":"nt:folder", + "childOne":{ + "jcr:createdBy":"admin", + "jcr:primaryType":"nt:folder", + "testfile.txt":{ + "jcr:createdBy":"admin", + "jcr:primaryType":"nt:file", + "jcr:content":{ + "jcr:lastModifiedBy":"admin", + ":jcr:data":21, + "jcr:primaryType":"nt:resource", + "jcr:mimeType":"text/plain", + } + } + } +} \ No newline at end of file