001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestModelAssembler.java,v 1.9 2008/01/03 15:18:54 chris-dollin 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.*;
013: import com.hp.hpl.jena.assembler.exceptions.UnknownStyleException;
014: import com.hp.hpl.jena.rdf.model.*;
015: import com.hp.hpl.jena.shared.*;
016:
017: public class TestModelAssembler extends AssemblerTestBase {
018: protected static final class FakeModelAssembler extends
019: ModelAssembler {
020: protected Model openEmptyModel(Assembler a, Resource root,
021: Mode mode) {
022: return ModelFactory.createDefaultModel();
023: }
024: }
025:
026: public TestModelAssembler(String name) {
027: super (name);
028: }
029:
030: protected Class getAssemblerClass() {
031: return null;
032: }
033:
034: public void testModelAssemblerVocabulary() {
035: assertDomain(JA.Model, JA.reificationMode);
036: assertRange(JA.ReificationMode, JA.reificationMode);
037: assertType(JA.ReificationMode, JA.minimal);
038: assertType(JA.ReificationMode, JA.standard);
039: assertType(JA.ReificationMode, JA.convenient);
040: }
041:
042: public void testContent() {
043: Resource root = resourceInModel("x rdf:type ja:DefaultModel; x ja:initialContent c; c ja:quotedContent A; A P B");
044: // root.getModel().write( System.err, "N3" );
045: Model m = (Model) new FakeModelAssembler().open(
046: new ContentAssembler(), root, Mode.ANY);
047: assertIsoModels(modelWithStatements("A P B"), m);
048: }
049:
050: public void testGetsPrefixMappings() {
051: Assembler a = new FakeModelAssembler();
052: PrefixMapping wanted = PrefixMapping.Factory.create()
053: .setNsPrefix("my", "urn:secret:42/").setNsPrefix(
054: "your", "urn:public:17#");
055: Resource root = resourceInModel("x rdf:type ja:DefaultModel; x ja:includes p1; x ja:includes p2"
056: + "; p1 rdf:type ja:PrefixMapping; p1 ja:prefix 'my'; p1 ja:namespace 'urn:secret:42/'"
057: + "; p2 rdf:type ja:PrefixMapping; p2 ja:prefix 'your'; p2 ja:namespace 'urn:public:17#'");
058: Model m = (Model) a.open(Assembler.prefixMapping, root);
059: assertSamePrefixMapping(wanted, m);
060: }
061:
062: public void testGetsStandardReificationMode() {
063: final List style = new ArrayList();
064: Assembler a = new ModelAssembler() {
065: protected Model openEmptyModel(Assembler a, Resource root,
066: Mode irrelevant) {
067: style.add(getReificationStyle(root));
068: return ModelFactory.createDefaultModel();
069: }
070: };
071: Model m = a.openModel(resourceInModel("a rdf:type ja:Model"));
072: assertEquals(listOfOne(ReificationStyle.Standard), style);
073: }
074:
075: public void testGetsExplicitReificationMode() {
076: testGetsStyle("ja:minimal", ReificationStyle.Minimal);
077: testGetsStyle("ja:standard", ReificationStyle.Standard);
078: testGetsStyle("ja:convenient", ReificationStyle.Convenient);
079: }
080:
081: public void testUnknownStyleFails() {
082: try {
083: testGetsStyle("unknown", ReificationStyle.Standard);
084: fail("should trap unknown reification style");
085: } catch (UnknownStyleException e) {
086: assertEquals(resource("unknown"), e.getStyle());
087: assertEquals(resource("a"), e.getRoot());
088: }
089: }
090:
091: private void testGetsStyle(String styleString,
092: ReificationStyle style) {
093: final List styles = new ArrayList();
094: Assembler a = new ModelAssembler() {
095: protected Model openEmptyModel(Assembler a, Resource root,
096: Mode irrelevant) {
097: styles.add(getReificationStyle(root));
098: return ModelFactory.createDefaultModel();
099: }
100: };
101: Model m = a
102: .openModel(resourceInModel("a rdf:type ja:Model; a ja:reificationMode "
103: + styleString));
104: assertEquals(listOfOne(style), styles);
105: }
106: }
107:
108: /*
109: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
110: * All rights reserved.
111: *
112: * Redistribution and use in source and binary forms, with or without
113: * modification, are permitted provided that the following conditions
114: * are met:
115: * 1. Redistributions of source code must retain the above copyright
116: * notice, this list of conditions and the following disclaimer.
117: * 2. Redistributions in binary form must reproduce the above copyright
118: * notice, this list of conditions and the following disclaimer in the
119: * documentation and/or other materials provided with the distribution.
120: * 3. The name of the author may not be used to endorse or promote products
121: * derived from this software without specific prior written permission.
122: *
123: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
124: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
125: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
126: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
127: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
128: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
129: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
130: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
131: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
132: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133: */
|