001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestOntModelAssembler.java,v 1.8 2008/01/03 15:18:54 chris-dollin Exp $
005: */
006:
007: package com.hp.hpl.jena.assembler.test;
008:
009: import java.lang.reflect.Field;
010: import java.util.List;
011:
012: import junit.framework.*;
013:
014: import com.hp.hpl.jena.assembler.*;
015: import com.hp.hpl.jena.assembler.assemblers.*;
016: import com.hp.hpl.jena.ontology.*;
017: import com.hp.hpl.jena.rdf.model.*;
018:
019: public class TestOntModelAssembler extends AssemblerTestBase {
020: public TestOntModelAssembler(String name) {
021: super (name);
022: }
023:
024: public static TestSuite suite() {
025: TestSuite result = new TestSuite();
026: result.addTestSuite(TestOntModelAssembler.class);
027: addParameterisedTests(result);
028: return result;
029: }
030:
031: protected Class getAssemblerClass() {
032: return OntModelAssembler.class;
033: }
034:
035: public void testOntModelAssemblerType() {
036: testDemandsMinimalType(new OntModelAssembler(), JA.OntModel);
037: }
038:
039: protected static void addParameterisedTests(TestSuite result) {
040: Field[] fields = OntModelSpec.class.getFields();
041: for (int i = 0; i < fields.length; i += 1) {
042: Field f = fields[i];
043: String name = f.getName();
044: if (f.getType() == OntModelSpec.class)
045: try {
046: result.addTest(createTest((OntModelSpec) f
047: .get(null), name));
048: } catch (Exception e) {
049: System.err
050: .println("WARNING: failed to create test for OntModelSpec "
051: + name);
052: }
053: }
054: }
055:
056: protected static Test createTest(final OntModelSpec spec,
057: final String name) {
058: return new TestOntModelAssembler(name) {
059: public void runBare() {
060: Assembler a = new OntModelAssembler();
061: Model m = (Model) a
062: .open(
063: new FixedObjectAssembler(spec),
064: resourceInModel("x rdf:type ja:OntModel; x ja:ontModelSpec ja:"
065: + name));
066: assertInstanceOf(OntModel.class, m);
067: OntModel om = (OntModel) m;
068: assertSame(spec, om.getSpecification());
069: }
070: };
071: }
072:
073: public void testAllDefaults() {
074: Assembler a = new OntModelAssembler();
075: Model m = a
076: .openModel(resourceInModel("x rdf:type ja:OntModel"));
077: assertInstanceOf(OntModel.class, m);
078: OntModel om = (OntModel) m;
079: assertSame(OntModelSpec.OWL_MEM_RDFS_INF, om.getSpecification());
080: }
081:
082: public void testBaseModel() {
083: final Model baseModel = model("a P b");
084: Assembler a = new OntModelAssembler();
085: Assembler aa = new ModelAssembler() {
086: protected Model openEmptyModel(Assembler a, Resource root,
087: Mode irrelevant) {
088: assertEquals(resource("y"), root);
089: return baseModel;
090: }
091: };
092: Object m = a
093: .open(
094: aa,
095: resourceInModel("x rdf:type ja:OntModel; x ja:baseModel y"));
096: assertInstanceOf(OntModel.class, m);
097: OntModel om = (OntModel) m;
098: assertSame(baseModel.getGraph(), om.getBaseModel().getGraph());
099: }
100:
101: public void testSubModels() {
102: final Model baseModel = model("a P b");
103: Assembler a = new OntModelAssembler();
104: Assembler aa = new ModelAssembler() {
105: protected Model openEmptyModel(Assembler a, Resource root,
106: Mode irrelevant) {
107: assertEquals(resource("y"), root);
108: return baseModel;
109: }
110: };
111: Object m = a
112: .open(
113: aa,
114: resourceInModel("x rdf:type ja:OntModel; x ja:subModel y"));
115: assertInstanceOf(OntModel.class, m);
116: OntModel om = (OntModel) m;
117: List subModels = om.listSubModels().toList();
118: assertEquals(1, subModels.size());
119: assertSame(baseModel.getGraph(), ((OntModel) subModels.get(0))
120: .getBaseModel().getGraph());
121: }
122:
123: public void testDefaultDocumentManager() {
124: Assembler a = new OntModelAssembler();
125: Resource root = resourceInModel("x rdf:type ja:OntModel");
126: OntModel om = (OntModel) a.openModel(root);
127: assertSame(OntDocumentManager.getInstance(), om
128: .getDocumentManager());
129: }
130:
131: public void testUsesOntModelSpec() {
132: Assembler a = new OntModelAssembler();
133: Resource root = resourceInModel("x rdf:type ja:OntModel; x ja:ontModelSpec y");
134: OntModelSpec spec = new OntModelSpec(OntModelSpec.DAML_MEM);
135: Assembler mock = new NamedObjectAssembler(resource("y"), spec);
136: OntModel om = (OntModel) a.open(mock, root);
137: assertSame(spec, om.getSpecification());
138: }
139: }
140:
141: /*
142: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
143: * All rights reserved.
144: *
145: * Redistribution and use in source and binary forms, with or without
146: * modification, are permitted provided that the following conditions
147: * are met:
148: * 1. Redistributions of source code must retain the above copyright
149: * notice, this list of conditions and the following disclaimer.
150: * 2. Redistributions in binary form must reproduce the above copyright
151: * notice, this list of conditions and the following disclaimer in the
152: * documentation and/or other materials provided with the distribution.
153: * 3. The name of the author may not be used to endorse or promote products
154: * derived from this software without specific prior written permission.
155: *
156: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
157: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
158: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
159: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
160: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
161: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
162: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
163: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
164: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
165: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166: */
|