You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/07/25 19:54:17 UTC

svn commit: r425503 - in /incubator/xap/trunk/testsrc/xap/util: _TestHttpUtils.html _TestHttpUtils.js

Author: mturyn
Date: Tue Jul 25 12:54:17 2006
New Revision: 425503

URL: http://svn.apache.org/viewvc?rev=425503&view=rev
Log:
New test for new RequestService's core.

Added:
    incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.html   (with props)
    incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.js   (with props)

Added: incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.html?rev=425503&view=auto
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.html (added)
+++ incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.html Tue Jul 25 12:54:17 2006
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
+	"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>HttpUtils Unit Tests</title>
+    <link rel="stylesheet" type="text/css" href="/jsunit/jsunit/css/jsUnitStyle.css">
+    <script language="JavaScript" type="text/javascript" src="/jsunit/jsunit/app/jsUnitCore.js"></script>
+    <script language="JavaScript" type="text/javascript" src="/jsunit/src/dojo/dojo.js"></script>
+    <script language="JavaScript" type="text/javascript" src="/jsunit/src/xap/util/Utils.js"></script>
+    <script language="JavaScript" type="text/javascript" src="/jsunit/src/xap/Xap.js"></script>
+    <script language="JavaScript" type="text/javascript" src="_TestHttpUtils.js"></script>
+
+    <script language="JavaScript" type="text/javascript">
+    	Xap.bootstrap( "/jsunit" );
+    </script>
+</head>
+
+<body>
+  		
+</body>
+</html>
+	 
\ No newline at end of file

Propchange: incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.js?rev=425503&view=auto
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.js (added)
+++ incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.js Tue Jul 25 12:54:17 2006
@@ -0,0 +1,148 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed 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.
+ *
+ */
+
+function exposeTestFunctionNames() {
+	return ['testGetWithoutCallbackIsSynchronous',
+		'testGetWithCallbackIsAsynchronous',
+		'testPostWithoutCallbackIsSynchronous',
+		'testPostWithCallbackIsAsynchronous'];
+}
+
+function testGetWithoutCallbackIsSynchronous () {
+	var page = 'http://www.mysite.com/users.xal';
+	var content = '<xal><label /></xal>';
+	var request = {
+		open : function (type, url, isAsync) {
+			this.open.called = true;
+			assertEquals('GET', type);
+			assertEquals(page, url);
+			assertTrue(! isAsync);
+		},
+		send : function (postData) {
+			this.send.called = true;
+			assertNull(postData);
+		},
+		responseText : content
+	};
+
+	xap.util.HttpUtils.createHttpRequest = function () {
+		xap.util.HttpUtils.createHttpRequest.called = true;
+		return request;
+	};
+
+	var response = xap.util.HttpUtils.get(page);
+	assertEquals(content, response.responseText);
+
+	assertTrue(xap.util.HttpUtils.createHttpRequest.called);
+	assertTrue(request.open.called);
+	assertTrue(request.send.called);
+}
+
+function testGetWithCallbackIsAsynchronous () {
+	var page = 'http://www.mysite.com/users.xal';
+	var content = '<xal><textField /></xal>';
+	var request = {
+		open : function (type, url, isAsync) {
+			this.open.called = true;
+			assertEquals('GET', type);
+			assertEquals(page, url);
+			assertTrue(isAsync);
+		},
+		send : function (postData) {
+			this.send.called = true;
+			assertNull(postData);
+		},
+		responseText : content
+	};
+
+	xap.util.HttpUtils.createHttpRequest = function () {
+		xap.util.HttpUtils.createHttpRequest.called = true;
+		return request;
+	};
+
+	xap.util.HttpUtils.get(page, function (response) {
+		assertEquals(request.responseText, response.responseText);
+	});
+
+	assertTrue(xap.util.HttpUtils.createHttpRequest.called);
+	assertTrue(request.open.called);
+	assertTrue(request.send.called);
+}
+
+function testPostWithoutCallbackIsSynchronous () {
+	var page = 'http://www.mysite.com/create.php';
+	var postContent = 'id=1&product=arex';
+	var content = '<xal><label /></xal>';
+	var request = {
+		open : function (type, url, isAsync) {
+			this.open.called = true;
+			assertEquals('POST', type);
+			assertEquals(page, url);
+			assertTrue(! isAsync);
+		},
+		send : function (postData) {
+			this.send.called = true;
+			assertEquals(postContent, postData);
+		},
+		responseText : content
+	};
+
+	xap.util.HttpUtils.createHttpRequest = function () {
+		xap.util.HttpUtils.createHttpRequest.called = true;
+		return request;
+	};
+
+	var response = xap.util.HttpUtils.post(page, null, postContent);
+	assertEquals(content, response.responseText);
+
+	assertTrue(xap.util.HttpUtils.createHttpRequest.called);
+	assertTrue(request.open.called);
+	assertTrue(request.send.called);
+}
+
+function testPostWithCallbackIsAsynchronous () {
+	var page = 'http://www.mysite.com/create.php';
+	var postContent = 'id=1&product=arex';
+	var content = '<xal><label /></xal>';
+	var request = {
+		open : function (type, url, isAsync) {
+			this.open.called = true;
+			assertEquals('POST', type);
+			assertEquals(page, url);
+			assertTrue(isAsync);
+		},
+		send : function (postData) {
+			this.send.called = true;
+			assertEquals(postContent, postData);
+		},
+		responseText : content
+	};
+
+	xap.util.HttpUtils.createHttpRequest = function () {
+		xap.util.HttpUtils.createHttpRequest.called = true;
+		return request;
+	};
+
+	xap.util.HttpUtils.post(page, function (response) {
+		assertEquals(request.responseText, response.responseText);
+	}, postContent);
+
+	assertTrue(xap.util.HttpUtils.createHttpRequest.called);
+	assertTrue(request.open.called);
+	assertTrue(request.send.called);
+}
+	
\ No newline at end of file

Propchange: incubator/xap/trunk/testsrc/xap/util/_TestHttpUtils.js
------------------------------------------------------------------------------
    svn:eol-style = native