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


001:        /*
002:          (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:          [See end of file]
004:          $Id: TestNsPrefix.java,v 1.12 2008/01/02 12:08:14 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.db.test;
008:
009:        /**
010:         * 
011:         * This tests basic open/create operations on the modelRDB.
012:         * 
013:         * To run, you must have a mySQL database operational on
014:         * localhost with a database name of "test" and allow use
015:         * by a user named "test" with an empty password.
016:         * 
017:         * (based in part on model tests written earlier by bwm and kers)
018:         * 
019:         * @author csayers
020:         * @version 0.1
021:         */
022:
023:        import com.hp.hpl.jena.db.*;
024:        import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
025:        import com.hp.hpl.jena.shared.PrefixMapping;
026:        import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
027:        import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping;
028:
029:        import junit.framework.*;
030:
031:        public class TestNsPrefix extends ModelTestBase {
032:
033:            public TestNsPrefix(String name) {
034:                super (name);
035:            }
036:
037:            public static TestSuite suite() {
038:                return new TestSuite(TestNsPrefix.class);
039:            }
040:
041:            protected void setUp() throws java.lang.Exception {
042:            }
043:
044:            protected void tearDown() throws java.lang.Exception {
045:            }
046:
047:            protected PrefixMapping getMapping() {
048:                IDBConnection conn = TestConnection
049:                        .makeAndCleanTestConnection();
050:                return ModelRDB.createModel(conn);
051:            }
052:
053:            public void testSinglePrefix() throws java.lang.Exception {
054:                String testPrefix = "testPrefix";
055:                String testURI = "http://someTestURI#";
056:                IDBConnection conn = TestConnection
057:                        .makeAndCleanTestConnection();
058:                ModelRDB m = ModelRDB.createModel(conn);
059:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
060:                m.setNsPrefix(testPrefix, testURI);
061:                assertEquals(1, m.getNsPrefixMap().size());
062:                assertEquals(testURI, m.getNsPrefixURI(testPrefix));
063:                m.close();
064:                conn.close();
065:            }
066:
067:            public void testDuplicatePrefix() throws java.lang.Exception {
068:                String testPrefix = "testPrefix";
069:                String testURI = "http://someTestURI#";
070:                IDBConnection conn = TestConnection
071:                        .makeAndCleanTestConnection();
072:                ModelRDB m = ModelRDB.createModel(conn);
073:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
074:                m.setNsPrefix(testPrefix, testURI);
075:                m.setNsPrefix(testPrefix, testURI);
076:                assertEquals(1, m.getNsPrefixMap().size());
077:                assertEquals(testURI, m.getNsPrefixURI(testPrefix));
078:                m.close();
079:                conn.close();
080:            }
081:
082:            public void testChangingPrefixMapping() throws java.lang.Exception {
083:                String testPrefix = "testPrefix";
084:                String testURI = "http://someTestURI#";
085:                String someOtherTestURI = "http://someOtherTestURI#";
086:                IDBConnection conn = TestConnection
087:                        .makeAndCleanTestConnection();
088:                ModelRDB m = ModelRDB.createModel(conn);
089:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
090:                m.setNsPrefix(testPrefix, testURI);
091:                m.setNsPrefix(testPrefix, someOtherTestURI);
092:                assertEquals(1, m.getNsPrefixMap().size());
093:                assertDiffer(testURI, m.getNsPrefixURI(testPrefix));
094:                assertEquals(someOtherTestURI, m.getNsPrefixURI(testPrefix));
095:                m.close();
096:                conn.close();
097:            }
098:
099:            public void testPersistenceOfPrefixes() throws java.lang.Exception {
100:                String testPrefix = "testPrefix";
101:                String testURI = "http://someTestURI#";
102:                IDBConnection conn = TestConnection
103:                        .makeAndCleanTestConnection();
104:                ModelRDB m = ModelRDB.createModel(conn);
105:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
106:                m.setNsPrefix(testPrefix, testURI);
107:                assertEquals(1, m.getNsPrefixMap().size());
108:                assertEquals(testURI, m.getNsPrefixURI(testPrefix));
109:                m.close();
110:
111:                // Now create a different model and check there is no prefix
112:                // and that removing it has no effect on the first model.
113:                ModelRDB m2 = ModelRDB.createModel(conn, "myName");
114:                assertEquals(0, m2.getNsPrefixMap().size());
115:                m2.remove();
116:                m2.close();
117:
118:                // Now reopen the first Model and check the prefix was persisted
119:                ModelRDB m3 = ModelRDB.open(conn);
120:                assertEquals(1, m3.getNsPrefixMap().size());
121:                assertEquals(testURI, m3.getNsPrefixURI(testPrefix));
122:                m3.close();
123:
124:                conn.close();
125:            }
126:
127:            public void testIdependenceOfPrefixes() throws java.lang.Exception {
128:                String testPrefix1 = "testPrefix1";
129:                String testURI1 = "http://someTestURI1#";
130:                String testPrefix2 = "testPrefix2";
131:                String testURI2 = "http://someTestURI2#";
132:                String testPrefix3 = "testPrefix3";
133:                String testURI3 = "http://someTestURI3#";
134:                IDBConnection conn = TestConnection
135:                        .makeAndCleanTestConnection();
136:
137:                // Create a first model with a set of prefixes
138:                ModelRDB m = ModelRDB.createModel(conn);
139:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
140:                m.setNsPrefix(testPrefix1, testURI1);
141:                m.setNsPrefix(testPrefix2, testURI2);
142:                assertEquals(2, m.getNsPrefixMap().size());
143:                assertEquals(testURI1, m.getNsPrefixURI(testPrefix1));
144:                assertEquals(testURI2, m.getNsPrefixURI(testPrefix2));
145:
146:                // Create a second model with an overlapping set of prefixes
147:                ModelRDB m2 = ModelRDB.createModel(conn, "secondGraph");
148:                assertEquals(0, m2.getNsPrefixMap().size()); // brand new model should have no prefixes
149:                m2.setNsPrefix(testPrefix2, testURI2);
150:                m2.setNsPrefix(testPrefix3, testURI3);
151:
152:                // Verify second model has the correct contents
153:                assertEquals(2, m2.getNsPrefixMap().size());
154:                assertEquals(testURI2, m2.getNsPrefixURI(testPrefix2));
155:                assertEquals(testURI3, m2.getNsPrefixURI(testPrefix3));
156:
157:                // Verify that first model was unchanged.
158:                assertEquals(2, m.getNsPrefixMap().size());
159:                assertEquals(testURI1, m.getNsPrefixURI(testPrefix1));
160:                assertEquals(testURI2, m.getNsPrefixURI(testPrefix2));
161:
162:                // Now remove the second model
163:                m2.remove();
164:                m2.close();
165:                m2 = null;
166:
167:                // Verify that first model was still unchanged.
168:                assertEquals(2, m.getNsPrefixMap().size());
169:                assertEquals(testURI1, m.getNsPrefixURI(testPrefix1));
170:                assertEquals(testURI2, m.getNsPrefixURI(testPrefix2));
171:
172:                // Now close and reopen the first Model and check the prefix was persisted
173:                m.close();
174:                m = null;
175:
176:                ModelRDB m3 = ModelRDB.open(conn);
177:                assertEquals(2, m3.getNsPrefixMap().size());
178:                assertEquals(testURI1, m3.getNsPrefixURI(testPrefix1));
179:                assertEquals(testURI2, m3.getNsPrefixURI(testPrefix2));
180:                m3.close();
181:
182:                conn.close();
183:            }
184:
185:            public void testPersistedChangedPrefixes()
186:                    throws java.lang.Exception {
187:                String testPrefix1 = "testPrefix1";
188:                String testURI1 = "http://someTestURI/1#";
189:                String testURI1b = "http://someTestURI/1b#";
190:                String testPrefix2 = "testPrefix2";
191:                String testURI2 = "http://someTestURI/2#";
192:                String testPrefix3 = "testPrefix3";
193:                String testURI3 = "http://someTestURI/3#";
194:                IDBConnection conn = TestConnection
195:                        .makeAndCleanTestConnection();
196:
197:                ModelRDB m = ModelRDB.createModel(conn);
198:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
199:                m.setNsPrefix(testPrefix1, testURI1);
200:                m.setNsPrefix(testPrefix2, testURI2);
201:                assertEquals(2, m.getNsPrefixMap().size());
202:                assertEquals(testURI1, m.getNsPrefixURI(testPrefix1));
203:                assertEquals(testURI2, m.getNsPrefixURI(testPrefix2));
204:                m.close();
205:                m = null;
206:
207:                // Now reopen the first Model and check the prefixes were persisted
208:                ModelRDB m2 = ModelRDB.open(conn);
209:                assertEquals(2, m2.getNsPrefixMap().size());
210:                assertEquals(testURI1, m2.getNsPrefixURI(testPrefix1));
211:                assertEquals(testURI2, m2.getNsPrefixURI(testPrefix2));
212:
213:                // Now change one prefix and add a third
214:                m2.setNsPrefix(testPrefix1, testURI1b);
215:                m2.setNsPrefix(testPrefix3, testURI3);
216:
217:                assertEquals(3, m2.getNsPrefixMap().size());
218:                assertEquals(testURI1b, m2.getNsPrefixURI(testPrefix1));
219:                assertEquals(testURI2, m2.getNsPrefixURI(testPrefix2));
220:                assertEquals(testURI3, m2.getNsPrefixURI(testPrefix3));
221:
222:                m2.close();
223:                m2 = null;
224:
225:                // Now reopen again and check it's all still as expected.
226:                ModelRDB m3 = ModelRDB.open(conn);
227:                assertEquals(3, m3.getNsPrefixMap().size());
228:                assertEquals(testURI1b, m3.getNsPrefixURI(testPrefix1));
229:                assertEquals(testURI2, m3.getNsPrefixURI(testPrefix2));
230:                assertEquals(testURI3, m3.getNsPrefixURI(testPrefix3));
231:
232:                m3.close();
233:                conn.close();
234:            }
235:
236:            public void testCopyPersistentPrefixMapping()
237:                    throws java.lang.Exception {
238:                String testPrefix1 = "testPrefix1";
239:                String testPrefix2 = "testPrefix2";
240:                String testURI1 = "http://someTestURI/1#";
241:                String testURI2 = "http://someTestURI/2#";
242:                IDBConnection conn = TestConnection
243:                        .makeAndCleanTestConnection();
244:                ModelRDB m = ModelRDB.createModel(conn);
245:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
246:                m.setNsPrefix(testPrefix1, testURI1);
247:                m.setNsPrefix(testPrefix2, testURI2);
248:                assertEquals(2, m.getNsPrefixMap().size());
249:                assertEquals(testURI1, m.getNsPrefixURI(testPrefix1));
250:                assertEquals(testURI2, m.getNsPrefixURI(testPrefix2));
251:
252:                // Now create a second model, copy the prefix mapping and make sure it matches
253:                ModelRDB m2 = ModelRDB.createModel(conn, "secondModel");
254:                assertEquals(0, m2.getNsPrefixMap().size());
255:                m2.setNsPrefixes(m.getNsPrefixMap());
256:                assertEquals(2, m2.getNsPrefixMap().size());
257:                assertEquals(testURI1, m2.getNsPrefixURI(testPrefix1));
258:                assertEquals(testURI2, m2.getNsPrefixURI(testPrefix2));
259:
260:                m.close();
261:                m2.close();
262:
263:                conn.close();
264:            }
265:
266:            public void testCopyMemoryPrefixMapping()
267:                    throws java.lang.Exception {
268:                String testPrefix1 = "testPrefix1";
269:                String testPrefix2 = "testPrefix2";
270:                String testURI1 = "http://someTestURI/1#";
271:                String testURI2 = "http://someTestURI/2#";
272:
273:                PrefixMapping myMap = new PrefixMappingImpl();
274:                myMap.setNsPrefix(testPrefix1, testURI1);
275:                myMap.setNsPrefix(testPrefix2, testURI2);
276:
277:                assertEquals(2, myMap.getNsPrefixMap().size());
278:                assertEquals(testURI1, myMap.getNsPrefixURI(testPrefix1));
279:                assertEquals(testURI2, myMap.getNsPrefixURI(testPrefix2));
280:
281:                IDBConnection conn = TestConnection
282:                        .makeAndCleanTestConnection();
283:                ModelRDB m = ModelRDB.createModel(conn);
284:                assertEquals(0, m.getNsPrefixMap().size()); // brand new model should have no prefixes
285:                m.setNsPrefixes(myMap);
286:                assertEquals(2, m.getNsPrefixMap().size());
287:                assertEquals(testURI1, m.getNsPrefixURI(testPrefix1));
288:                assertEquals(testURI2, m.getNsPrefixURI(testPrefix2));
289:
290:                m.close();
291:                conn.close();
292:            }
293:
294:            public void testSecondPrefixDoesNotRemoveSharedURI()
295:                    throws Exception {
296:                IDBConnection conn = TestConnection
297:                        .makeAndCleanTestConnection();
298:                ModelRDB m = ModelRDB.createModel(conn);
299:                String someURI = "urn:x-hp:db-unit-testing:xxx";
300:                m.setNsPrefix("p1", someURI);
301:                m.setNsPrefix("p2", someURI);
302:                m.close();
303:                conn.close();
304:                IDBConnection conn2 = TestConnection.makeTestConnection();
305:                ModelRDB m2 = ModelRDB.open(conn2);
306:                assertEquals(someURI, m2.getNsPrefixURI("p1"));
307:                assertEquals(someURI, m2.getNsPrefixURI("p2"));
308:                m2.close();
309:                conn2.close();
310:            }
311:
312:        }
313:
314:        /*
315:         (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
316:         All rights reserved.
317:
318:         Redistribution and use in source and binary forms, with or without
319:         modification, are permitted provided that the following conditions
320:         are met:
321:
322:         1. Redistributions of source code must retain the above copyright
323:         notice, this list of conditions and the following disclaimer.
324:
325:         2. Redistributions in binary form must reproduce the above copyright
326:         notice, this list of conditions and the following disclaimer in the
327:         documentation and/or other materials provided with the distribution.
328:
329:         3. The name of the author may not be used to endorse or promote products
330:         derived from this software without specific prior written permission.
331:
332:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
333:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
334:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
335:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
336:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
337:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
338:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
339:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
340:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
341:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
342:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.