001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestTransactions.java,v 1.12 2008/01/02 12:08:14 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.db.test;
008:
009: /**
010: *
011: * This tests basic operations on the modelRDB.
012: *
013: * It adds/removes statements of different types and verifys
014: * that the correct statements exist at the correct times.
015: *
016: * To run, you must have a mySQL database operational on
017: * localhost with a database name of "test" and allow use
018: * by a user named "test" with an empty password.
019: *
020: * @author hkuno
021: */
022:
023: import junit.framework.*;
024:
025: import com.hp.hpl.jena.db.IDBConnection;
026: import com.hp.hpl.jena.db.ModelRDB;
027: import com.hp.hpl.jena.db.impl.DriverRDB;
028: import com.hp.hpl.jena.db.impl.Driver_MySQL;
029: import com.hp.hpl.jena.rdf.model.*;
030:
031: public class TestTransactions extends TestCase {
032:
033: public TestTransactions(String name) {
034: super (name);
035: }
036:
037: public static TestSuite suite() {
038: return new TestSuite(TestTransactions.class);
039: }
040:
041: ModelRDB model = null;
042: Model dbProperties = null;
043: IDBConnection conn = null;
044: DriverRDB m_driver = null;
045:
046: protected void setUp() throws java.lang.Exception {
047:
048: conn = TestConnection.makeAndCleanTestConnection();
049: dbProperties = conn.getDatabaseProperties();
050: model = ModelRDB.createModel(conn);
051: m_driver = new Driver_MySQL();
052: m_driver.setConnection(conn);
053: }
054:
055: protected void tearDown() throws java.lang.Exception {
056: model.close();
057: model = null;
058: conn.cleanDB();
059: conn.close();
060: conn = null;
061: }
062:
063: private void addCommit(Statement stmt) {
064: model.remove(stmt);
065: model.begin();
066: model.add(stmt);
067: model.commit();
068: assertTrue(model.contains(stmt));
069: }
070:
071: private void addAbort(Statement stmt) {
072: model.remove(stmt);
073: // try {
074: model.begin();
075: model.add(stmt);
076: model.abort();
077: // } catch(Exception e) {
078: // throw new JenaException( e ); // System.out.println("addAbort caught exception: " + e);
079: // }
080: assertTrue(!model.contains(stmt));
081: }
082:
083: public void testAddCommitURI() {
084: Resource s = model.createResource("test#subject");
085: Property p = model.createProperty("test#predicate");
086: Resource o = model.createResource("test#object");
087:
088: addCommit(model.createStatement(s, p, o));
089: }
090:
091: public void testAddAbortURI() {
092: Resource s = model.createResource("test#subject");
093: Property p = model.createProperty("test#predicate");
094: Resource o = model.createResource("test#object");
095:
096: addAbort(model.createStatement(s, p, o));
097: }
098:
099: public void testAddCommitLiteral() {
100: Resource s = model.createResource("test#subject");
101: Property p = model.createProperty("test#predicate");
102: Literal l = model.createLiteral("testLiteral");
103:
104: addCommit(model.createStatement(s, p, l));
105: }
106:
107: public void testAddCommitHugeLiteral() {
108: String base = Data.strLong;
109: StringBuffer buffer = new StringBuffer(4096);
110: while (buffer.length() < 4000)
111: buffer.append(base);
112: Resource s = model.createResource("test#subject");
113: Property p = model.createProperty("test#predicate");
114: Literal l = model.createLiteral(buffer.toString());
115:
116: addCommit(model.createStatement(s, p, l));
117: }
118:
119: public void testAddAbortHugeLiteral() {
120: String base = Data.strLong;
121: StringBuffer buffer = new StringBuffer(4096);
122: while (buffer.length() < 4000)
123: buffer.append(base);
124: Resource s = model.createResource("test#subject");
125: Property p = model.createProperty("test#predicate");
126: Literal l = model.createLiteral(buffer.toString());
127:
128: addAbort(model.createStatement(s, p, l));
129: }
130:
131: public void testAddCommitDatatype() {
132: Resource s = model.createResource("test#subject");
133: Property p = model.createProperty("test#predicate");
134: Literal l = model.createTypedLiteral("stringType");
135:
136: addCommit(model.createStatement(s, p, l));
137: }
138:
139: public void testAddAbortDatatype() {
140: Resource s = model.createResource("test#subject");
141: Property p = model.createProperty("test#predicate");
142: Literal l = model.createTypedLiteral("stringType");
143:
144: addAbort(model.createStatement(s, p, l));
145: }
146:
147: public void testAddAbortHugeDatatype() {
148: String base = Data.strLong;
149: StringBuffer buffer = new StringBuffer(4096);
150: while (buffer.length() < 4000)
151: buffer.append(base);
152: Resource s = model.createResource("test#subject");
153: Property p = model.createProperty("test#predicate");
154: Literal l2 = model.createTypedLiteral(buffer.toString());
155:
156: addAbort(model.createStatement(s, p, l2));
157: }
158:
159: public void testAddCommitHugeDatatype() {
160: String base = Data.strLong;
161: StringBuffer buffer = new StringBuffer(4096);
162: while (buffer.length() < 4000)
163: buffer.append(base);
164: Resource s = model.createResource("test#subject");
165: Property p = model.createProperty("test#predicate");
166: Literal l2 = model.createTypedLiteral(buffer.toString());
167:
168: addCommit(model.createStatement(s, p, l2));
169: }
170:
171: public void testAddCommitBNode() {
172: Resource s = model.createResource();
173: Property p = model.createProperty("test#predicate");
174: Resource o = model.createResource();
175:
176: addCommit(model.createStatement(s, p, o));
177: }
178:
179: public void testAddAbortBNode() {
180: Resource s = model.createResource();
181: Property p = model.createProperty("test#predicate");
182: Resource o = model.createResource();
183:
184: addAbort(model.createStatement(s, p, o));
185: }
186:
187: }
188:
189: /*
190: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
191: All rights reserved.
192:
193: Redistribution and use in source and binary forms, with or without
194: modification, are permitted provided that the following conditions
195: are met:
196:
197: 1. Redistributions of source code must retain the above copyright
198: notice, this list of conditions and the following disclaimer.
199:
200: 2. Redistributions in binary form must reproduce the above copyright
201: notice, this list of conditions and the following disclaimer in the
202: documentation and/or other materials provided with the distribution.
203:
204: 3. The name of the author may not be used to endorse or promote products
205: derived from this software without specific prior written permission.
206:
207: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
208: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
209: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
210: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
211: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
212: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
213: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
214: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
215: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
216: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
217: */
|