Source Code Cross Referenced for FlowJXPathSelectionListTestCase.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » woody » datatype » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.woody.datatype 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.cocoon.woody.datatype;
019:
020:        import java.io.Writer;
021:        import java.util.ArrayList;
022:        import java.util.HashMap;
023:        import java.util.List;
024:        import java.util.Locale;
025:        import java.util.Map;
026:
027:        import javax.xml.parsers.DocumentBuilder;
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:        import javax.xml.transform.TransformerFactory;
030:        import javax.xml.transform.dom.DOMSource;
031:        import javax.xml.transform.stream.StreamResult;
032:
033:        import org.apache.avalon.framework.context.Context;
034:        import org.apache.avalon.framework.context.DefaultContext;
035:        import org.apache.cocoon.components.ContextHelper;
036:        import org.apache.cocoon.components.flow.FlowHelper;
037:        import org.apache.cocoon.core.container.ContainerTestCase;
038:        import org.apache.cocoon.environment.ObjectModelHelper;
039:        import org.apache.cocoon.environment.Request;
040:        import org.apache.cocoon.environment.mock.MockRequest;
041:        import org.apache.cocoon.woody.Constants;
042:        import org.apache.cocoon.xml.dom.DOMBuilder;
043:        import org.apache.excalibur.source.Source;
044:        import org.apache.excalibur.source.impl.ResourceSource;
045:        import org.custommonkey.xmlunit.Diff;
046:        import org.w3c.dom.Document;
047:        import org.w3c.dom.Element;
048:
049:        /**
050:         * Test case for Woody's FlowModelSelectionList datatype.
051:         * @version CVS $Id: FlowJXPathSelectionListTestCase.java 433543 2006-08-22 06:22:54Z crossley $
052:         */
053:        public class FlowJXPathSelectionListTestCase extends ContainerTestCase {
054:
055:            protected DatatypeManager datatypeManager;
056:            protected DocumentBuilder parser;
057:
058:            /* (non-Javadoc)
059:             * @see junit.framework.TestCase#setUp()
060:             */
061:            protected void setUp() throws Exception {
062:                super .setUp();
063:                datatypeManager = (DatatypeManager) this 
064:                        .lookup(DatatypeManager.ROLE);
065:                DocumentBuilderFactory factory = DocumentBuilderFactory
066:                        .newInstance();
067:                factory.setNamespaceAware(true);
068:                parser = factory.newDocumentBuilder();
069:            }
070:
071:            /* (non-Javadoc)
072:             * @see junit.framework.TestCase#tearDown()
073:             */
074:            protected void tearDown() throws Exception {
075:                if (datatypeManager != null) {
076:                    this .release(datatypeManager);
077:                }
078:                super .tearDown();
079:            }
080:
081:            /**
082:             * Test the generateSaxFragment method.
083:             */
084:            public void testGenerateSaxFragment() throws Exception {
085:                List beans = new ArrayList(2);
086:                beans.add(new TestBean("1", "One"));
087:                beans.add(new TestBean("2", "Two"));
088:                Map flowContextObject = new HashMap();
089:                flowContextObject.put("beans", beans);
090:                Request request = new MockRequest();
091:                Map objectModel = new HashMap();
092:                FlowHelper.setContextObject(objectModel, flowContextObject);
093:                objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
094:                Map contextObjectModel = new HashMap();
095:                contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL,
096:                        objectModel);
097:                Context context = new DefaultContext(contextObjectModel);
098:                Source sampleSource = new ResourceSource(
099:                        "resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCase.source.xml");
100:                Document sample = parser.parse(sampleSource.getInputStream());
101:                Element datatypeElement = (Element) sample
102:                        .getElementsByTagNameNS(Constants.WD_NS, "datatype")
103:                        .item(0);
104:                Datatype datatype = datatypeManager.createDatatype(
105:                        datatypeElement, false);
106:                FlowJXPathSelectionList list = new FlowJXPathSelectionList(
107:                        context, "beans", "key", "value", datatype);
108:                DOMBuilder dest = new DOMBuilder();
109:                list.generateSaxFragment(dest, Locale.ENGLISH);
110:                Source expectedSource = new ResourceSource(
111:                        "resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCase.dest.xml");
112:                Document expected = parser.parse(expectedSource
113:                        .getInputStream());
114:                assertEqual("Test if generated list matches expected",
115:                        expected, dest.getDocument());
116:            }
117:
118:            /**
119:             * Test the generateSaxFragment method with a list containing a null value.
120:             */
121:            public void testGenerateSaxFragmentWithNull() throws Exception {
122:                List beans = new ArrayList(2);
123:                beans.add(null);
124:                beans.add(new TestBean("1", "One"));
125:                beans.add(new TestBean("2", "Two"));
126:                Map flowContextObject = new HashMap();
127:                flowContextObject.put("beans", beans);
128:                Request request = new MockRequest();
129:                Map objectModel = new HashMap();
130:                FlowHelper.setContextObject(objectModel, flowContextObject);
131:                objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
132:                Map contextObjectModel = new HashMap();
133:                contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL,
134:                        objectModel);
135:                Context context = new DefaultContext(contextObjectModel);
136:                Source sampleSource = new ResourceSource(
137:                        "resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCase.source.xml");
138:                Document sample = parser.parse(sampleSource.getInputStream());
139:                Element datatypeElement = (Element) sample
140:                        .getElementsByTagNameNS(Constants.WD_NS, "datatype")
141:                        .item(0);
142:                Datatype datatype = datatypeManager.createDatatype(
143:                        datatypeElement, false);
144:                FlowJXPathSelectionList list = new FlowJXPathSelectionList(
145:                        context, "beans", "key", "value", datatype);
146:                DOMBuilder dest = new DOMBuilder();
147:                list.generateSaxFragment(dest, Locale.ENGLISH);
148:                Source expectedSource = new ResourceSource(
149:                        "resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml");
150:                Document expected = parser.parse(expectedSource
151:                        .getInputStream());
152:                assertEqual("Test if generated list matches expected",
153:                        expected, dest.getDocument());
154:            }
155:
156:            /**
157:             * Check is the source document is equal to the one produced by the method under test.
158:             * @param message A message to print in case of failure.
159:             * @param expected The expected (source) document.
160:             * @param actual The actual (output) document.
161:             */
162:            private void assertEqual(String message, Document expected,
163:                    Document actual) {
164:                expected.getDocumentElement().normalize();
165:                actual.getDocumentElement().normalize();
166:                // DIRTY HACK WARNING: we add the "xmlns:wi" attribute reported
167:                // by DOM, as expected, but not generated by the method under test,
168:                // otherwise the comparison would fail. 
169:                actual.getDocumentElement().setAttribute(Constants.WI_PREFIX,
170:                        Constants.WI_NS);
171:                Diff diff = new Diff(expected, actual);
172:                assertTrue(message + ", " + diff.toString(), diff.similar());
173:            }
174:
175:            /**
176:             * Print a document to a writer for debugging purposes.
177:             * @param document The document to print.
178:             * @param out The writer to write to.
179:             */
180:            public final void print(Document document, Writer out) {
181:                TransformerFactory factory = TransformerFactory.newInstance();
182:                try {
183:                    javax.xml.transform.Transformer serializer = factory
184:                            .newTransformer();
185:                    serializer.transform(new DOMSource(document),
186:                            new StreamResult(out));
187:                    out.write('\n');
188:                } catch (Exception e) {
189:                    e.printStackTrace();
190:                }
191:            }
192:
193:            public static class TestBean {
194:                private String key;
195:                private String value;
196:
197:                public TestBean(String key, String value) {
198:                    this .key = key;
199:                    this .value = value;
200:                }
201:
202:                public String getKey() {
203:                    return key;
204:                }
205:
206:                public String getValue() {
207:                    return value;
208:                }
209:
210:                public String toString() {
211:                    return "{ " + key + " : " + value + " }";
212:                }
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.