001: /*
002: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestDocumentManagerAssembler.java,v 1.6 2008/01/02 12:05:57 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.DocumentManagerAssembler;
013: import com.hp.hpl.jena.ontology.OntDocumentManager;
014: import com.hp.hpl.jena.rdf.model.*;
015: import com.hp.hpl.jena.util.FileManager;
016:
017: public class TestDocumentManagerAssembler extends AssemblerTestBase {
018: public TestDocumentManagerAssembler(String name) {
019: super (name);
020: }
021:
022: protected Class getAssemblerClass() {
023: return DocumentManagerAssembler.class;
024: }
025:
026: public void testDocumentManagerAssemblerType() {
027: testDemandsMinimalType(new DocumentManagerAssembler(),
028: JA.DocumentManager);
029: }
030:
031: public void testDocumentManagerVocabulary() {
032: assertSubclassOf(JA.DocumentManager, JA.Object);
033: assertSubclassOf(JA.DocumentManager, JA.HasFileManager);
034: assertRange(JA.FileManager, JA.fileManager);
035: assertDomain(JA.DocumentManager, JA.policyPath);
036: }
037:
038: public void testCreatesDocumentManager() {
039: Resource root = resourceInModel("x rdf:type ja:DocumentManager");
040: Assembler a = new DocumentManagerAssembler();
041: Object x = a.open(root);
042: assertInstanceOf(OntDocumentManager.class, x);
043: }
044:
045: public void testUsesFileManager() {
046: Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:fileManager f");
047: Assembler a = new DocumentManagerAssembler();
048: FileManager fm = new FileManager();
049: Assembler mock = new NamedObjectAssembler(resource("f"), fm);
050: Object x = a.open(mock, root);
051: assertInstanceOf(OntDocumentManager.class, x);
052: assertSame(fm, ((OntDocumentManager) x).getFileManager());
053: }
054:
055: public void testSetsPolicyPath() {
056: Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:policyPath 'somePath'");
057: final List history = new ArrayList();
058: Assembler a = new DocumentManagerAssembler() {
059: protected OntDocumentManager createDocumentManager() {
060: return new OntDocumentManager("") {
061: public void setMetadataSearchPath(String path,
062: boolean replace) {
063: assertEquals(false, replace);
064: history.add(path);
065: super .setMetadataSearchPath(path, replace);
066: }
067: };
068: }
069: };
070: OntDocumentManager d = (OntDocumentManager) a.open(root);
071: assertEquals(listOfOne("somePath"), history);
072: }
073:
074: public void testTrapsPolicyPathNotString() {
075: testTrapsBadPolicyPath("aResource");
076: testTrapsBadPolicyPath("17");
077: testTrapsBadPolicyPath("'char'en");
078: testTrapsBadPolicyPath("'cafe'xsd:integer");
079: }
080:
081: private void testTrapsBadPolicyPath(String path) {
082: Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:policyPath <policy>"
083: .replaceAll("<policy>", path));
084: final List history = new ArrayList();
085: Assembler a = new DocumentManagerAssembler();
086: try {
087: a.open(root);
088: fail("should trap illegal policy path object " + path);
089: } catch (BadObjectException e) {
090: assertEquals(resource("x"), e.getRoot());
091: assertEquals(rdfNode(root.getModel(), path), e.getObject());
092: }
093: }
094:
095: public void testSetsMetadata() { // we set policyPath to avoid Ont default models being thrown at us
096: Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:policyPath ''; x P a; a Q b; y R z");
097: final Model expected = model("x rdf:type ja:DocumentManager; x ja:policyPath ''; x P a; a Q b");
098: final List history = new ArrayList();
099: Assembler a = new DocumentManagerAssembler() {
100: protected OntDocumentManager createDocumentManager() {
101: return new OntDocumentManager("") {
102: public void processMetadata(Model m) {
103: assertIsoModels(expected, m);
104: history.add("called");
105: super .processMetadata(m);
106: }
107: };
108: }
109: };
110: OntDocumentManager d = (OntDocumentManager) a.open(root);
111: assertEquals(listOfOne("called"), history);
112: }
113: }
114:
115: /*
116: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
117: * All rights reserved.
118: *
119: * Redistribution and use in source and binary forms, with or without
120: * modification, are permitted provided that the following conditions
121: * are met:
122: * 1. Redistributions of source code must retain the above copyright
123: * notice, this list of conditions and the following disclaimer.
124: * 2. Redistributions in binary form must reproduce the above copyright
125: * notice, this list of conditions and the following disclaimer in the
126: * documentation and/or other materials provided with the distribution.
127: * 3. The name of the author may not be used to endorse or promote products
128: * derived from this software without specific prior written permission.
129: *
130: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
131: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
132: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
133: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
134: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
135: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
136: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
137: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
138: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
139: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
140: */
|