You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/03/11 16:23:05 UTC

svn commit: r635973 - in /incubator/sling/trunk: launchpad/content/src/main/resources/content/ launchpad/content/src/main/resources/content/sling-test/ launchpad/content/src/main/resources/content/sling-test/ujax/ sling/ujax/src/main/resources/ujax/

Author: bdelacretaz
Date: Tue Mar 11 08:23:03 2008
New Revision: 635973

URL: http://svn.apache.org/viewvc?rev=635973&view=rev
Log:
SLING-241 - ujax tests re-added to launchpad/content, and two minor fixes in ujax.js fixed so that tests pass

Added:
    incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/
    incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/
    incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js   (with props)
    incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html   (with props)
Modified:
    incubator/sling/trunk/launchpad/content/src/main/resources/content/index.html
    incubator/sling/trunk/sling/ujax/src/main/resources/ujax/ujax.js

Modified: incubator/sling/trunk/launchpad/content/src/main/resources/content/index.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/content/src/main/resources/content/index.html?rev=635973&r1=635972&r2=635973&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/content/src/main/resources/content/index.html (original)
+++ incubator/sling/trunk/launchpad/content/src/main/resources/content/index.html Tue Mar 11 08:23:03 2008
@@ -5,5 +5,8 @@
     <p>
       We'll have more content for you here, hopefully soon...
     </p>
+    <p>
+    	The &micro;jax tests are available at <a href="sling-test/ujax/ujax-test.html">sling-test/ujax/ujax-test.html</a>.
+    </p>
   </body>
 </html>

Added: incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js?rev=635973&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js (added)
+++ incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js Tue Mar 11 08:23:03 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+// Minimal javascript assertion framework, used for ujax automated testing.
+
+function assert(message,condition) {
+  if(condition != true) {
+    alert("Assertion failed: " + message);
+  }
+}
+
+function assertEquals(message,a,b) {
+  if(a!=b) {
+    alert("assertEquals failed: " + message + ": " + a + "!=" + b);
+  }
+}
+
+function assertNotNull(message,o) {
+  if(o==null) {
+    alert("assertNotNull failed: " + message);
+  }
+}
+
+function assertNull(message,o) {
+  if(o!=null) {
+    alert("assertNull failed: " + message);
+  }
+}

