You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2008/12/05 11:32:48 UTC
svn commit: r723702 - in /myfaces/core/branches/2_0_0/api: ./
src/main/javascript/META-INF/resources/javax/faces/_util/
src/main/javascript/META-INF/resources/javax/faces/ajax/
src/test/javascript/org/apache/myfaces/mockups/
src/test/javascript/org/apa...
Author: werpu
Date: Fri Dec 5 02:32:47 2008
New Revision: 723702
URL: http://svn.apache.org/viewvc?rev=723702&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2122
ongoing works in the mockup area... basic dom manipulation now is in place
Added:
myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/test/MockupTest.js
Removed:
myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/test/ScenarioTest.js
Modified:
myfaces/core/branches/2_0_0/api/pom.xml
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_JSF2Utils.js
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/Ajax.js
myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/mockups/BrowserMockups.js
Modified: myfaces/core/branches/2_0_0/api/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/pom.xml?rev=723702&r1=723701&r2=723702&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/pom.xml (original)
+++ myfaces/core/branches/2_0_0/api/pom.xml Fri Dec 5 02:32:47 2008
@@ -86,7 +86,7 @@
<name>javax.faces.Ajax</name>
<type>TESTSUITES</type>
<includes>
- <include>test/ScenarioTest.js</include>
+ <include>test/MockupTest.js</include>
<include>utils/_JSF2UtilsTests.js</include>
<include>ajax/AjaxTests.js</include>
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_JSF2Utils.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_JSF2Utils.js?rev=723702&r1=723701&r2=723702&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_JSF2Utils.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_JSF2Utils.js Fri Dec 5 02:32:47 2008
@@ -17,11 +17,12 @@
*
* reserve the root namespace for myfaces
*/
-if('undefined' != typeof OpenAjax && ('undefined' == typeof org || 'undefined' == typeof org.apache || 'undefined' == typeof org.apache.myfaces) ) {
+if('undefined' != typeof OpenAjax && ('undefined' == typeof org || 'undefined' == typeof org.apache || 'undefined' == typeof org.apache.myfaces ||
+ null == org || null == org.apache || null == org.apache.myfaces) ) {
OpenAjax.hub.registerLibrary("org.apache.myfaces", "myfaces.apache.org", "2.0", null);
}
-if('undefined' == typeof(org.apache.myfaces._JSF2Utils)) {
+if('undefined' == typeof(org.apache.myfaces._JSF2Utils) || null == org.apache.myfaces._JSF2Utils) {
org.apache.myfaces._JSF2Utils = function() {
var _underTest = false;
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/Ajax.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/Ajax.js?rev=723702&r1=723701&r2=723702&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/Ajax.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/Ajax.js Fri Dec 5 02:32:47 2008
@@ -21,15 +21,15 @@
*
* reserve the root namespace
*/
-if('undefined' != typeof OpenAjax && 'undefined' == typeof javax) {
+if('undefined' != typeof OpenAjax && ('undefined' == typeof javax || null == typeof javax)) {
OpenAjax.hub.registerLibrary("javax", "www.sun.com", "1.0", null);
}
-if('undefined' == typeof javax.faces) {
+if('undefined' == typeof javax.faces || null == javax.faces ) {
javax.faces = new Object();
}
-if('undefined' == typeof javax.faces.Ajax) {
+if('undefined' == typeof javax.faces.Ajax || null == javax.faces.Ajax ) {
javax.faces.Ajax = new function() {};
}
Modified: myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/mockups/BrowserMockups.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/mockups/BrowserMockups.js?rev=723702&r1=723701&r2=723702&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/mockups/BrowserMockups.js (original)
+++ myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/mockups/BrowserMockups.js Fri Dec 5 02:32:47 2008
@@ -27,57 +27,221 @@
window.document = new Object();
}
+
+
+
+if('undefined' == typeof(node)) {
+ var node = function(tagName, id) {
+ this.nodeType = "tag";
+ this.attributes = new Object(); /*associative array keeping the attributes list*/
+ this.id = id;
+ this.tagName = tagName;
+ this.childNodes = [];
+ this.nodeValue = null;
+ this.parentNode = null;
+ this._data = [];
+ this.data = null;
+ this.firstChild = null;
+ this.lastChild = null;
+ this.nextSibling = null;
+ this.previousSibling = null;
+ //TODO add supported node functions here
+
+ /**
+ * append child which does all the needed dom concatenation
+ * on the appended child elements
+ * its parents and siblings!
+ */
+ this.appendChild = function(/*Node*/ child) {
+ this.childNodes.push(child);
+ if(this.childNodes.length == 1) {
+ this.firstChild = child;
+ } else {
+ this.childNodes[this.childNodes.length - 2].nextSibling = child;
+ child.previousSibling = this.childNodes[this.childNodes.length - 2];
+ }
+ this.lastChild = child;
+ child.parentNode = this;
+ };
+
+ /**
+ * remove child function
+ * which does all the internally defined cross concatenation
+ * of a dom element!
+ */
+ this.removeChild = function(/*Node*/ child) {
+ var childPos = -1;
+ for(var cnt = 0; cnt < this.childNodes.length && childPos == -1; cnt ++) {
+ if(this.childNodes[cnt] == child) {
+ childPos = cnt;
+ }
+ }
+ if(childPos > -1) {
+ if(childPos < this.childNodes.length - 1 && childPos > 0) {
+ this.childNodes[childPos-1].nextSibling = this.childNodes[childPos+1];
+ this.childNodes[childPos+1].previousSibling = this.childNodes[childPos-1];
+
+ }
+ else if(childPos == 0 && this.childNodes.length > 1) {
+ this.childNodes[1].previousSibling = null;
+ } else if(childPos == this.childNodes.length - 1 & this.childNodes.length > 1) {
+ this.childNodes[this.childNodes.length - 2].nextSibling = null;
+ }
+ this.childNodes.splice(childPos, 1);
+ }
+ };
+
+ /**
+ * implementation of our getElementsByTagName function
+ */
+ this.getElementsByTagName = function(/*String*/tagName) {
+ return this._getElementsByTagName(this, tagName);
+ };
+
+ /**
+ * implementation of our getElementsByTagName function
+ * recursive helper to walk the subtree
+ * in a proper manner!
+ */
+ this._getElementsByTagName = function(/*node*/ rootNode, /*String*/ tagName) {
+ if('undefined' == typeof(rootNode) || null == rootNode || rootNode.childNodes.length == 0) {
+ return [];
+ }
+ var resultArr = [];
+ for(var cnt = 0; cnt < rootNode.childNodes.length; cnt ++) {
+ var node = this.childNodes[cnt];
+ if('undefined' != typeof (node.tagName) && null != node.tagName && node.tagName == tagName) {
+ resultArr.push(node);
+ }
+ }
+ for(cnt = 0; cnt < rootNode.childNodes.length; cnt ++) {
+ var foundResults = this._getElementsByTagName(rootNode.childNodes[cnt],tagName);
+ if(foundResults.length > 0) {
+ resultArr = resultArr.concat(foundResults);
+ }
+ }
+
+ return resultArr;
+ };
+
+ this._getElementById = function(/*String*/ id) {
+ return this.__getElementById(this, id);
+ };
+
+ /**
+ * helper for our document object
+ */
+ this.__getElementById = function(/*node*/ rootNode, /*String*/ id) {
+ if('undefined' != typeof(rootNode) && null != rootNode && 'undefined' != typeof rootNode.id && null != rootNode.id
+ && rootNode.id == id) {
+ return rootNode;
+ }
+ if('undefined' == typeof(rootNode) || null == rootNode
+ || 'undefined' == typeof(rootNode.childNodes) || null == rootNode.childNodes
+ || rootNode.childNodes.length == 0) {
+ return null;
+ }
+ for(var cnt = 0; cnt < this.childNodes.length; cnt ++) {
+ var foundResult = rootNode.childNodes[cnt]._getElementById(id);
+ if(foundResult != null) {
+ return foundResult;
+ }
+ }
+ return null;
+ };
+
+
+ this.appendData = function(/*Object*/ dataVar) {
+ this._data = dataVar;
+ this.data = this._data.join("");
+ };
+
+
+ /**
+ *getAttribute('attributeName') Returns the value of the specified attribute [not class, style or event handler]
+ */
+ this.getAttribute = function(/*String*/ attributeName) {
+ if ('undefined' != typeof(this.attributes.attributeName) && null != this.attributes.attributeName) {
+ return this.attributes.attributeName;
+ }
+ return null;
+ };
+
+ this.removeAttribute = function(/*String*/ attributeName) {
+ var attr = this.getAttribute(attributeName);
+ if ('undefined' != attr && null != attr) {
+ var attrIndex = -1;
+ /**/
+ for(var cnt = 0; cnt < this.attributes.length && attrIndex == -1; cnt ++) {
+ if(attr == this.attributes[cnt]) {
+
+ }
+ }
+ }
+ return attr;
+ };
+
+ this.setAttribute = function(/*String*/name,/*String*/ value) {
+ this.attributes.name = value;
+ };
+ };
+}
+
if('undefined' == typeof document || null == document) {
var document = window.document;
document._idCnt = 0;
document.elements = [];
/*for internal handling*/
document._elementIndex = new Object();
-
+ document.node = new node("document","document");
/**
*Simulation of the create element
*functionality
*/
document.createElement = function(nodeType) {
- var element = new Object();
- element.nodeName = nodeType;
- element.children = [];
- element.id = document._idCnt++;
- return element;
- }
+ return new node(nodeType, document._idCnt++);
+ };
/**
*Simulation of the create textnode
*functionality
*/
document.createTextNode = function(text) {
- var element = new Object();
- element.innerHTML = text;
- element.nodeName = "text";
- element.children = [];
- element.id = document._idCnt++;
+ var element = new node("text", document._idCnt++);
+ element.nodeType="text";
+ element.appendData(text);
return element;
- }
+ };
+
document.getElementById = function(id) {
- //TODO implement this
- }
+ return this.node._getElementById(id);
+ };
- document._getElementById = function(id,node) {
- //TODO implement this
- }
-}
+ /**
+ *internal method only to be used
+ *by testing environments!
+ */
+ document._reset = function() {
+ this._idCnt = 0;
+ this.elements = [];
+ /*for internal handling*/
+ this._elementIndex = new Object();
+ this.node = new node("document","document");
+ };
+};
-if('undefined' == typeof org || null == org) {
- var org = new Object();
- document.org = org;
-}
if('undefined' == typeof javax || null == javax) {
var javax = new Object();
document.javax = javax;
}
+if('undefined' == typeof org || null == org) {
+ var org = new Object();
+ document.org = org;
+}
+
Added: myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/test/MockupTest.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/test/MockupTest.js?rev=723702&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/test/MockupTest.js (added)
+++ myfaces/core/branches/2_0_0/api/src/test/javascript/org/apache/myfaces/test/MockupTest.js Fri Dec 5 02:32:47 2008
@@ -0,0 +1,168 @@
+/*
+ * 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.
+ * under the License.
+ */
+
+/**
+ * JSUnit Test for our testing scenario to be able
+ * to test the test integration
+ *
+ * We need to test if the scenario test is given
+ * then we have most of the setup in place
+ * and do various tests on our test mockups if they behave accordingly!
+ *
+ */
+
+function SimpleTest(name)
+{
+ TestCase.call( this, name );
+}
+
+
+function SimpleTest_testTestScenario() {
+ this.assertTrue( "This test should succeed" , helloWorld() == "hello world" );
+}
+
+/**
+ * check for existing dom and
+ */
+function SimpleTest_testDocumentAndWindowExists() {
+ this.assertTrue("Window object exists", 'undefined' != typeof(window) && null != window);
+ this.assertTrue("Document Object exists", 'undefined' != typeof(document) && null != document);
+ this.assertTrue("Node type exists", 'undefined' != typeof(node) && null != node);
+}
+
+function SimpleTest_testDocumentHasNode() {
+ this.assertTrue("Document has 1 node", 'undefined' != typeof(document.node) && null != document.node);
+}
+
+function SimpleTest_testElementInsertion() {
+ var element = document.createElement("div");
+ this.assertTrue("Element must be of the correct type", element instanceof node);
+ element.id = "rootNode_after_document";
+ document.node.appendChild(element);
+
+ this.assertTrue("nodelist on the document must be size 1", document.node.childNodes.length == 1);
+
+ var element2 = document.createElement("div");
+ element2.id = "div2";
+ document.node.appendChild(element2);
+
+ this.assertTrue("nodelist on the document must be size 2", document.node.childNodes.length == 2);
+ this.assertTrue("previoussibling test 1", 'undefined' == typeof(element.previousSibling) || null == element.previousSibling);
+ this.assertTrue("previoussibling test 2", 'undefined' != typeof(element.nextSibling) && null != element.nextSibling);
+
+ this.assertTrue("previoussibling test 3", 'undefined' == typeof(element2.nextSibling) || null == element2.nextSibling);
+ this.assertTrue("previoussibling test 4", 'undefined' != typeof(element2.previousSibling) && null != element2.previousSibling);
+
+ var element3 = document.createElement("div");
+ element3.id = "div3";
+
+ element2.appendChild(element3);
+
+ var element4 = document.createElement("div");
+ element4.id = "div4";
+ document.node.appendChild(element4);
+
+
+ this.assertTrue("previoussibling test 3", 'undefined' != typeof(element2.nextSibling) && null != element2.nextSibling);
+ this.assertTrue("previoussibling test 4", 'undefined' != typeof(element2.previousSibling) && null != element2.previousSibling);
+
+ this.assertTrue("previoussibling test 1", 'undefined' == typeof(element3.previousSibling) || null == element3.previousSibling);
+ this.assertTrue("previoussibling test 3", 'undefined' == typeof(element3.nextSibling) || null == element3.nextSibling);
+
+ var findElement = document.getElementById("div3");
+
+ this.assertTrue("div 3 found", 'undefined' != typeof(findElement) && null != findElement);
+ this.assertTrue("div3 is correct", findElement == element3);
+ findElement = document.getElementById("div4");
+ this.assertTrue("div 4 found", 'undefined' != typeof(findElement) && null != findElement);
+
+ var tagNames = document.node.getElementsByTagName("div");
+ this.assertTrue("checking for elementByTagName size", 'undefined' != typeof(tagNames) && null != tagNames );
+
+ this.assertTrue("size of tags", tagNames.length == 4);
+}
+
+
+function SimpleTest_testElementRemoval() {
+ /*lets throw away everything, do not do this in a browser environment!*/
+ document._reset();
+ var element = document.createElement("div");
+ this.assertTrue("Element must be of the correct type", element instanceof node);
+ element.id = "rootNode after document";
+ document.node.appendChild(element);
+
+
+ var element2 = document.createElement("div");
+ element2.id = "div2";
+ document.node.appendChild(element2);
+
+ var element3 = document.createElement("div");
+ element3.id = "div3";
+
+ element2.appendChild(element3);
+
+ var element4 = document.createElement("div");
+ element4.id = "div4";
+ document.node.appendChild(element4);
+
+ var tagNames = document.node.getElementsByTagName("div");
+ this.assertTrue("size of tags 1:"+tagNames.length, tagNames.length == 4);
+
+
+ document.node.removeChild(element4);
+
+ tagNames = document.node.getElementsByTagName("div");
+ this.assertTrue("size of tags 2:"+tagNames.length, tagNames.length == 3);
+
+ this.assertTrue("element2 next node == null", 'undefined' == typeof(element2.nextSibling) || null == element2.nextSibling);
+
+ document.node.appendChild(element4);
+ tagNames = document.node.getElementsByTagName("div");
+ this.assertTrue("size of tags 4:"+tagNames.length, tagNames.length == 4);
+
+ document.node.removeChild(element2);
+
+ tagNames = document.node.getElementsByTagName("div");
+ this.assertTrue("size of tags 4:"+tagNames.length, tagNames.length == 2);
+
+ document.node.appendChild(element2);
+ tagNames = document.node.getElementsByTagName("div");
+ this.assertTrue("size of tags 4:"+tagNames.length, tagNames.length == 4);
+
+}
+
+SimpleTest.prototype = new TestCase();
+SimpleTest.glue();
+
+
+
+
+
+
+
+
+function SimpleTestTestSuite()
+{
+ TestSuite.call( this, "SimpleTestTest" );
+ this.addTestSuite( SimpleTest );
+}
+
+
+
+
+SimpleTestTestSuite.prototype = new TestSuite();
+SimpleTestTestSuite.prototype.suite = function (){
+ return new SimpleTestTestSuite();
+}
\ No newline at end of file