Source Code Cross Referenced for VariableTest.java in  » Library » Apache-commons-jxpath-1.2-src » org » apache » commons » jxpath » ri » compiler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons jxpath 1.2 src » org.apache.commons.jxpath.ri.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.jxpath.ri.compiler;
017:
018:        import org.apache.commons.jxpath.JXPathContext;
019:        import org.apache.commons.jxpath.JXPathTestCase;
020:        import org.apache.commons.jxpath.Variables;
021:
022:        /**
023:         * Test basic functionality of JXPath - infoset types,
024:         * operations.
025:         *
026:         * @author Dmitri Plotnikov
027:         * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:42 $
028:         */
029:
030:        public class VariableTest extends JXPathTestCase {
031:            private JXPathContext context;
032:
033:            /**
034:             * Construct a new instance of this test case.
035:             *
036:             * @param name Name of the test case
037:             */
038:            public VariableTest(String name) {
039:                super (name);
040:            }
041:
042:            public void setUp() {
043:                if (context == null) {
044:                    context = JXPathContext.newContext(null);
045:                    context.setFactory(new VariableFactory());
046:
047:                    Variables vars = context.getVariables();
048:                    vars.declareVariable("a", new Double(1));
049:                    vars.declareVariable("b", new Double(1));
050:                    vars.declareVariable("c", null);
051:                    vars.declareVariable("d", new String[] { "a", "b" });
052:                    vars.declareVariable("integer", new Integer(1));
053:                    vars.declareVariable("nan", new Double(Double.NaN));
054:                    vars.declareVariable("x", null);
055:                }
056:            }
057:
058:            public void testVariables() {
059:                // Variables
060:                assertXPathValueAndPointer(context, "$a", new Double(1), "$a");
061:            }
062:
063:            public void testVariablesInExpressions() {
064:                assertXPathValue(context, "$a = $b", Boolean.TRUE);
065:
066:                assertXPathValue(context, "$a = $nan", Boolean.FALSE);
067:
068:                assertXPathValue(context, "$a + 1", new Double(2));
069:
070:                assertXPathValue(context, "$c", null);
071:
072:                assertXPathValue(context, "$d[2]", "b");
073:            }
074:
075:            public void testInvalidVariableName() {
076:                boolean exception = false;
077:                try {
078:                    context.getValue("$none");
079:                } catch (Exception ex) {
080:                    exception = true;
081:                }
082:                assertTrue(
083:                        "Evaluating '$none', expected exception - did not get it",
084:                        exception);
085:
086:                exception = false;
087:                try {
088:                    context.setValue("$none", new Integer(1));
089:                } catch (Exception ex) {
090:                    exception = true;
091:                }
092:                assertTrue(
093:                        "Setting '$none = 1', expected exception - did not get it",
094:                        exception);
095:            }
096:
097:            public void testNestedContext() {
098:                JXPathContext nestedContext = JXPathContext.newContext(context,
099:                        null);
100:
101:                assertXPathValue(nestedContext, "$a", new Double(1));
102:            }
103:
104:            public void testSetValue() {
105:                assertXPathSetValue(context, "$x", new Integer(1));
106:            }
107:
108:            public void testCreatePathDeclareVariable() {
109:                // Calls factory.declareVariable("string")
110:                assertXPathCreatePath(context, "$string", null, "$string");
111:            }
112:
113:            public void testCreatePathAndSetValueDeclareVariable() {
114:                // Calls factory.declareVariable("string")
115:                assertXPathCreatePathAndSetValue(context, "$string", "Value",
116:                        "$string");
117:            }
118:
119:            public void testCreatePathDeclareVariableSetCollectionElement() {
120:                // Calls factory.declareVariable("stringArray"). 
121:                // The factory needs to create a collection
122:                assertXPathCreatePath(context, "$stringArray[2]", "",
123:                        "$stringArray[2]");
124:
125:                // See if the factory populated the first element as well
126:                assertEquals("Created <" + "$stringArray[1]" + ">", "Value1",
127:                        context.getValue("$stringArray[1]"));
128:            }
129:
130:            public void testCreateAndSetValuePathDeclareVariableSetCollectionElement() {
131:                // Calls factory.declareVariable("stringArray"). 
132:                // The factory needs to create a collection
133:                assertXPathCreatePathAndSetValue(context, "$stringArray[2]",
134:                        "Value2", "$stringArray[2]");
135:
136:                // See if the factory populated the first element as well
137:                assertEquals("Created <" + "$stringArray[1]" + ">", "Value1",
138:                        context.getValue("$stringArray[1]"));
139:            }
140:
141:            public void testCreatePathExpandCollection() {
142:                context.getVariables().declareVariable("array",
143:                        new String[] { "Value1" });
144:
145:                // Does not involve factory at all - just expands the collection
146:                assertXPathCreatePath(context, "$array[2]", "", "$array[2]");
147:
148:                // Make sure it is still the same array
149:                assertEquals("Created <" + "$array[1]" + ">", "Value1", context
150:                        .getValue("$array[1]"));
151:            }
152:
153:            public void testCreatePathAndSetValueExpandCollection() {
154:                context.getVariables().declareVariable("array",
155:                        new String[] { "Value1" });
156:
157:                // Does not involve factory at all - just expands the collection
158:                assertXPathCreatePathAndSetValue(context, "$array[2]",
159:                        "Value2", "$array[2]");
160:
161:                // Make sure it is still the same array
162:                assertEquals("Created <" + "$array[1]" + ">", "Value1", context
163:                        .getValue("$array[1]"));
164:            }
165:
166:            public void testCreatePathDeclareVariableSetProperty() {
167:                // Calls factory.declareVariable("test"). 
168:                // The factory should create a TestBean
169:                assertXPathCreatePath(context, "$test/boolean", Boolean.FALSE,
170:                        "$test/boolean");
171:
172:            }
173:
174:            public void testCreatePathAndSetValueDeclareVariableSetProperty() {
175:                // Calls factory.declareVariable("test"). 
176:                // The factory should create a TestBean
177:                assertXPathCreatePathAndSetValue(context, "$test/boolean",
178:                        Boolean.TRUE, "$test/boolean");
179:
180:            }
181:
182:            public void testCreatePathDeclareVariableSetCollectionElementProperty() {
183:                // Calls factory.declareVariable("testArray").
184:                // The factory should create a collection of TestBeans.
185:                // Then calls factory.createObject(..., collection, "testArray", 1).
186:                // That one should produce an instance of TestBean and 
187:                // put it in the collection at index 1.
188:                assertXPathCreatePath(context, "$testArray[2]/boolean",
189:                        Boolean.FALSE, "$testArray[2]/boolean");
190:            }
191:
192:            public void testCreatePathAndSetValueDeclVarSetCollectionElementProperty() {
193:                // Calls factory.declareVariable("testArray").
194:                // The factory should create a collection of TestBeans.
195:                // Then calls factory.createObject(..., collection, "testArray", 1).
196:                // That one should produce an instance of TestBean and 
197:                // put it in the collection at index 1.
198:                assertXPathCreatePathAndSetValue(context,
199:                        "$testArray[2]/boolean", Boolean.TRUE,
200:                        "$testArray[2]/boolean");
201:            }
202:
203:            public void testRemovePathUndeclareVariable() {
204:                // Undeclare variable
205:                context.getVariables().declareVariable("temp", "temp");
206:                context.removePath("$temp");
207:                assertTrue("Undeclare variable", !context.getVariables()
208:                        .isDeclaredVariable("temp"));
209:
210:            }
211:
212:            public void testRemovePathArrayElement() {
213:                // Remove array element - reassigns the new array to the var
214:                context.getVariables().declareVariable("temp",
215:                        new String[] { "temp1", "temp2" });
216:                context.removePath("$temp[1]");
217:                assertEquals("Remove array element", "temp2", context
218:                        .getValue("$temp[1]"));
219:            }
220:
221:            public void testRemovePathCollectionElement() {
222:                // Remove list element - does not create a new list
223:                context.getVariables().declareVariable("temp",
224:                        list("temp1", "temp2"));
225:                context.removePath("$temp[1]");
226:                assertEquals("Remove collection element", "temp2", context
227:                        .getValue("$temp[1]"));
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.