[seam-commits] Seam SVN: r14125 - in branches/community/Seam_2_3/jboss-seam-remoting/src: test/javascript and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Jul 13 10:04:37 EDT 2011


Author: manaRH
Date: 2011-07-13 10:04:37 -0400 (Wed, 13 Jul 2011)
New Revision: 14125

Modified:
   branches/community/Seam_2_3/jboss-seam-remoting/src/main/resources/org/jboss/seam/remoting/remote.js
   branches/community/Seam_2_3/jboss-seam-remoting/src/test/javascript/remote.spec.js
   branches/community/Seam_2_3/jboss-seam-remoting/src/test/jsUnit/jsUnitSeamRemoting.html
Log:
fixed testing Seam.Remoting.sendAjaxRequest

Modified: branches/community/Seam_2_3/jboss-seam-remoting/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- branches/community/Seam_2_3/jboss-seam-remoting/src/main/resources/org/jboss/seam/remoting/remote.js	2011-07-08 17:03:46 UTC (rev 14124)
+++ branches/community/Seam_2_3/jboss-seam-remoting/src/main/resources/org/jboss/seam/remoting/remote.js	2011-07-13 14:04:37 UTC (rev 14125)
@@ -708,6 +708,7 @@
     
   asyncReq.open("POST", Seam.Remoting.resourcePath + path, true);
   asyncReq.send(envelope);
+  return asyncReq;
 }
 
 Seam.Remoting.displayError = function(code)

Modified: branches/community/Seam_2_3/jboss-seam-remoting/src/test/javascript/remote.spec.js
===================================================================
--- branches/community/Seam_2_3/jboss-seam-remoting/src/test/javascript/remote.spec.js	2011-07-08 17:03:46 UTC (rev 14124)
+++ branches/community/Seam_2_3/jboss-seam-remoting/src/test/javascript/remote.spec.js	2011-07-13 14:04:37 UTC (rev 14125)
@@ -1,3 +1,20 @@
+/** fake XMLHttpRequest **/
+function myFakeXMLHttpRequest() {
+  this.method = null;
+  this.path = null;
+  this.async = null;
+  this.open = function(method, path, async) {
+	    this.method = method;
+	    this.path = path;
+	    this.async = async;
+	  };
+  this.send = function(envelope) {};
+};
+
+
+
+/** Jasmine spec file for testing remoting javascript **/
+
 describe('Seam Remoting javascript suite', function () {
 
   it('Confirm that URL encoding/decoding function we are using works', function () {
@@ -156,49 +173,48 @@
 	  expect(null).toEqual(Seam.Remoting.extractEncodedSessionId('http://localhost:8080/contextPath/page.seam'));
   });
   
-  // THIS doesn't work
-  xit('Seam.Remoting.Serialize testEncodeAjaxRequest', function() {
-	  var restoreXMLHttpRequest = window.XMLHttpRequest;
-	  window.XMLHttpRequest = dummyXMLHttpRequest;
-	  Seam.Remoting.resourcePath = "/resourcePath";
-	  Seam.Remoting.encodedSessionId = 'abcdefg';
-	  var req = Seam.Remoting.sendAjaxRequest(null, "/execute", null, true); 
-	  expect(req.method).toEqual("POST");
-	  expect(req.path).toEqual("/resourcePath/execute;jsessionid=abcdefg");
-	  expect(req.async).toBeTruthy();
-	  window.XMLHttpRequest = restoreXMLHttpRequest;
-  });
-
-  // THIS doesn't work
-  xit('Seam.Remoting.Serialize testNoEncodeAjaxRequest', function() {
-	  var restoreXMLHttpRequest = window.XMLHttpRequest;
-	  window.XMLHttpRequest = dummyXMLHttpRequest;
-	  Seam.Remoting.resourcePath = "/resourcePath";
-	  Seam.Remoting.encodedSessionId = null;
-	  var req = Seam.Remoting.sendAjaxRequest(null, "/execute", null, true); 
-	  expect(req.method).toEqual("POST");
-	  expect(req.path).toEqual("/resourcePath/execute");
-	  expect(req.async).toBeTruthy();
-	  window.XMLHttpRequest = restoreXMLHttpRequest;
-  });  
   
 });
 
+describe('Seam Remoting javascript suite AJAX tests', function () {
 
-function dummyXMLHttpRequest() {
-  this.method = null;
-  this.path = null;
-  this.async = null;
-}
+	beforeEach(function() {
+		  spyOn(window, 'XMLHttpRequest').andReturn(new myFakeXMLHttpRequest());
+	});
+			
+	it('Seam.Remoting.Serialize faking XMLHttpRequest', function() {		
+		var myRequest = new XMLHttpRequest();		
+		expect(myRequest).toBeDefined();
+		myRequest.open('POST', 'test/path', false);
+		
+		expect(myRequest.path).toBeDefined();		
+		expect(myRequest.path).toEqual('test/path');
+		expect(myRequest.method).toEqual('POST');
+		
+	});
 
-dummyXMLHttpRequest.prototype = {
-  open: function(method, path, async) {
-    this.method = method;
-    this.path = path;
-    this.async = async;
-  },
+	it('Seam.Remoting.Serialize testEncodeAjaxRequest', function() {		
+		Seam.Remoting.resourcePath = "/resourcePath";
+		Seam.Remoting.encodedSessionId = 'abcdefg';
+		
+		var req = Seam.Remoting.sendAjaxRequest(null, "/execute", null, true);
 
-  send: function(envelope) {}
-}
+		// actual tests		
+		expect(req).toBeDefined();
+		expect(req.method).toEqual("POST");
+		expect(req.path).toEqual("/resourcePath/execute;jsessionid=abcdefg");
+		expect(req.async).toBeTruthy();			
+	});
 
-
+	it('Seam.Remoting.Serialize testNoEncodeAjaxRequest', function() {
+		Seam.Remoting.resourcePath = "/resourcePath";
+		Seam.Remoting.encodedSessionId = null;
+		
+		var req = Seam.Remoting.sendAjaxRequest(null, "/execute", null, true);
+		
+		expect(req.method).toEqual("POST");
+		expect(req.path).toEqual("/resourcePath/execute");
+		expect(req.async).toBeTruthy();
+	});  	
+	
+});

Modified: branches/community/Seam_2_3/jboss-seam-remoting/src/test/jsUnit/jsUnitSeamRemoting.html
===================================================================
--- branches/community/Seam_2_3/jboss-seam-remoting/src/test/jsUnit/jsUnitSeamRemoting.html	2011-07-08 17:03:46 UTC (rev 14124)
+++ branches/community/Seam_2_3/jboss-seam-remoting/src/test/jsUnit/jsUnitSeamRemoting.html	2011-07-13 14:04:37 UTC (rev 14125)
@@ -6,8 +6,8 @@
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Seam Remoting JsUnit Tests</title>
 <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
-<script language="JavaScript" type="text/javascript" src="../../../extras/jsUnit/app/jsUnitCore.js"></script>
-<script language="JavaScript" type="text/javascript" src="../../remoting/org/jboss/seam/remoting/remote.js"></script>
+<script language="JavaScript" type="text/javascript" src="../../../../extras/jsUnit/app/jsUnitCore.js"></script>
+<script language="JavaScript" type="text/javascript" src="../../main/resource/org/jboss/seam/remoting/remote.js"></script>
 <script language="JavaScript" type="text/javascript">
 
 /** Confirm that the URL encoding/decoding function we are using works **/



More information about the seam-commits mailing list