Source Code Cross Referenced for TestAssemblerGroup.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: TestAssemblerGroup.java,v 1.12 2008/01/02 12:05:56 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.*;
011:        import com.hp.hpl.jena.assembler.assemblers.AssemblerGroup.ExpandingAssemblerGroup;
012:        import com.hp.hpl.jena.assembler.exceptions.*;
013:        import com.hp.hpl.jena.graph.Graph;
014:        import com.hp.hpl.jena.mem.GraphMemBase;
015:        import com.hp.hpl.jena.rdf.model.*;
016:        import com.hp.hpl.jena.vocabulary.RDFS;
017:
018:        public class TestAssemblerGroup extends AssemblerTestBase {
019:            public TestAssemblerGroup(String name) {
020:                super (name);
021:            }
022:
023:            protected Class getAssemblerClass() {
024:                return AssemblerGroup.class;
025:            }
026:
027:            public void testEmptyAssemblerGroup() {
028:                AssemblerGroup a = AssemblerGroup.create();
029:                assertInstanceOf(AssemblerGroup.class, a);
030:                assertEquals(null, a.assemblerFor(resource("ja:Anything")));
031:                checkFailsType(a, "rdf:Resource");
032:            }
033:
034:            protected void checkFailsType(Assembler a, String type) {
035:                try {
036:                    a.open(resourceInModel("x rdf:type " + type));
037:                    fail("should trap missing implementation");
038:                } catch (NoSpecificTypeException e) {
039:                    assertEquals(resource("x"), e.getRoot());
040:                }
041:                //        catch (NoImplementationException e) 
042:                //            { 
043:                //            assertEquals( resource( "x" ), e.getRoot() ); 
044:                //            assertEquals( JA.Object, e.getType() );
045:                //            assertNotNull( e.getAssembler() );
046:                //            }
047:            }
048:
049:            public static boolean loaded = false;
050:
051:            public static class Trivial {
052:                static {
053:                    loaded = true;
054:                }
055:            }
056:
057:            public void testLoadsClasses() {
058:                AssemblerGroup a = AssemblerGroup.create();
059:                a.implementWith(resource("T"), new MockAssembler());
060:                Resource root = resourceInModel("x rdf:type T; _c ja:loadClass '"
061:                        + TestAssemblerGroup.class.getName() + "$Trivial'");
062:                assertFalse(
063:                        "something has pre-loaded Trivial, so we can't test if it gets loaded",
064:                        loaded);
065:                assertEquals("mockmockmock", a.open(root));
066:                assertTrue(
067:                        "the assembler group did not obey the ja:loadClass directive",
068:                        loaded);
069:            }
070:
071:            static class MockAssembler extends AssemblerBase {
072:                public Object open(Assembler a, Resource root, Mode mode) {
073:                    return "mockmockmock";
074:                }
075:            }
076:
077:            public void testSingletonAssemblerGroup() {
078:                AssemblerGroup a = AssemblerGroup.create();
079:                assertSame(a, a.implementWith(JA.InfModel, Assembler.infModel));
080:                a.openModel(resourceInModel("x rdf:type ja:InfModel"));
081:                checkFailsType(a, "js:DefaultModel");
082:            }
083:
084:            public void testMultipleAssemblerGroup() {
085:                AssemblerGroup a = AssemblerGroup.create();
086:                assertSame(a, a.implementWith(JA.InfModel, Assembler.infModel));
087:                assertSame(a, a.implementWith(JA.MemoryModel,
088:                        Assembler.memoryModel));
089:                assertInstanceOf(InfModel.class, a
090:                        .openModel(resourceInModel("x rdf:type ja:InfModel")));
091:                assertFalse(a
092:                        .openModel(resourceInModel("y rdf:type ja:MemoryModel")) instanceof  InfModel);
093:                checkFailsType(a, "js:DefaultModel");
094:            }
095:
096:            public void testImpliedType() {
097:                AssemblerGroup a = AssemblerGroup.create();
098:                Resource root = resourceInModel("x ja:reasoner y");
099:                Object expected = new Object();
100:                a.implementWith(JA.InfModel, new NamedObjectAssembler(
101:                        resource("x"), expected));
102:                assertSame(expected, a.open(root));
103:            }
104:
105:            public void testBuiltinGroup() {
106:                AssemblerGroup g = Assembler.general;
107:                assertInstanceOf(Model.class, g
108:                        .open(resourceInModel("x rdf:type ja:DefaultModel")));
109:                assertInstanceOf(InfModel.class, g
110:                        .open(resourceInModel("x rdf:type ja:InfModel")));
111:                assertMemoryModel(g
112:                        .open(resourceInModel("x rdf:type ja:MemoryModel")));
113:            }
114:
115:            private static Assembler mockAssembler = new AssemblerBase() {
116:                public Object open(Assembler a, Resource root, Mode mode) {
117:                    return null;
118:                }
119:            };
120:
121:            public void testAddingImplAddsSubclass() {
122:                final Model[] fullModel = new Model[1];
123:                AssemblerGroup g = new AssemblerGroup.ExpandingAssemblerGroup() {
124:                    public void loadClasses(Model full) {
125:                        fullModel[0] = full;
126:                    }
127:                };
128:                Resource root = resourceInModel("root rdf:type typeA");
129:                Resource typeA = resource("typeA"), typeB = resource("typeB");
130:                g.implementWith(typeA, mockAssembler);
131:                g.implementWith(typeB, mockAssembler);
132:                g.open(root);
133:                assertTrue(fullModel[0].contains(typeA, RDFS.subClassOf,
134:                        JA.Object));
135:                assertTrue(fullModel[0].contains(typeB, RDFS.subClassOf,
136:                        JA.Object));
137:            }
138:
139:            public static class ImplementsSPOO {
140:                public static void whenRequiredByAssembler(AssemblerGroup g) {
141:                    g.implementWith(resource("SPOO"), mockAssembler);
142:                }
143:            }
144:
145:            public void testClassesLoadedBeforeAddingTypes() {
146:                String className = ImplementsSPOO.class.getName();
147:                Resource root = resourceInModel("_root rdf:type ja:MemoryModel; _x ja:loadClass '"
148:                        + className + "'");
149:                ExpandingAssemblerGroup g = new AssemblerGroup.ExpandingAssemblerGroup();
150:                g.implementWith(resource("ja:MemoryModel"), mockAssembler);
151:                g.open(root);
152:                assertEquals(resourceSet("SPOO ja:MemoryModel"), g
153:                        .implements Types());
154:            }
155:
156:            protected void assertMemoryModel(Object object) {
157:                if (object instanceof  Model) {
158:                    Graph g = ((Model) object).getGraph();
159:                    assertInstanceOf(GraphMemBase.class, g);
160:                } else
161:                    fail("expected a Model, but got a " + object.getClass());
162:            }
163:
164:            public void testPassesSelfIn() {
165:                final AssemblerGroup group = AssemblerGroup.create();
166:                final Object result = new Object();
167:                Assembler fake = new AssemblerBase() {
168:                    public Object open(Assembler a, Resource root,
169:                            Mode irrelevant) {
170:                        assertSame(
171:                                "nested call should pass in assembler group:",
172:                                group, a);
173:                        return result;
174:                    }
175:                };
176:                group.implementWith(JA.Object, fake);
177:                assertSame(result, group
178:                        .open(resourceInModel("x rdf:type ja:Object")));
179:            }
180:
181:            public void testCopyPreservesMapping() {
182:                AssemblerGroup initial = AssemblerGroup.create().implementWith(
183:                        JA.InfModel, new InfModelAssembler());
184:                AssemblerGroup copy = initial.copy();
185:                assertSame(initial.assemblerFor(JA.InfModel), copy
186:                        .assemblerFor(JA.InfModel));
187:                assertNull(copy.assemblerFor(JA.Connection));
188:            }
189:
190:            public void testCopyHasOwnMapping() {
191:                AssemblerGroup initial = AssemblerGroup.create().implementWith(
192:                        JA.InfModel, new InfModelAssembler());
193:                AssemblerGroup copy = initial.copy();
194:                copy.implementWith(JA.Connection, new ConnectionAssembler());
195:                assertNull(initial.assemblerFor(JA.Connection));
196:            }
197:        }
198:
199:        /*
200:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
201:         * All rights reserved.
202:         *
203:         * Redistribution and use in source and binary forms, with or without
204:         * modification, are permitted provided that the following conditions
205:         * are met:
206:         * 1. Redistributions of source code must retain the above copyright
207:         *    notice, this list of conditions and the following disclaimer.
208:         * 2. Redistributions in binary form must reproduce the above copyright
209:         *    notice, this list of conditions and the following disclaimer in the
210:         *    documentation and/or other materials provided with the distribution.
211:         * 3. The name of the author may not be used to endorse or promote products
212:         *    derived from this software without specific prior written permission.
213:         *
214:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
215:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
216:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
217:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
218:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
219:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
220:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
222:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
224:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.