001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestInfModelAssembler.java,v 1.5 2008/01/02 12:05:55 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.InfModelAssembler;
011: import com.hp.hpl.jena.assembler.exceptions.NotUniqueException;
012: import com.hp.hpl.jena.rdf.model.*;
013: import com.hp.hpl.jena.reasoner.*;
014: import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasonerFactory;
015:
016: public class TestInfModelAssembler extends AssemblerTestBase {
017: public TestInfModelAssembler(String name) {
018: super (name);
019: }
020:
021: protected Class getAssemblerClass() {
022: return InfModelAssembler.class;
023: }
024:
025: public void testLocationMapperAssemblerType() {
026: testDemandsMinimalType(new InfModelAssembler(), JA.InfModel);
027: }
028:
029: public void testMockReasonersDifferent() {
030: Reasoner R = GenericRuleReasonerFactory.theInstance().create(
031: null);
032: assertNotSame(mockReasonerFactory(R), mockReasonerFactory(R));
033: }
034:
035: public void testInfModel() {
036: Assembler a = Assembler.infModel;
037: Model m = a
038: .openModel(resourceInModel("x rdf:type ja:InfModel"));
039: assertInstanceOf(InfModel.class, m);
040: }
041:
042: public void testInfModelType() {
043: testDemandsMinimalType(Assembler.infModel, JA.InfModel);
044: }
045:
046: public void testGetsReasoner() {
047: Reasoner R = GenericRuleReasonerFactory.theInstance().create(
048: null);
049: final ReasonerFactory RF = mockReasonerFactory(R);
050: Assembler mock = new FixedObjectAssembler(RF);
051: Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:reasoner R");
052: InfModel m = (InfModel) Assembler.infModel.open(mock, root);
053: assertSame(R, m.getReasoner());
054: }
055:
056: protected ReasonerFactory mockReasonerFactory(final Reasoner R) {
057: return new ReasonerFactory() {
058: public Reasoner create(Resource configuration) {
059: return R;
060: }
061:
062: public Model getCapabilities() {
063: throw new RuntimeException(
064: "mock doesn't do getCapabilities");
065: }
066:
067: public String getURI() {
068: throw new RuntimeException("mock doesn't do getURI");
069: }
070: };
071: }
072:
073: public void testGetsSpecifiedModel() {
074: Model base = ModelFactory.createDefaultModel();
075: Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:baseModel M");
076: Assembler mock = new NamedObjectAssembler(resource("M"), base);
077: InfModel inf = (InfModel) Assembler.infModel.open(mock, root);
078: assertSame(base.getGraph(), inf.getRawModel().getGraph());
079: }
080:
081: public void testDetectsMultipleBaseModels() {
082: Model base = ModelFactory.createDefaultModel();
083: Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:baseModel M; x ja:baseModel M2");
084: Assembler mock = new FixedObjectAssembler(base);
085: try {
086: Assembler.infModel.open(mock, root);
087: fail("should detect multiple baseModels");
088: } catch (NotUniqueException e) {
089: assertEquals(JA.baseModel, e.getProperty());
090: assertEquals(resource("x"), e.getRoot());
091: }
092: }
093:
094: public void testDetectsMultipleReasoners() {
095: Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:reasoner R; x ja:reasoner R2");
096: Assembler mock = new FixedObjectAssembler(null);
097: try {
098: Assembler.infModel.open(mock, root);
099: fail("should detect multiple reasoners");
100: } catch (NotUniqueException e) {
101: assertEquals(JA.reasoner, e.getProperty());
102: assertEquals(resource("x"), e.getRoot());
103: }
104: }
105: }
106:
107: /*
108: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
109: * All rights reserved.
110: *
111: * Redistribution and use in source and binary forms, with or without
112: * modification, are permitted provided that the following conditions
113: * are met:
114: * 1. Redistributions of source code must retain the above copyright
115: * notice, this list of conditions and the following disclaimer.
116: * 2. Redistributions in binary form must reproduce the above copyright
117: * notice, this list of conditions and the following disclaimer in the
118: * documentation and/or other materials provided with the distribution.
119: * 3. The name of the author may not be used to endorse or promote products
120: * derived from this software without specific prior written permission.
121: *
122: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
123: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
124: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
125: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
126: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
127: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
128: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
129: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
130: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
131: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
132: */
|