Source Code Cross Referenced for TestContentAssembler.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: TestContentAssembler.java,v 1.12 2008/01/02 12:05:57 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.assembler.test;
008:
009:        import com.hp.hpl.jena.assembler.*;
010:        import com.hp.hpl.jena.assembler.assemblers.ContentAssembler;
011:        import com.hp.hpl.jena.assembler.exceptions.UnknownEncodingException;
012:        import com.hp.hpl.jena.rdf.model.*;
013:        import com.hp.hpl.jena.util.*;
014:
015:        public class TestContentAssembler extends AssemblerTestBase {
016:            protected static String Testing = "testing/assemblers";
017:
018:            public TestContentAssembler(String name) {
019:                super (name);
020:            }
021:
022:            protected Class getAssemblerClass() {
023:                return ContentAssembler.class;
024:            }
025:
026:            public void testContentAssemblerType() {
027:                testDemandsMinimalType(new ContentAssembler(), JA.Content);
028:            }
029:
030:            public void testContentVocabulary() {
031:                assertSubclassOf(JA.Content, JA.HasFileManager);
032:                assertSubclassOf(JA.ContentItem, JA.Content);
033:                // assertSubclassOf( JA.LiteralContent, JA.Content );
034:            }
035:
036:            public void testContent() {
037:                Assembler a = new ContentAssembler();
038:                Content c = (Content) a
039:                        .open(resourceInModel("x rdf:type ja:Content"));
040:                assertNotNull(c);
041:                Model m = ModelFactory.createDefaultModel();
042:                c.fill(m);
043:                assertEquals(0, m.size());
044:            }
045:
046:            public void testMultipleLiteralsWorks() {
047:                Assembler a = new ContentAssembler();
048:                String A = "<eh:/A> a <eh:/Type>.".replaceAll(" ", "\\\\s");
049:                String B = "<eh:/Type> a rdfs:Class.".replaceAll(" ", "\\\\s");
050:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:LiteralContent; x ja:literalContent '"
051:                        + A + "'; x ja:literalContent '" + B + "'");
052:                Content C = (Content) a.open(root);
053:                assertIsoModels(
054:                        model("Type rdf:type rdfs:Class; A rdf:type Type"), C
055:                                .fill(model("")));
056:            }
057:
058:            public void testN3StringContentSingleTriples() {
059:                testStringContent("_x rdf:value '17'xsd:integer",
060:                        "_:x rdf:value 17 .");
061:                testStringContent("_x rdf:value '42'xsd:integer",
062:                        "_:x rdf:value 42 .");
063:                testStringContent("_x rdfs:label 'cosmetic'",
064:                        "_:x rdfs:label 'cosmetic' .");
065:                testStringContent("_x owl:sameAs spoo",
066:                        "_:x owl:sameAs <eh:/spoo> .");
067:                testStringContent("_x rdf:value '17'xsd:something",
068:                        "_:x rdf:value '17'^^xsd:something .");
069:                testStringContent("_x dc:title 'A\\sTitle'",
070:                        "_:x dc:title 'A Title' .");
071:            }
072:
073:            public void testN3StringContentMultipleTriples() {
074:                testStringContent("x rdf:value 5; y owl:sameAs x",
075:                        "<eh:/x> rdf:value 5 . <eh:/y> owl:sameAs <eh:/x> .");
076:            }
077:
078:            public void testRDFXMLContent() {
079:                Assembler a = new ContentAssembler();
080:                String Stuff = "<owl:Class></owl:Class>".replaceAll(" ",
081:                        "\\\\s");
082:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:LiteralContent; x ja:literalContent '"
083:                        + Stuff + "'; x ja:contentEncoding 'RDF/XML'");
084:                Content c = (Content) a.open(root);
085:                assertIsoModels(model("_x rdf:type owl:Class"), c
086:                        .fill(model("")));
087:            }
088:
089:            public void testSingleExternalContent() {
090:                Assembler a = new ContentAssembler();
091:                String source = Testing + "/schema.n3";
092:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:ExternalContent; x ja:externalContent file:"
093:                        + source);
094:                Content c = (Content) a.open(root);
095:                assertIsoModels(FileManager.get().loadModel("file:" + source),
096:                        c.fill(model("")));
097:            }
098:
099:            public void testMultipleExternalContent() {
100:                Assembler a = new ContentAssembler();
101:                String sourceA = Testing + "/schema.n3";
102:                String sourceB = Testing + "/schema2.n3";
103:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:ExternalContent"
104:                        + "; x ja:externalContent file:"
105:                        + sourceA
106:                        + "; x ja:externalContent file:" + sourceB);
107:                Content c = (Content) a.open(root);
108:                Model wanted = FileManager.get().loadModel("file:" + sourceA)
109:                        .add(FileManager.get().loadModel("file:" + sourceB));
110:                assertIsoModels(wanted, c.fill(model("")));
111:            }
112:
113:            public void testIndirectContent() {
114:                Assembler a = new ContentAssembler();
115:                Resource root = resourceInModel("x rdf:type ja:Content; x ja:content y"
116:                        + "; y rdf:type ja:Content; y ja:content z"
117:                        + "; z rdf:type ja:Content; z ja:quotedContent A; A P B");
118:                Content c = (Content) a.open(root);
119:                Model wanted = model("A P B");
120:                assertIsoModels(wanted, c.fill(model("")));
121:            }
122:
123:            public void testTrapsBadEncodings() {
124:                Assembler a = new ContentAssembler();
125:                Resource root = resourceInModel("x rdf:type ja:Content; x ja:contentEncoding 'bogus'; x ja:literalContent 'sham'");
126:                try {
127:                    a.open(root);
128:                    fail("should trap bad encoding");
129:                } catch (UnknownEncodingException e) {
130:                    assertEquals("bogus", e.getEncoding());
131:                    assertEquals(resource("x"), e.getRoot());
132:                }
133:            }
134:
135:            public void testContentTrapsBadObjects() {
136:                testContentTrapsBadObjects("ja:content", "17");
137:                // testContentTrapsBadObjects( "ja:externalContent", "17" );
138:                testContentTrapsBadObjects("ja:quotedContent", "17");
139:                testContentTrapsBadObjects("ja:literalContent", "aResource");
140:                testContentTrapsBadObjects("ja:literalContent", "17");
141:                testContentTrapsBadObjects("ja:literalContent", "'plume'fr");
142:            }
143:
144:            private void testContentTrapsBadObjects(String property,
145:                    String value) {
146:                Assembler a = new ContentAssembler();
147:                Resource root = resourceInModel("x rdf:type ja:Content; x <property> <value>"
148:                        .replaceAll("<property>", property).replaceAll(
149:                                "<value>", value));
150:                try {
151:                    a.open(root);
152:                    fail("should trap bad content resource");
153:                } catch (BadObjectException e) {
154:                    assertEquals(resource("x"), e.getRoot());
155:                    assertEquals(rdfNode(empty, value), e.getObject());
156:                }
157:            }
158:
159:            public void testMixedContent() {
160:                Assembler a = new ContentAssembler();
161:                String source = Testing + "/schema.n3";
162:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:LiteralContent; x rdf:type ja:ExternalContent"
163:                        + "; x ja:literalContent '<eh:/eggs>\\srdf:type\\srdf:Property.'"
164:                        + "; x ja:externalContent file:" + source);
165:                Content c = (Content) a.open(root);
166:                Model wanted = FileManager.get().loadModel("file:" + source)
167:                        .add(model("eggs rdf:type rdf:Property"));
168:                assertIsoModels(wanted, c.fill(model("")));
169:            }
170:
171:            public void testSingleContentQuotation() {
172:                Assembler a = new ContentAssembler();
173:                Resource root = resourceInModel("c rdf:type ja:Content; c rdf:type ja:QuotedContent; c ja:quotedContent x; x P A; x Q B");
174:                Content c = (Content) a.open(root);
175:                assertIsoModels(model("x P A; x Q B"), c.fill(model("")));
176:            }
177:
178:            public void testMultipleContentQuotation() {
179:                Assembler a = new ContentAssembler();
180:                Resource root = resourceInModel("c rdf:type ja:Content; c rdf:type ja:QuotedContent; c ja:quotedContent x"
181:                        + "; c ja:quotedContent y; x P A; x Q B; y R C");
182:                Content c = (Content) a.open(root);
183:                assertIsoModels(model("x P A; x Q B; y R C"), c.fill(model("")));
184:            }
185:
186:            public void testContentLoadsPrefixMappings() {
187:                Assembler a = new ContentAssembler();
188:                String content = "@prefix foo: <eh:/foo#>. <eh:/eggs> rdf:type rdf:Property."
189:                        .replaceAll(" ", "\\\\s");
190:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:LiteralContent; x ja:literalContent '"
191:                        + content + "'");
192:                Content c = (Content) a.open(root);
193:                Model m = ModelFactory.createDefaultModel();
194:                c.fill(m);
195:                assertEquals("eh:/foo#", m.getNsPrefixURI("foo"));
196:            }
197:
198:            protected void testStringContent(String expected, String n3) {
199:                Assembler a = new ContentAssembler();
200:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:LiteralContent; x ja:literalContent '"
201:                        + n3.replaceAll(" ", "\\\\s") + "'");
202:                Content c = (Content) a.open(root);
203:                Model m = ModelFactory.createDefaultModel();
204:                c.fill(m);
205:                assertIsoModels(model(expected), m);
206:            }
207:
208:            /*
209:                -- ContentAssembler FileManager tests ----------------------------------
210:             */
211:
212:            public void testContentAssemblerHasNoDefaultFileManager() {
213:                assertNull("by default, ContentAssemblers have no FileManager",
214:                        new ContentAssembler().getFileManager());
215:            }
216:
217:            public void testContentAssemblerHasSuppliedFileManager() {
218:                FileManager fm = new FileManager();
219:                assertSame(fm, new ContentAssembler(fm).getFileManager());
220:            }
221:
222:            public void testUsesSuppliedFileManager() {
223:                final boolean[] used = { false };
224:                FileManager fm = new FileManager() {
225:                    public Model loadModel(String filenameOrURI) {
226:                        used[0] = true;
227:                        return FileManager.get().loadModel(filenameOrURI);
228:                    }
229:                };
230:                Assembler a = new ContentAssembler(fm);
231:                String source = Testing + "/schema.n3";
232:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:ExternalContent; x ja:externalContent file:"
233:                        + source);
234:                Content c = (Content) a.open(root);
235:                assertIsoModels(FileManager.get().loadModel("file:" + source),
236:                        c.fill(model("")));
237:                assertTrue("the supplied file manager must have been used",
238:                        used[0]);
239:            }
240:
241:            public void testContentAssemblerUsesFileManagerProperty() {
242:                Model expected = model("a P b");
243:                String fileName = "file:spoo";
244:                FixedFileManager fm = new FixedFileManager(expected, fileName);
245:                NamedObjectAssembler noa = new NamedObjectAssembler(
246:                        resource("F"), fm);
247:                Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:ExternalContent; x ja:externalContent <F>; x ja:fileManager F"
248:                        .replaceAll("<F>", fileName));
249:                Assembler a = new ContentAssembler();
250:                Content c = (Content) a.open(noa, root);
251:                assertTrue(fm.wasUsed());
252:                assertIsoModels(expected, c.fill(model()));
253:            }
254:
255:            private final class FixedFileManager extends FileManager {
256:                private final Model expected;
257:                private final String fileName;
258:                private boolean used;
259:
260:                private FixedFileManager(Model expected, String fileName) {
261:                    this .expected = expected;
262:                    this .fileName = fileName;
263:                }
264:
265:                public Model loadModel(String filenameOrURI) {
266:                    used = true;
267:                    assertEquals(fileName, filenameOrURI);
268:                    return expected;
269:                }
270:
271:                public boolean wasUsed() {
272:                    return used;
273:                }
274:            }
275:
276:        }
277:
278:        /*
279:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
280:         * All rights reserved.
281:         *
282:         * Redistribution and use in source and binary forms, with or without
283:         * modification, are permitted provided that the following conditions
284:         * are met:
285:         * 1. Redistributions of source code must retain the above copyright
286:         *    notice, this list of conditions and the following disclaimer.
287:         * 2. Redistributions in binary form must reproduce the above copyright
288:         *    notice, this list of conditions and the following disclaimer in the
289:         *    documentation and/or other materials provided with the distribution.
290:         * 3. The name of the author may not be used to endorse or promote products
291:         *    derived from this software without specific prior written permission.
292:         *
293:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
294:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
295:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
296:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
297:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
298:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
299:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
300:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
301:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
302:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.