incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enor...@apache.org
Subject svn commit: r1206611 - in /sling/trunk: bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ bundles/jcr/contentloader/src/test/java/org/apache/...
Date Sat, 26 Nov 2011 21:40:21 GMT
Author: enorman
Date: Sat Nov 26 21:40:18 2011
New Revision: 1206611

URL: http://svn.apache.org/viewvc?rev=1206611&view=rev
Log:
SLING-2108 PostServlet :import operation does not take autoCheckout into account

Modified:
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ContentImportListener.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
    sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
    sling/trunk/bundles/servlets/post/pom.xml
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java
    sling/trunk/launchpad/integration-tests/pom.xml
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ContentImportListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ContentImportListener.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ContentImportListener.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ContentImportListener.java
Sat Nov 26 21:40:18 2011
@@ -64,4 +64,17 @@ public interface ContentImportListener {
      */
 	void onReorder(String orderedPath, String beforeSibbling);
 	
+    /**
+     * A versionable Node has been checked in. The source path provides the path of the 
+     * newly checked in Node.
+     * @since 2.1.4
+     */
+	void onCheckin(String srcPath);
+
+	/**
+     * A versionable Node has been checked out. The source path provides the path of the

+     * newly checked out Node.
+     * @since 2.1.4
+     */
+	void onCheckout(String srcPath);
 }

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
Sat Nov 26 21:40:18 2011
@@ -46,6 +46,16 @@ public abstract class ImportOptions {
 	public abstract boolean isCheckin();
 
 	/**
+	 * Specifies whether versionable nodes is automatically checked out when
+	 * necessary.
+	 * @return true to checkout the versionable nodes, false otherwise
+     * @since 2.1.4
+	 */
+	public boolean isAutoCheckout() {
+		return true;
+	}
+
+	/**
 	 * Check if the import provider for the given file extension should
 	 * be ignored.
 	 * 

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
Sat Nov 26 21:40:18 2011
@@ -50,6 +50,7 @@ import java.util.Map.Entry;
 import java.util.regex.Pattern;
 
 import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -251,6 +252,7 @@ public class DefaultContentCreator imple
         if ( !isParentImport || this.parentNodeStack.size() > 1 ) {
             // if node already exists but should be overwritten, delete it
             if (!this.ignoreOverwriteFlag && this.configuration.isOverwrite() &&
parentNode.hasNode(name)) {
+            	checkoutIfNecessary(parentNode);
                 parentNode.getNode(name).remove();
             }
 
@@ -263,6 +265,7 @@ public class DefaultContentCreator imple
             } else if (primaryNodeType == null) {
 
                 // no explicit node type, use repository default
+            	checkoutIfNecessary(parentNode);
                 node = parentNode.addNode(name);
                 addNodeToCreatedList(node);
                 if ( this.importListener != null ) {
@@ -271,6 +274,7 @@ public class DefaultContentCreator imple
             } else {
 
                 // explicit primary node type
+            	checkoutIfNecessary(parentNode);
                 node = parentNode.addNode(name, primaryNodeType);
                 addNodeToCreatedList(node);
                 if ( this.importListener != null ) {
@@ -319,6 +323,7 @@ public class DefaultContentCreator imple
             String propPath = node.getPath() + "/" + name;
             String uuid = getUUID(node.getSession(), propPath, getAbsPath(node, value));
             if (uuid != null) {
+                checkoutIfNecessary(node);
                 node.setProperty(name, uuid, propertyType);
                 
                 if ( this.importListener != null ) {
@@ -337,6 +342,7 @@ public class DefaultContentCreator imple
                 }
             }
         } else if ( propertyType == PropertyType.DATE ) {
+            checkoutIfNecessary(node);
             try {
               node.setProperty(name, parseDateString(value) );
             }
@@ -348,6 +354,7 @@ public class DefaultContentCreator imple
             	this.importListener.onCreate(node.getProperty(name).getPath());
             }
         } else {
+            checkoutIfNecessary(node);
             if (propertyType == PropertyType.UNDEFINED) {
                 node.setProperty(name, value);
             } else {
@@ -383,6 +390,7 @@ public class DefaultContentCreator imple
                 if (uuids[i] == null) hasAll = false;
             }
 
+            checkoutIfNecessary(node);
             node.setProperty(name, uuids, propertyType);
             if ( this.importListener != null ) {
             	this.importListener.onCreate(node.getProperty(name).getPath());
@@ -392,6 +400,7 @@ public class DefaultContentCreator imple
                 delayedMultipleReferences.put(propPath, uuidOrPaths);
             }
         } else if ( propertyType == PropertyType.DATE ) {
+            checkoutIfNecessary(node);
             try {
               // This modification is to remove the colon in the JSON Timezone
               ValueFactory valueFactory = node.getSession().getValueFactory();
@@ -412,6 +421,7 @@ public class DefaultContentCreator imple
             	this.importListener.onCreate(node.getProperty(name).getPath());
             }
         } else {
+            checkoutIfNecessary(node);
             if (propertyType == PropertyType.UNDEFINED) {
                 node.setProperty(name, values);
             } else {
@@ -536,6 +546,7 @@ public class DefaultContentCreator imple
             String name = getName(property);
             Node parentNode = getParentNode(session, property);
             if (parentNode != null) {
+                checkoutIfNecessary(parentNode);
                 if (parentNode.hasProperty(name) && parentNode.getProperty(name).getDefinition().isMultiple())
{
                     boolean hasAll = true;
                     String[] uuidOrPaths = delayedMultipleReferences.get(property);
@@ -640,6 +651,7 @@ public class DefaultContentCreator imple
         }
         if ( value == null ) {
             if ( node.hasProperty(name) ) {
+            	checkoutIfNecessary(node);
             	String propPath = node.getProperty(name).getPath();
                 node.getProperty(name).remove();
                 if ( this.importListener != null ) {
@@ -647,6 +659,7 @@ public class DefaultContentCreator imple
                 }
             }
         } else {
+        	checkoutIfNecessary(node);
             final Value jcrValue = this.createValue(node.getSession().getValueFactory(),
value);
             node.setProperty(name, jcrValue);
             if ( this.importListener != null ) {
@@ -665,6 +678,7 @@ public class DefaultContentCreator imple
         }
         if ( values == null || values.length == 0 ) {
             if ( node.hasProperty(name) ) {
+            	checkoutIfNecessary(node);
             	String propPath = node.getProperty(name).getPath();
                 node.getProperty(name).remove();
                 if ( this.importListener != null ) {
@@ -672,6 +686,7 @@ public class DefaultContentCreator imple
                 }
             }
         } else {
+        	checkoutIfNecessary(node);
             final Value[] jcrValues = new Value[values.length];
             for(int i = 0; i < values.length; i++) {
                 jcrValues[i] = this.createValue(node.getSession().getValueFactory(), values[i]);
@@ -752,6 +767,7 @@ public class DefaultContentCreator imple
                 if ( newNodeType == null ) {
                     return false;
                 }
+            	checkoutIfNecessary(node);
                 final Node n = node.addNode(token, newNodeType);
                 addNodeToCreatedList(n);
                 if ( this.importListener != null ) {
@@ -925,4 +941,46 @@ public class DefaultContentCreator imple
         }
         return res.toString();
     }
+    
+
+    /**
+     * Find an ancestor that is versionable
+     */
+    protected Node findVersionableAncestor(Node node) throws RepositoryException {
+    	if (node == null) {
+    		return null;
+    	} else  if (isVersionable(node)) {
+            return node;
+        } else {
+            try {
+                node = node.getParent();
+                return findVersionableAncestor(node);
+            } catch (ItemNotFoundException e) {
+                // top-level
+                return null;
+            }
+        }
+    }
+
+    protected boolean isVersionable(Node node) throws RepositoryException {
+        return node.isNodeType("mix:versionable");
+    }
+
+    /**
+     * Checkout the node if needed
+     */
+    protected void checkoutIfNecessary(Node node) throws RepositoryException {
+        if (this.configuration.isAutoCheckout()) {
+            Node versionableNode = findVersionableAncestor(node);
+            if (versionableNode != null) {
+                if (!versionableNode.isCheckedOut()) {
+                    versionableNode.checkout();
+                    if ( this.importListener != null ) {
+                    	this.importListener.onCheckout(versionableNode.getPath());
+                    }
+                }
+            }
+        }
+    }
+    
 }

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
Sat Nov 26 21:40:18 2011
@@ -117,6 +117,9 @@ public class DefaultContentImporter exte
         // finally checkin versionable nodes
         for (final Node versionable : contentCreator.getVersionables()) {
             versionable.checkin();
+            if ( importListener != null ) {
+            	importListener.onCheckin(versionable.getPath());
+            }
         }
     }
 

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
Sat Nov 26 21:40:18 2011
@@ -68,6 +68,12 @@ public class PathEntry extends ImportOpt
     public static final String CHECKIN_DIRECTIVE = "checkin";
 
     /**
+     * The autoCheckout directive specifying whether versionable nodes should be
+     * checked out when necessary
+     */
+    public static final String AUTOCHECKOUT_DIRECTIVE = "autoCheckout";
+
+    /**
      * The ignore import providers directive specifying whether the available {@link ImportProvider}s
      * should be used during content loading. This is a string value that defaults to the
empty
      * string..
@@ -90,6 +96,9 @@ public class PathEntry extends ImportOpt
     /** Should versionable nodes be checked in? */
     private final boolean checkin;
 
