001: /*
002: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestDatabaseModes.java,v 1.5 2008/01/02 12:10:32 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.assembler.acceptance;
008:
009: import com.hp.hpl.jena.assembler.*;
010: import com.hp.hpl.jena.assembler.test.AssemblerTestBase;
011: import com.hp.hpl.jena.rdf.model.Resource;
012: import com.hp.hpl.jena.shared.*;
013:
014: public class TestDatabaseModes extends AssemblerTestBase {
015: public TestDatabaseModes(String name) {
016: super (name);
017: }
018:
019: public void testRDBModelOpenedWhenExists() {
020: openWith("square", false, true);
021: openWith("circle", true, true);
022: }
023:
024: public void testRDBModelCreatedWhenMissing() {
025: openWith("line", true, true);
026: openWith("edge", true, false);
027: }
028:
029: public void testRDBModelFailsIfExists() {
030: try {
031: openWith("triangle", true, false);
032: AllAccept.fail("should trap existing model");
033: } catch (AlreadyExistsException e) {
034: AllAccept.assertEquals("triangle", e.getMessage());
035: }
036: try {
037: openWith("hex", false, false);
038: AllAccept.fail("should trap existing model");
039: } catch (AlreadyExistsException e) {
040: AllAccept.assertEquals("hex", e.getMessage());
041: }
042: }
043:
044: public void testRDBModelFailsIfMissing() {
045: try {
046: openWith("parabola", false, true);
047: AllAccept.fail("should trap missing model");
048: } catch (NotFoundException e) {
049: AllAccept.assertEquals("parabola", e.getMessage());
050: }
051: try {
052: openWith("curve", false, false);
053: AllAccept.fail("should trap missing model");
054: } catch (NotFoundException e) {
055: AllAccept.assertEquals("curve", e.getMessage());
056: }
057: }
058:
059: private void openWith(String name, boolean mayCreate,
060: boolean mayReuse) {
061: Assembler.general.openModel(getRoot(name),
062: new Mode(mayCreate, mayReuse)).close();
063: }
064:
065: private Resource getRoot(String name) {
066: return resourceInModel(getDescription(name));
067: }
068:
069: private String getDescription(String modelName) {
070: return ("x rdf:type ja:RDBModel; x ja:modelName 'spoo'; x ja:connection C"
071: + "; C ja:dbURLProperty 'jena.db.url'"
072: + "; C ja:dbUserProperty 'jena.db.user'"
073: + "; C ja:dbPasswordProperty 'jena.db.password'"
074: + "; C ja:dbTypeProperty 'jena.db.type'"
075: + "; C ja:dbClassProperty 'jena.db.driver'")
076: .replaceAll("spoo", modelName);
077: }
078: }
079:
080: /*
081: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
082: * reserved.
083: *
084: * Redistribution and use in source and binary forms, with or without
085: * modification, are permitted provided that the following conditions are met:
086: * 1. Redistributions of source code must retain the above copyright notice,
087: * this list of conditions and the following disclaimer. 2. Redistributions in
088: * binary form must reproduce the above copyright notice, this list of
089: * conditions and the following disclaimer in the documentation and/or other
090: * materials provided with the distribution. 3. The name of the author may not
091: * be used to endorse or promote products derived from this software without
092: * specific prior written permission.
093: *
094: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
095: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
096: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
097: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
098: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
099: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
100: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
101: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
102: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
103: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
104: */
|