Source Code Cross Referenced for JNDIBindingUnitTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » xml » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.xml;
023:
024:        import java.util.Properties;
025:        import java.net.URL;
026:        import java.net.InetAddress;
027:        import java.io.IOException;
028:
029:        import org.jboss.xb.binding.Unmarshaller;
030:        import org.jboss.xb.binding.UnmarshallerFactory;
031:        import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
032:        import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
033:        import org.jboss.naming.JNDIBindings;
034:        import org.jboss.naming.JNDIBinding;
035:        import org.jboss.util.xml.JBossEntityResolver;
036:        import org.xml.sax.InputSource;
037:        import org.xml.sax.SAXException;
038:
039:        import junit.framework.TestCase;
040:
041:        /**
042:         * Test unmarshalling xml documents conforming to xml/naming/jndi_binding_service_1_0.xsd
043:         * the org.jboss.naming.JNDIBindings and related objects.
044:         * 
045:         * @author Scott.Stark@jboss.org
046:         * @version $Revision: 57211 $
047:         */
048:        public class JNDIBindingUnitTestCase extends TestCase {
049:            public void testMain() throws Exception {
050:                URL url = getResource("xml/naming/jndi-binding-service_1_0.xsd");
051:                SchemaBinding schemaBinding = XsdBinder.bind(url.toString());
052:                schemaBinding.setIgnoreUnresolvedFieldOrClass(false);
053:
054:                Unmarshaller unmarshaller = UnmarshallerFactory.newInstance()
055:                        .newUnmarshaller();
056:                unmarshaller.setEntityResolver(new JBossEntityResolver() {
057:                    public InputSource resolveEntity(String publicId,
058:                            String systemId) throws SAXException, IOException {
059:                        if (systemId.endsWith("jndi-binding-service_1_0.xsd")) {
060:                            URL url = Thread
061:                                    .currentThread()
062:                                    .getContextClassLoader()
063:                                    .getResource(
064:                                            "xml/naming/jndi-binding-service_1_0.xsd");
065:                            return new InputSource(url.toExternalForm());
066:                        } else if (systemId
067:                                .endsWith("custom-object-binding.xsd")) {
068:                            URL url = Thread
069:                                    .currentThread()
070:                                    .getContextClassLoader()
071:                                    .getResource(
072:                                            "xml/naming/custom-object-binding.xsd");
073:                            return new InputSource(url.toExternalForm());
074:                        } else {
075:                            return super .resolveEntity(publicId, systemId);
076:                        }
077:                    }
078:                });
079:
080:                URL xml = getResource("xml/naming/testBindings.xml");
081:                JNDIBindings bindings = (JNDIBindings) unmarshaller.unmarshal(
082:                        xml.openStream(), schemaBinding);
083:                JNDIBinding[] values = bindings.getBindings();
084:                assertTrue("There are 5 bindings(" + values.length + ")",
085:                        values.length == 5);
086:
087:                JNDIBinding key1 = values[0];
088:                assertTrue("values[0] name is ctx1/key1", key1.getName()
089:                        .equals("ctx1/key1"));
090:                assertTrue("values[0] is string of value1", key1.getText()
091:                        .equals("value1"));
092:
093:                JNDIBinding userHome = values[1];
094:                assertTrue("values[1] name is ctx1/user.home", userHome
095:                        .getName().equals("ctx1/user.home"));
096:                String p = System.getProperty("user.home");
097:                assertTrue("values[1] is property ${user.home}", userHome
098:                        .getText().equals(p));
099:
100:                // Test binding from a text to URL based on the type attribute PropertyEditor
101:                JNDIBinding jbossHome = values[2];
102:                assertTrue("values[2] name is ctx1/key2", jbossHome.getName()
103:                        .equals("ctx1/key2"));
104:                assertTrue("values[2] is http://www.jboss.org", jbossHome
105:                        .getText().equals("http://www.jboss.org"));
106:                assertTrue("values[2] type is java.net.URL", jbossHome
107:                        .getType().equals("java.net.URL"));
108:                Object value2 = jbossHome.getValue();
109:                assertTrue("values[2] value is URL(http://www.jboss.org)",
110:                        value2.equals(new URL("http://www.jboss.org")));
111:
112:                // Test a binding from an xml fragment from a foreign namespace.
113:                JNDIBinding properties = values[3];
114:                Object value = properties.getValue();
115:                assertTrue("values[3] name is ctx2/key1", properties.getName()
116:                        .equals("ctx2/key1"));
117:                assertTrue("values[3] is java.util.Properties",
118:                        value instanceof  Properties);
119:                Properties props = (Properties) value;
120:                assertTrue("Properties(key1) == value1", props.getProperty(
121:                        "key1").equals("value1"));
122:                assertTrue("Properties(key2) == value2", props.getProperty(
123:                        "key2").equals("value2"));
124:
125:                // Test binding from a text to InetAddress based on the editor attribute PropertyEditor
126:                JNDIBinding host = values[4];
127:                assertTrue("values[4] name is hosts/localhost", host.getName()
128:                        .equals("hosts/localhost"));
129:                assertTrue(host.isTrim());
130:                assertTrue("values[4] text is 127.0.0.1", host.getText()
131:                        .equals("127.0.0.1"));
132:                assertTrue(
133:                        "values[4] editor is org.jboss.util.propertyeditor.InetAddressEditor",
134:                        host
135:                                .getEditor()
136:                                .equals(
137:                                        "org.jboss.util.propertyeditor.InetAddressEditor"));
138:                Object value4 = host.getValue();
139:                InetAddress hostValue = (InetAddress) value4;
140:                InetAddress localhost = InetAddress.getByName("127.0.0.1");
141:                assertTrue("values[4] value is InetAddress(127.0.0.1)",
142:                        hostValue.getHostAddress().equals(
143:                                localhost.getHostAddress()));
144:            }
145:
146:            // Private
147:
148:            private static URL getResource(String path) {
149:                java.net.URL url = Thread.currentThread()
150:                        .getContextClassLoader().getResource(path);
151:                if (url == null) {
152:                    fail("URL not found: " + path);
153:                }
154:                return url;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.