+    /** Should versionable nodes be auto checked out when necessary? */
+    private final boolean autoCheckout;
+    
     /** Which import providers should be ignored? @since 2.0.4 */
     private final List<String> ignoreImportProviders;
 
@@ -172,6 +181,14 @@ public class PathEntry extends ImportOpt
             this.checkin = false;
         }
 
+        // autoCheckout directive
+        final String autoCheckoutValue = entry.getDirectiveValue(AUTOCHECKOUT_DIRECTIVE);
+        if (autoCheckoutValue != null) {
+            this.autoCheckout = Boolean.valueOf(autoCheckoutValue);
+        } else {
+            this.autoCheckout = true;
+        }
+
         // expand directive
         this.ignoreImportProviders = new ArrayList<String>();
         final String expandValue = entry.getDirectiveValue(IGNORE_IMPORT_PROVIDERS_DIRECTIVE);
@@ -224,8 +241,16 @@ public class PathEntry extends ImportOpt
     public boolean isCheckin() {
         return this.checkin;
     }
-
+    
     /* (non-Javadoc)
+	 * @see org.apache.sling.jcr.contentloader.ImportOptions#isAutoCheckout()
+	 */
+	@Override
+	public boolean isAutoCheckout() {
+		return this.autoCheckout;
+	}
+
+	/* (non-Javadoc)
 	 * @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isIgnoredImportProvider(java.lang.String)
 	 */
     public boolean isIgnoredImportProvider(String extension) {

Modified: sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
Sat Nov 26 21:40:18 2011
@@ -36,7 +36,12 @@ public class DefaultContentCreatorTest {
                 return false;
             }
 
-            @Override
+			@Override
+			public boolean isAutoCheckout() {
+				return true;
+			}
+
+			@Override
             public boolean isIgnoredImportProvider(String extension) {
                 return false;
             }
@@ -53,6 +58,8 @@ public class DefaultContentCreatorTest {
         
         contentCreator.prepareParsing(parentNode, null);
         this.mockery.checking(new Expectations() {{
+        	allowing(parentNode).isNodeType("mix:versionable"); will(returnValue(Boolean.FALSE));
+        	allowing(parentNode).getParent(); will(returnValue(null));
             oneOf (parentNode).hasProperty("foo"); will(returnValue(Boolean.TRUE));
             oneOf (parentNode).setProperty(with(equal("foo")), with(equal("bar")));
         }});
@@ -71,6 +78,11 @@ public class DefaultContentCreatorTest {
             }
 
             @Override
+			public boolean isAutoCheckout() {
+				return true;
+			}
+
+            @Override
             public boolean isIgnoredImportProvider(String extension) {
                 return false;
             }

Modified: sling/trunk/bundles/servlets/post/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/pom.xml?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/pom.xml (original)
+++ sling/trunk/bundles/servlets/post/pom.xml Sat Nov 26 21:40:18 2011
@@ -140,7 +140,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.contentloader</artifactId>
-            <version>2.1.0</version>
+            <version>2.1.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
Sat Nov 26 21:40:18 2011
@@ -466,6 +466,14 @@ public interface SlingPostConstants {
     public static final String RP_CHECKIN = RP_PREFIX + "checkin";
 
     /**
+     * Name of the request parameter indicating whether versionable nodes should
+     * be checked in during an {@link SlingPostConstants#OPERATION_IMPORT} operation.
+     * 
+     * @since 2.1.2
+     */
+    public static final String RP_AUTO_CHECKOUT = RP_PREFIX + "autoCheckout";
+
+    /**
      * Name of the request attribute (not parameter) indicating that a post operation
      * should not invoke session.save() upon completion.
      * 

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java
Sat Nov 26 21:40:18 2011
@@ -113,6 +113,7 @@ public class ImportOperation extends Abs
         final boolean replace = "true".equalsIgnoreCase(getRequestParamAsString(request,
SlingPostConstants.RP_REPLACE));
         final boolean replaceProperties = "true".equalsIgnoreCase(getRequestParamAsString(request,
SlingPostConstants.RP_REPLACE_PROPERTIES));
         final boolean checkin = "true".equalsIgnoreCase(getRequestParamAsString(request,
SlingPostConstants.RP_CHECKIN));
+        final boolean autoCheckout = "true".equalsIgnoreCase(getRequestParamAsString(request,
SlingPostConstants.RP_AUTO_CHECKOUT));
 
         String basePath = getItemPath(request);
         basePath = removeAndValidateWorkspace(basePath, request.getResourceResolver().adaptTo(Session.class));
@@ -176,7 +177,12 @@ public class ImportOperation extends Abs
                                 return checkin;
                             }
 
-                            @Override
+							@Override
+							public boolean isAutoCheckout() {
+								return autoCheckout;
+							}
+
+							@Override
                             public boolean isIgnoredImportProvider(
                                     String extension) {
                                 // this probably isn't important in this context.
@@ -219,7 +225,14 @@ public class ImportOperation extends Abs
                             }
 
                             public void onCopy(String srcPath, String destPath) {
-                                changes.add(Modification.onMoved(srcPath, destPath));
+                                changes.add(Modification.onCopied(srcPath, destPath));
+                            }
+
+                            public void onCheckin(String srcPath) {
+                                changes.add(Modification.onCheckin(srcPath));
+                            }
+                            public void onCheckout(String srcPath) {
+                                changes.add(Modification.onCheckout(srcPath));
                             }
                         });
             }

Modified: sling/trunk/launchpad/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/pom.xml?rev=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/pom.xml (original)
+++ sling/trunk/launchpad/integration-tests/pom.xml Sat Nov 26 21:40:18 2011
@@ -137,7 +137,7 @@
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.servlets.post</artifactId>
-      <version>2.1.0</version>
+      <version>2.1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>

Modified: 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=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java
Sat Nov 26 21:40:18 2011
@@ -32,6 +32,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
@@ -282,6 +283,81 @@ public class PostServletImportTest exten
     }
 
     /**
+     * SLING-2108 Test import operation which auto checks out versionable nodes.
+     */
+    public void testImportAutoCheckoutNodes() throws IOException, JSONException {
+        final String testPath = TEST_BASE_PATH;
+        Map<String, String> props = new HashMap<String, String>();
+        String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
+        urlsToDelete.add(testNode);
+
+        //1. first create some content to update.
+        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, SERVLET_CONTEXT + 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"));
+
+
+		//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"));		
+    }
+    
+    /**
      * Test import operation for a posted json file
      */
     public void testImportJSONFromFile() throws IOException, JSONException {

Modified: 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=1206611&r1=1206610&r2=1206611&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/post/testimport3.json
Sat Nov 26 21:40:18 2011
@@ -3,5 +3,6 @@
 	"jcr:mixinTypes": [
 		"mix:referenceable",
 		"mix:versionable"
-	]
+	],
+	"abc": "def"
 }
\ No newline at end of file



Mime
View raw message