Propchange: incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/assert.js
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html?rev=635973&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html (added)
+++ incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html Tue Mar 11 08:23:03 2008
@@ -0,0 +1,146 @@
+<html>
+
+<!--
+	   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.
+-->
+
+<head>
+	<title>&micro;jax test page</title>
+	
+	<script src="/ujax/ujax.js"></script>
+	<script src="assert.js"></script>
+	
+	<style type="text/css">
+	.output {
+		background-color: #FFFF99;
+		border: solid #FF9900 1px;
+		padding: 2px;
+	}
+	.warning {
+		border: solid yellow 1px;
+		background-color: red;
+		color: white;
+		padding: 0.5em;
+		font-weight: bold;
+	}
+	</style>
+</head>
+
+<body onload="runTests()">
+
+<h1>Automated &micro;jax tests</h1>
+<p class="warning">TODO: for now, running these tests requires setting <em>Allow
+Anonymous Access</em> to <em>false</em> on the Sling <em>Authentication
+Filter</em> configuration page.</p>
+
+<p>Loading this page executes some simple automated javascript tests
+of the &micro;jax library.</p>
+
+<h2>Test results</h2>
+<p>If all goes well, the paragraph styled <span class="output">like
+this</span> below should say "Done running tests".</p>
+<p>Tests run quickly, this might have happened already.</p>
+<p>To run the tests again click <a href="javascript:runTests()">here</a>.
+</p>
+<div id="output" class="output" style="padding: 1em;">Tests are
+running...</div>
+
+<h2>More info</h2>
+<p>After running the tests at least once, <a
+	href="/test-data/ujax-test/testhtml-nodes.infinity.json">/ujax-test/testhtml-nodes.json</a>
+should show the JSON data of the nodes created by the test cases.</p>
+<p>See the source code of this page for details.</p>
+
+
+<script language="javascript">
+	  function ujaxPost(url,params) {
+	    var httpcon = ujax.getXHR();
+	    httpcon.open("POST", url, false);
+	    httpcon.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	    httpcon.setRequestHeader("Content-length", params.length);
+	    httpcon.setRequestHeader("Connection", "close");
+	    httpcon.send(params);
+	    return httpcon;
+	  }
+	  
+	  var passes = 0;
+	  var now = new Date().getTime();
+	  var baseTestPath = "/test-data/ujax-test/testhtml-nodes";
+	  var testPath = baseTestPath + "/test-" + now;
+	  
+	  function testPost() {
+	    var c = ujaxPost(testPath,"title=hello&created=&dummy=&time=" + now);
+	    assert("Expected 200 status for POST",c.status == 200);
+	  }
+	  
+	  function verifyPostedElement() {
+	    var data = ujax.getContent(testPath,1);
+	    assertNotNull("data",data);
+	    assertEquals("title matches","hello",data.title);
+	    assertEquals("time matches",now,data.time);
+	    assertEquals("created property is a string","string",typeof(data.created));
+        // TODO implement 'created' autoset property
+	    // assert("created property is not empty",data.created.length > 0);
+	    assertEquals("dummy property is a string","string",typeof(data.dummy));
+	    assert("dummy property is empty",data.dummy.length == 0);
+	  }
+	  
+	  function testGetSessionInfo() {
+	    var session = ujax.getSessionInfo();
+	    assertEquals("session.userID is a string","string",typeof(session.userID));
+        assertEquals("session.userID == 'admin'","admin",session.userID);
+	    assertEquals("session.workspace is a string","string",typeof(session.workspace));
+	    assert("session.workspace contains 'default'",session.workspace.indexOf('default') >= 0);
+	  }
+	  
+	  function testRemoveContent() {
+		var deletePath = baseTestPath + "/ujax-test/testhtml-nodes/delete-" + now;
+	    var c = ujaxPost(deletePath,"title=hello&created=&dummy=&time=" + now);
+	    assert("Expected 200 status for POST",c.status == 200);
+	    
+	    var data = ujax.getContent(deletePath,1);
+	    assertNotNull("data must be found before removeContent",data);
+	    
+	    var d = ujax.removeContent(deletePath);
+	    assert("Expected 200 status for removeContent, got " + d.status,d.status == 200);
+	    data = ujax.getContent(deletePath,1);
+	    assertNull("data should be gone after deletePath (" + deletePath + ")",data);
+	  }
+	  
+	  function testJsonLevels() {
+	    var c = ujaxPost(baseTestPath + "/json-levels", "title=JsonLevelsTest");
+	    var data0 = ujax.getContent(baseTestPath,0);
+	    var data1 = ujax.getContent(baseTestPath,1);
+	    assert("Level 0 must not provide child", typeof data0['json-levels'] == "undefined");
+	    assert("Level 1 must provide child", typeof data1['json-levels'] == "object");
+	    assert("Level 1 must provide child title", data1['json-levels'].title == "JsonLevelsTest");
+	  }
+	  
+	  function runTests() {
+	    var out = document.getElementById("output");
+	    out.innerHTML = "Tests are running...";
+	    assert(null,2 + 2 == 4);
+	    testPost();
+	    verifyPostedElement();
+	    testGetSessionInfo();
+	    testRemoveContent();
+	    testJsonLevels();
+	    out.innerHTML = "<b>Done running tests, pass " + (++passes) + "</b>";
+	  }
+	</script>
+
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/content/src/main/resources/content/sling-test/ujax/ujax-test.html
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/sling/trunk/sling/ujax/src/main/resources/ujax/ujax.js
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/ujax/src/main/resources/ujax/ujax.js?rev=635973&r1=635972&r2=635973&view=diff
==============================================================================
--- incubator/sling/trunk/sling/ujax/src/main/resources/ujax/ujax.js (original)
+++ incubator/sling/trunk/sling/ujax/src/main/resources/ujax/ujax.js Tue Mar 11 08:23:03 2008
@@ -146,7 +146,12 @@
 			and therefore need some additions before they are sent
 			to the server
 			*/
-			path=ujax.baseurl+path+".json";
+			if(maxlevels == "0" || maxlevels) {
+			  maxlevels = "." + maxlevels;
+			} else {
+			  maxlevels = "";
+			}
+			path=ujax.baseurl + path + maxlevels + ".json";
 		}
 	    //checking for a trailing "/*"
 	    if (path.indexOf("/*")>=0) return obj;
@@ -173,7 +178,7 @@
 		var httpcon = ujax.getXHR();
 		if (httpcon) {
 			var params = "ujax:delete="+path;
-			httpcon.open('POST', ujax.baseurl + ujax.currentPath, false);
+			httpcon.open('POST', ujax.baseurl + path, false);
 
 			// Send the proper header information along with the request
 			httpcon.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
@@ -205,7 +210,7 @@
 	 * @type Object
 	 */
 	ujax.getSessionInfo = function() {
-	    var res=ujax.httpGet(ujax.baseurl+"/ujax:sessionInfo.json");
+	    var res=ujax.httpGet(ujax.baseurl+"/ujax.sessionInfo.json");
 	    if(res.status == 200) {
 	    	return ujax.evalString(res.responseText);
 	    }