Author: bdelacretaz
Date: Fri Dec  7 06:57:57 2007
New Revision: 602113

URL: http://svn.apache.org/viewvc?rev=602113&view=rev
Log:
SLING-127, microjax.removeContent method added in microjax.js, with automated 
test

Modified:
    
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
    
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/assert.js
    
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/microjax-test.html

Modified: 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js?rev=602113&r1=602112&r2=602113&view=diff
==============================================================================
--- 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
 (original)
+++ 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
 Fri Dec  7 06:57:57 2007
@@ -60,7 +60,7 @@
        /**
         * HTTP GET XHR Helper
         * @param {String} url The URL
-        * @return The response body
+        * @return the XHR object, use .responseText for the data
         * @type String
         */
        microjax.httpGet = function(url) {
@@ -68,9 +68,9 @@
            if (httpcon) {
                        httpcon.open('GET', url, false);
                        httpcon.send(null);
-                       return httpcon.responseText;
+                       return httpcon;
            } else {
-                       return "";
+                       return null;
            }
        }
        /**
@@ -131,7 +131,7 @@
         * @param {String} path Path into the current workspace
         * @param {int} maxlevel maximum depth to traverse to
         * @param {Array} filters filter only these properties
-        * @return An Object tree of content nodes and properties
+        * @return An Object tree of content nodes and properties, null if not 
found
         * @type Object
         */
        microjax.getContent = function(path, maxlevels) {
@@ -155,7 +155,29 @@
                // but in tests IE6 tends to cache too much
                var passThroughCacheParam = "?clock=" + new Date().getTime();
            var res=microjax.httpGet(path + passThroughCacheParam + 
(maxlevels?"&maxlevels="+maxlevels:""));
-           return microjax.evalString(res);
+           
+           if(res.status == 200) {
+               return microjax.evalString(res.responseText);
+           }
+           return null; 
+       }
+       
+       /** Remove content by path */
+       microjax.removeContent = function(path) {
+               var httpcon = microjax.getXHR();
+               if (httpcon) {
+                       var params = "ujax_delete="+path;
+                       httpcon.open('POST', microjax.baseurl + 
microjax.currentPath, false);
+
+                       // Send the proper header information along with the 
request
+                       httpcon.setRequestHeader("Content-type", 
"application/x-www-form-urlencoded");
+                       httpcon.setRequestHeader("Content-length", 
params.length);
+                       httpcon.setRequestHeader("Connection", "close");
+                       httpcon.send(params);
+                       return httpcon;
+               } else {
+                       return false;
+               }
        }
        
        /** eval str, accepting various object delimiters */
@@ -173,12 +195,15 @@
         
        /** Get "session info" from repository. Mainly answers the question: 
"Who am I"
         *  and "Which workspace am I logged into.
-        * @return An Object tree containing the session information
+        * @return An Object tree containing the session information, null if 
server status <> 200
         * @type Object
         */
        microjax.getSessionInfo = function() {
            var 
res=microjax.httpGet(microjax.baseurl+"/microjax:sessionInfo.json");
-           return microjax.evalString(res);
+           if(res.status == 200) {
+               return microjax.evalString(res.responseText);
+           }
+           return null;
        }
        
        /** Replace extension in a path */

Modified: 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/assert.js
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/assert.js?rev=602113&r1=602112&r2=602113&view=diff
==============================================================================
--- 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/assert.js
 (original)
+++ 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/assert.js
 Fri Dec  7 06:57:57 2007
@@ -38,3 +38,9 @@
     alert("assertNotNull failed: " + message);
   }
 }
+
+function assertNull(message,o) {
+  if(o!=null) {
+    alert("assertNull failed: " + message);
+  }
+}

Modified: 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/microjax-test.html
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/microjax-test.html?rev=602113&r1=602112&r2=602113&view=diff
==============================================================================
--- 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/microjax-test.html
 (original)
+++ 
incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/test/microjax-test.html
 Fri Dec  7 06:57:57 2007
@@ -102,6 +102,20 @@
            assert("session.workspace contains 
'default'",session.workspace.indexOf('default') >= 0);
          }
          
+         function testRemoveContent() {
+               var deletePath = "/microjax-test/testhtml-nodes/delete-" + now;
+           var c = microjaxPost(deletePath,"title=hello&created=&dummy=&time=" 
+ now);
+           assert("Expected 200 status for POST",c.status == 200);
+           
+           var data = microjax.getContent(deletePath,1);
+           assertNotNull("data must be found before removeContent",data);
+           
+           var d = microjax.removeContent(deletePath);
+           assert("Expected 200 status for removeContent, got " + 
d.status,d.status == 200);
+           data = microjax.getContent(deletePath,1);
+           assertNull("data should be gone after deletePath",data);
+         }
+         
          function runTests() {
            var out = document.getElementById("output");
            out.innerHTML = "Tests are running...";
@@ -109,6 +123,7 @@
            testPost();
            verifyPostedElement();
            testGetSessionInfo();
+           testRemoveContent();
            out.innerHTML = "<b>Done running tests, at " + new Date() + "</b>";
          }
        </script>


Reply via email to