Source Code Cross Referenced for AssemblerTestBase.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: AssemblerTestBase.java,v 1.11 2008/01/03 15:18:54 chris-dollin 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.AssemblerBase;
011:        import com.hp.hpl.jena.assembler.exceptions.CannotConstructException;
012:        import com.hp.hpl.jena.rdf.model.*;
013:        import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
014:        import com.hp.hpl.jena.shared.*;
015:        import com.hp.hpl.jena.vocabulary.*;
016:
017:        /**
018:         A convenient base class for Assembler tests. The instance methods
019:         <code>modelAddFacts</code> and <code>setRequiredPrefixes</code>
020:         may be over-ridden in subclasses to control the parser that is used to
021:         construct models and the prefixes added to the model (these features
022:         added for Eyeball).
023:        
024:         @author kers
025:         */
026:        public abstract class AssemblerTestBase extends ModelTestBase {
027:            protected Class getAssemblerClass() {
028:                throw new BrokenException(
029:                        "this class must define getAssemblerClass");
030:            }
031:
032:            /**
033:                 An assembler that always returns the same fixed object.
034:                @author kers
035:             */
036:            protected static final class FixedObjectAssembler extends
037:                    AssemblerBase {
038:                private final Object x;
039:
040:                protected FixedObjectAssembler(Object x) {
041:                    this .x = x;
042:                }
043:
044:                public Object open(Assembler a, Resource root, Mode irrelevant) {
045:                    return x;
046:                }
047:            }
048:
049:            /**
050:                An assembler that insists on being called on a given name, and always
051:                returns the same fixed object.
052:                @author kers
053:             */
054:            protected static class NamedObjectAssembler extends AssemblerBase {
055:                final Resource name;
056:                final Object result;
057:
058:                public NamedObjectAssembler(Resource name, Object result) {
059:                    this .name = name;
060:                    this .result = result;
061:                }
062:
063:                public Model openModel(Resource root, Mode mode) {
064:                    return (Model) open(this , root, mode);
065:                }
066:
067:                public Object open(Assembler a, Resource root, Mode irrelevant) {
068:                    assertEquals(name, root);
069:                    return result;
070:                }
071:            }
072:
073:            protected static final Model schema = JA.getSchema();
074:
075:            public AssemblerTestBase(String name) {
076:                super (name);
077:            }
078:
079:            protected Model model(String string) {
080:                Model result = createModel(ReificationStyle.Standard);
081:                setRequiredPrefixes(result);
082:                return modelAddFacts(result, string);
083:            }
084:
085:            protected Model model() {
086:                return model("");
087:            }
088:
089:            /**
090:             	Subclasses may override to use their choice of string-to-model
091:                parsers.
092:             */
093:            protected Model modelAddFacts(Model result, String string) {
094:                return modelAdd(result, string);
095:            }
096:
097:            /**
098:                Subclasses may extend to get their choice of defined prefixes.
099:             */
100:            protected Model setRequiredPrefixes(Model m) {
101:                m.setNsPrefix("ja", JA.getURI());
102:                m.setNsPrefix("lm", LocationMappingVocab.getURI());
103:                return m;
104:            }
105:
106:            protected Resource resourceInModel(String string) {
107:                Model m = model(string);
108:                Resource r = resource(string.substring(0, string.indexOf(' ')));
109:                return (Resource) r.inModel(m);
110:            }
111:
112:            protected void testDemandsMinimalType(Assembler a, Resource type) {
113:                try {
114:                    a.open(resourceInModel("x rdf:type rdf:Resource"));
115:                    fail("should trap insufficient type");
116:                } catch (CannotConstructException e) {
117:                    assertEquals(getAssemblerClass(), e.getAssemblerClass());
118:                    assertEquals(type, e.getType());
119:                    assertEquals(resource("x"), e.getRoot());
120:                }
121:            }
122:
123:            protected void assertSamePrefixMapping(PrefixMapping wanted,
124:                    PrefixMapping got) {
125:                if (!wanted.samePrefixMappingAs(got))
126:                    fail("wanted: " + wanted + " but got: " + got);
127:            }
128:
129:            /**
130:                 assert that the property <code>p</code> has <code>domain</code> as
131:                 its rdfs:domain.
132:             */
133:            protected void assertDomain(Resource domain, Property p) {
134:                if (!schema.contains(p, RDFS.domain, domain))
135:                    fail(p + " was expected to have domain " + domain);
136:            }
137:
138:            /**
139:                 assert that the property <code>p</code> has <code>range</code> as
140:                 its rdfs:range.
141:             */
142:            protected void assertRange(Resource range, Property p) {
143:                if (!schema.contains(p, RDFS.range, range))
144:                    fail(p + " was expected to have range " + range);
145:            }
146:
147:            /**
148:                 assert that <code>expectedSub</code> is an rdfs:subClassOf
149:                 <code>expectedSuper</code>.
150:             */
151:            protected void assertSubclassOf(Resource expectedSub,
152:                    Resource expectedSuper) {
153:                if (!schema.contains(expectedSub, RDFS.subClassOf,
154:                        expectedSuper))
155:                    fail(expectedSub + " should be a subclass of "
156:                            + expectedSuper);
157:            }
158:
159:            /**
160:                 assert that <code>instance</code> has rdf:type <code>type</code>.
161:             */
162:            protected void assertType(Resource type, Resource instance) {
163:                if (!schema.contains(instance, RDF.type, type))
164:                    fail(instance + " should have rdf:type " + type);
165:            }
166:        }
167:
168:        /*
169:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
170:         * All rights reserved.
171:         *
172:         * Redistribution and use in source and binary forms, with or without
173:         * modification, are permitted provided that the following conditions
174:         * are met:
175:         * 1. Redistributions of source code must retain the above copyright
176:         *    notice, this list of conditions and the following disclaimer.
177:         * 2. Redistributions in binary form must reproduce the above copyright
178:         *    notice, this list of conditions and the following disclaimer in the
179:         *    documentation and/or other materials provided with the distribution.
180:         * 3. The name of the author may not be used to endorse or promote products
181:         *    derived from this software without specific prior written permission.
182:         *
183:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
184:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
185:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
186:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
187:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
188:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
189:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
190:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
191:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
192:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
193:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.