001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestModelContent.java,v 1.8 2008/01/03 09:33:04 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.exceptions.TransactionAbortedException;
013: import com.hp.hpl.jena.rdf.model.*;
014:
015: public class TestModelContent extends AssemblerTestBase {
016: public TestModelContent(String name) {
017: super (name);
018: }
019:
020: protected Class getAssemblerClass() {
021: return null;
022: }
023:
024: public void testMemoryModelLoadsSingleContent() {
025: testModelLoadsSingleContent(Assembler.memoryModel,
026: JA.MemoryModel);
027: }
028:
029: public void testMemoryModelLoadsMultipleContent() {
030: testModelLoadsMultipleContent(Assembler.memoryModel,
031: JA.MemoryModel);
032: }
033:
034: public void testDefaultModelLoadsSingleContent() {
035: testModelLoadsSingleContent(Assembler.defaultModel,
036: JA.DefaultModel);
037: }
038:
039: public void testDefaultModelLoadsMultipleContent() {
040: testModelLoadsMultipleContent(Assembler.defaultModel,
041: JA.DefaultModel);
042: }
043:
044: public void testInfModelLoadsContent() {
045: testModelLoadsMultipleContent(Assembler.infModel, JA.InfModel);
046: }
047:
048: public void testContentTransactionsNone() {
049: final List history = new ArrayList();
050: final Model expected = model("_x rdf:value '17'xsd:integer");
051: Assembler a = new MockTransactionModel(history, expected,
052: false, true);
053: Resource root = resourceInModel("x rdf:type ja:Model; x ja:content y; y rdf:type ja:Content; y rdf:type ja:LiteralContent; y ja:literalContent '_:x\\srdf:value\\s17.'");
054: try {
055: a.open(Assembler.content, root);
056: } catch (RuntimeException e) {
057: }
058: }
059:
060: public void testContentTransactionsCommit() {
061: final List history = new ArrayList();
062: final Model expected = model("_x rdf:value '17'xsd:integer");
063: Assembler a = new MockTransactionModel(history, expected, true,
064: false);
065: Resource root = resourceInModel("x rdf:type ja:Model; x ja:content y; y rdf:type ja:Content; y rdf:type ja:LiteralContent; y ja:literalContent '_:x\\srdf:value\\s17.'");
066: Model m = (Model) a.open(Assembler.content, root);
067: assertEquals(listOfStrings("supports[true] begin add commit"),
068: history);
069: assertIsoModels(expected, m);
070: }
071:
072: public void testContentTransactionsAbort() {
073: final List history = new ArrayList();
074: final Model expected = model("_x rdf:value '17'xsd:integer");
075: final Model toDeliver = model("").add(expected);
076: Assembler a = new MockTransactionModel(history, toDeliver,
077: true, true);
078: try {
079: Resource root = resourceInModel("x rdf:type ja:Model; x ja:content y; y rdf:type ja:Content"
080: + "; y rdf:type ja:LiteralContent; y ja:literalContent '_:x\\srdf:value\\s17.'");
081: a.open(Assembler.content, root);
082: fail("should throw (wrapped) failing exception");
083: } catch (TransactionAbortedException e) {
084: assertEquals(resource("x"), e.getRoot());
085: assertEquals(
086: listOfStrings("supports[true] begin add abort"),
087: history);
088: assertIsoModels(expected, toDeliver);
089: }
090: }
091:
092: protected void testModelLoadsSingleContent(Assembler a,
093: Resource type) {
094: Resource root = resourceInModel("x rdf:type "
095: + type
096: + "; x ja:content y; y rdf:type ja:Content"
097: + "; y rdf:type ja:LiteralContent; y ja:literalContent '_:x\\srdf:value\\s17.'");
098: Model m = (Model) a.open(Assembler.content, root);
099: assertIsoModels(model("_x rdf:value '17'xsd:integer"), m);
100: }
101:
102: protected void testModelLoadsMultipleContent(Assembler a,
103: Resource type) {
104: Model m = (Model) a
105: .open(
106: Assembler.content,
107: resourceInModel("x rdf:type "
108: + type
109: + "; x ja:content y; x ja:content z"
110: + "; y rdf:type ja:Content; y rdf:type ja:LiteralContent; y ja:literalContent '_:x\\srdf:value\\s17.'"
111: + "; z rdf:type ja:Content; z rdf:type ja:LiteralContent; z ja:literalContent '_:x\\srdf:value\\s42.'"));
112: assertIsoModels(
113: model("_x rdf:value '17'xsd:integer; _y rdf:value '42'xsd:integer"),
114: m);
115: }
116: }
117:
118: /*
119: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
120: * All rights reserved.
121: *
122: * Redistribution and use in source and binary forms, with or without
123: * modification, are permitted provided that the following conditions
124: * are met:
125: * 1. Redistributions of source code must retain the above copyright
126: * notice, this list of conditions and the following disclaimer.
127: * 2. Redistributions in binary form must reproduce the above copyright
128: * notice, this list of conditions and the following disclaimer in the
129: * documentation and/or other materials provided with the distribution.
130: * 3. The name of the author may not be used to endorse or promote products
131: * derived from this software without specific prior written permission.
132: *
133: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
134: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
135: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
136: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
137: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
138: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
139: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
140: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
141: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
142: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
143: */
|