Source Code Cross Referenced for TestConnectionAssembler.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » assembler » test » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.assembler.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         	(c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         	All rights reserved - see end of file.
004:         	$Id: TestConnectionAssembler.java,v 1.8 2008/01/02 12:05:57 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.assembler.test;
008:
009:        import java.util.StringTokenizer;
010:
011:        import com.hp.hpl.jena.assembler.*;
012:        import com.hp.hpl.jena.assembler.assemblers.ConnectionAssembler;
013:        import com.hp.hpl.jena.assembler.exceptions.CannotLoadClassException;
014:        import com.hp.hpl.jena.rdf.model.Resource;
015:        import com.hp.hpl.jena.shared.JenaException;
016:
017:        public class TestConnectionAssembler extends AssemblerTestBase {
018:            public TestConnectionAssembler(String name) {
019:                super (name);
020:            }
021:
022:            protected Class getAssemblerClass() {
023:                return ConnectionAssembler.class;
024:            }
025:
026:            public void testConnectionAssemblerType() {
027:                testDemandsMinimalType(new ConnectionAssembler(), JA.Connection);
028:            }
029:
030:            public void testConnectionVocabulary() {
031:                assertRange(JA.Connection, JA.connection);
032:                assertDomain(JA.Connection, JA.dbClass);
033:                assertDomain(JA.Connection, JA.dbUser);
034:                assertDomain(JA.Connection, JA.dbPassword);
035:                assertDomain(JA.Connection, JA.dbType);
036:                assertDomain(JA.Connection, JA.dbURL);
037:                assertDomain(JA.Connection, JA.dbClassProperty);
038:                assertDomain(JA.Connection, JA.dbUserProperty);
039:                assertDomain(JA.Connection, JA.dbPasswordProperty);
040:                assertDomain(JA.Connection, JA.dbTypeProperty);
041:                assertDomain(JA.Connection, JA.dbURLProperty);
042:            }
043:
044:            public void testConnectionDescriptionFailsOnMissingURL() {
045:                ConnectionDescription c = new ConnectionDescription(
046:                        "eh:/subject", null, null, null, "myType");
047:                try {
048:                    c.getConnection();
049:                    fail("should trap null URL");
050:                } catch (JenaException e) {
051:                    assertTrue(e
052:                            .getMessage()
053:                            .endsWith(
054:                                    "cannot be opened because no dbURL or dbType was specified"));
055:                }
056:            }
057:
058:            public void testConnectionDescriptionFailsOnMissingType() {
059:                ConnectionDescription c = new ConnectionDescription(
060:                        "eh:/subject", "URL", null, null, null);
061:                try {
062:                    c.getConnection();
063:                    fail("should trap null type");
064:                } catch (JenaException e) {
065:                    assertTrue(e
066:                            .getMessage()
067:                            .endsWith(
068:                                    "cannot be opened because no dbURL or dbType was specified"));
069:                }
070:            }
071:
072:            public void testConnectionInitDefaults() {
073:                Resource init = resourceInModel("x ja:dbUser 'USER'; x ja:dbPassword 'PASS'; x ja:dbURL URL:url; x ja:dbType 'TYPE'");
074:                ConnectionAssembler c = new ConnectionAssembler(init);
075:                assertEquals("USER", c.defaultUser);
076:                assertEquals("PASS", c.defaultPassword);
077:                assertEquals("URL:url", c.defaultURL);
078:                assertEquals("TYPE", c.defaultType);
079:            }
080:
081:            public void testCannotLoadClass() {
082:                Assembler a = new ConnectionAssembler();
083:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbClass 'no.such.class'");
084:                try {
085:                    a.open(root);
086:                    fail("should catch class load failure");
087:                } catch (CannotLoadClassException e) {
088:                    assertEquals(resource("x"), e.getRoot());
089:                    assertEquals("no.such.class", e.getClassName());
090:                    assertInstanceOf(ClassNotFoundException.class, e.getCause());
091:                }
092:            }
093:
094:            public void testDefaultUser() {
095:                Resource init = resourceInModel("x ja:dbUser 'test'");
096:                Resource root = resourceInModel("x rdf:type JA.Connection");
097:                assertEquals("test", new ConnectionAssembler(init)
098:                        .getUser(root));
099:            }
100:
101:            public void testDefaultPassword() {
102:                Resource init = resourceInModel("x ja:dbPassword 'byzantium'");
103:                Resource root = resourceInModel("x rdf:type JA.Connection");
104:                assertEquals("byzantium", new ConnectionAssembler(init)
105:                        .getPassword(root));
106:            }
107:
108:            public void testDefaultURL() {
109:                Resource init = resourceInModel("x ja:dbURL URL:database");
110:                Resource root = resourceInModel("x rdf:type ja:Connection");
111:                assertEquals("URL:database", new ConnectionAssembler(init)
112:                        .getURL(root));
113:            }
114:
115:            public void testDefaultType() {
116:                Resource init = resourceInModel("x ja:dbType 'bodacious'");
117:                Resource root = resourceInModel("x rdf:type ja:Connection");
118:                assertEquals("bodacious", new ConnectionAssembler(init)
119:                        .getType(root));
120:            }
121:
122:            public void testFullySpecifiedConnection() {
123:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbUser 'test'; x ja:dbPassword ''; x ja:dbURL jdbc:mysql://localhost/test; x ja:dbType 'MySQL'");
124:                assertEquals("test", new ConnectionAssembler().getUser(root));
125:                assertEquals("", new ConnectionAssembler().getPassword(root));
126:                assertEquals("jdbc:mysql://localhost/test",
127:                        new ConnectionAssembler().getURL(root));
128:                assertEquals("MySQL", new ConnectionAssembler().getType(root));
129:            }
130:
131:            public void testTrapsNonStringObjects() {
132:                testTrapsNonStringObjects("ja:dbClass", "aResource");
133:                testTrapsNonStringObjects("ja:dbClass", "17");
134:                testTrapsNonStringObjects("ja:dbClass", "'tag'de");
135:                testTrapsNonStringObjects("ja:dbClassProperty", "aResource");
136:                testTrapsNonStringObjects("ja:dbClassProperty", "17");
137:                testTrapsNonStringObjects("ja:dbClassProperty", "'tag'de");
138:            }
139:
140:            private void testTrapsNonStringObjects(String property, String value) {
141:                Resource root = resourceInModel("x rdf:type ja:Connection; x <property> <value>"
142:                        .replaceAll("<property>", property).replaceAll(
143:                                "<value>", value));
144:                try {
145:                    new ConnectionAssembler().open(root);
146:                    fail("should trap bad object " + value + " for property "
147:                            + property);
148:                } catch (BadObjectException e) {
149:                    assertEquals(resource("x"), e.getRoot());
150:                    assertEquals(rdfNode(empty, value), e.getObject());
151:                }
152:            }
153:
154:            public void testOpenConnectionWIthLabels() {
155:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbUser 'X'; x ja:dbPassword 'P'; x ja:dbURL U:RL; x ja:dbType 'T'");
156:                final ConnectionDescription fake = ConnectionDescription
157:                        .create("eh:/x", "DD", "TT", "UU", "PP");
158:                CheckingConnectionAssembler x = new CheckingConnectionAssembler(
159:                        fake, "eh:/x U:RL X P T");
160:                assertSame(fake, x.open(root));
161:                assertTrue("mock createConnection should have been called",
162:                        x.called);
163:            }
164:
165:            public void testConnection() {
166:                Assembler a = new ConnectionAssembler();
167:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbUser 'test'; x ja:dbPassword ''; x ja:dbURL jdbc:mysql://localhost/test; x ja:dbType 'MySQL'");
168:                Object x = a.open(root);
169:                assertInstanceOf(ConnectionDescription.class, x);
170:                ConnectionDescription d = (ConnectionDescription) x;
171:                assertEquals("test", d.dbUser);
172:                assertEquals("", d.dbPassword);
173:                assertEquals("MySQL", d.dbType);
174:                assertEquals("jdbc:mysql://localhost/test", d.dbURL);
175:            }
176:
177:            public void testIndirectURLConnection() {
178:                System.setProperty("test.url", "bbb");
179:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbURLProperty 'test.url'");
180:                Assembler a = new ConnectionAssembler();
181:                ConnectionDescription d = (ConnectionDescription) a.open(root);
182:                assertEquals("bbb", d.dbURL);
183:            }
184:
185:            public void testIndirectUserConnection() {
186:                System.setProperty("test.user", "blenkinsop");
187:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbUserProperty 'test.user'");
188:                Assembler a = new ConnectionAssembler();
189:                ConnectionDescription d = (ConnectionDescription) a.open(root);
190:                assertEquals("blenkinsop", d.dbUser);
191:            }
192:
193:            public void testIndirectPasswordConnection() {
194:                System.setProperty("test.password", "Top/Secret");
195:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbPasswordProperty 'test.password'");
196:                Assembler a = new ConnectionAssembler();
197:                ConnectionDescription d = (ConnectionDescription) a.open(root);
198:                assertEquals("Top/Secret", d.dbPassword);
199:            }
200:
201:            public void testIndirectTypeConnection() {
202:                System.setProperty("test.type", "HisSQL");
203:                Resource root = resourceInModel("x rdf:type ja:Connection; x ja:dbTypeProperty 'test.type'");
204:                Assembler a = new ConnectionAssembler();
205:                ConnectionDescription d = (ConnectionDescription) a.open(root);
206:                assertEquals("HisSQL", d.dbType);
207:            }
208:
209:            private static final class CheckingConnectionAssembler extends
210:                    ConnectionAssembler {
211:                private final ConnectionDescription result;
212:                private final String expectSubject;
213:                private final String expectURL;
214:                private final String expectUser;
215:                private final String expectPassword;
216:                private final String expectType;
217:
218:                private boolean called;
219:
220:                private CheckingConnectionAssembler(
221:                        ConnectionDescription result, String expected) {
222:                    super ();
223:                    StringTokenizer st = new StringTokenizer(expected);
224:                    expectSubject = st.nextToken();
225:                    expectURL = st.nextToken();
226:                    expectUser = st.nextToken();
227:                    expectPassword = st.nextToken();
228:                    expectType = st.nextToken();
229:                    this .result = result;
230:                }
231:
232:                public ConnectionDescription createConnection(String subject,
233:                        String url, String type, String user, String pass) {
234:                    assertEquals(expectSubject, subject);
235:                    assertEquals(expectURL, url);
236:                    assertEquals(expectUser, user);
237:                    assertEquals(expectPassword, pass);
238:                    assertEquals(expectType, type);
239:                    called = true;
240:                    return result;
241:                }
242:            }
243:        }
244:
245:        /*
246:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
247:         * All rights reserved.
248:         *
249:         * Redistribution and use in source and binary forms, with or without
250:         * modification, are permitted provided that the following conditions
251:         * are met:
252:         * 1. Redistributions of source code must retain the above copyright
253:         *    notice, this list of conditions and the following disclaimer.
254:         * 2. Redistributions in binary form must reproduce the above copyright
255:         *    notice, this list of conditions and the following disclaimer in the
256:         *    documentation and/or other materials provided with the distribution.
257:         * 3. The name of the author may not be used to endorse or promote products
258:         *    derived from this software without specific prior written permission.
259:         *
260:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
261:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
262:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
263:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
264:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
265:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
266:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
267:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
269:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.