001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestModelSourceAssembler.java,v 1.8 2008/01/02 12:05:55 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.assembler.test;
008:
009: import java.util.*;
010:
011: import com.hp.hpl.jena.assembler.*;
012: import com.hp.hpl.jena.assembler.assemblers.ModelSourceAssembler;
013: import com.hp.hpl.jena.assembler.exceptions.PropertyRequiredException;
014: import com.hp.hpl.jena.rdf.model.*;
015: import com.hp.hpl.jena.rdf.model.impl.MemoryModelGetter;
016:
017: public class TestModelSourceAssembler extends AssemblerTestBase {
018: public TestModelSourceAssembler(String name) {
019: super (name);
020: }
021:
022: protected Class getAssemblerClass() {
023: return ModelSourceAssembler.class;
024: }
025:
026: public void testModelSourceAssemblerType() {
027: testDemandsMinimalType(new ModelSourceAssembler(),
028: JA.ModelSource);
029: }
030:
031: public void testModelSourceVocabulary() {
032: assertDomain(JA.Connectable, JA.connection);
033: assertRange(JA.Connection, JA.connection);
034: assertSubclassOf(JA.Connectable, JA.Object);
035: assertSubclassOf(JA.RDBModelSource, JA.Connectable);
036: assertSubclassOf(JA.RDBModelSource, JA.ModelSource);
037: }
038:
039: public void testDBSourceDemandsConnection() {
040: Resource root = resourceInModel("x rdf:type ja:ModelSource; x rdf:type ja:RDBModelSource");
041: Assembler a = new ModelSourceAssembler();
042: try {
043: a.open(root);
044: fail("should catch missing connection");
045: } catch (PropertyRequiredException e) {
046: assertEquals(resource("x"), e.getRoot());
047: assertEquals(JA.connection, e.getProperty());
048: }
049: }
050:
051: public void testMemModelMakerSource() {
052: Assembler a = new ModelSourceAssembler();
053: ModelGetter g = (ModelGetter) a
054: .open(resourceInModel("mg rdf:type ja:ModelSource"));
055: assertInstanceOf(MemoryModelGetter.class, g);
056: }
057:
058: public void testRDBModelMakerSource() {
059: final ConnectionDescription c = new ConnectionDescription(
060: "eh:/subject", "url", "user", "password", "type");
061: final List history = new ArrayList();
062: Assembler a = new ModelSourceAssembler() {
063: protected ModelGetter createRDBGetter(
064: ConnectionDescription cGiven) {
065: assertSame(c, cGiven);
066: history.add("created");
067: return ModelFactory.createMemModelMaker();
068: }
069: };
070: Assembler mock = new NamedObjectAssembler(resource("C"), c);
071: Resource root = resourceInModel("mg rdf:type ja:RDBModelSource; mg rdf:type ja:ModelSource; mg ja:connection C");
072: assertInstanceOf(ModelGetter.class, a.open(mock, root));
073: assertEquals(listOfOne("created"), history);
074: }
075: }
076:
077: /*
078: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
079: * All rights reserved.
080: *
081: * Redistribution and use in source and binary forms, with or without
082: * modification, are permitted provided that the following conditions
083: * are met:
084: * 1. Redistributions of source code must retain the above copyright
085: * notice, this list of conditions and the following disclaimer.
086: * 2. Redistributions in binary form must reproduce the above copyright
087: * notice, this list of conditions and the following disclaimer in the
088: * documentation and/or other materials provided with the distribution.
089: * 3. The name of the author may not be used to endorse or promote products
090: * derived from this software without specific prior written permission.
091: *
092: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
093: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
094: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
095: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
096: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
097: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
098: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
099: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102: */
|