001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestFileGraphMaker.java,v 1.17 2008/01/02 12:05:34 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.test;
008:
009: import java.io.File;
010: import java.util.HashSet;
011:
012: import com.hp.hpl.jena.graph.*;
013: import com.hp.hpl.jena.graph.impl.*;
014: import com.hp.hpl.jena.shared.*;
015: import com.hp.hpl.jena.util.FileUtils;
016:
017: import junit.framework.*;
018:
019: /**
020: Test a FileGraphMaker; use the abstract tests, plus specialised ones for the name
021: conversion routines.
022:
023: @author hedgehog
024: */
025: public class TestFileGraphMaker extends AbstractTestGraphMaker {
026: public TestFileGraphMaker(String name) {
027: super (name);
028: }
029:
030: public static TestSuite suite() {
031: return new TestSuite(TestFileGraphMaker.class);
032: }
033:
034: public GraphMaker getGraphMaker() {
035: String scratch = FileUtils.getScratchDirectory(
036: "jena-test-FileGraphMaker").getPath();
037: return new FileGraphMaker(scratch, ReificationStyle.Minimal,
038: true);
039: }
040:
041: public void testToFilename() {
042: assertEquals("plain", FileGraphMaker.toFilename("plain"));
043: assertEquals("with_Sslash", FileGraphMaker
044: .toFilename("with/slash"));
045: assertEquals("with_Ccolon", FileGraphMaker
046: .toFilename("with:colon"));
047: assertEquals("with_Uunderbar", FileGraphMaker
048: .toFilename("with_underbar"));
049: assertEquals("with_Stwo_Sslashes", FileGraphMaker
050: .toFilename("with/two/slashes"));
051: assertEquals("with_Sa_Cmixture_U...", FileGraphMaker
052: .toFilename("with/a:mixture_..."));
053: }
054:
055: public void testToGraphname() {
056: assertEquals("plain", FileGraphMaker.toGraphname("plain"));
057: assertEquals("with/slash", FileGraphMaker
058: .toGraphname("with_Sslash"));
059: assertEquals("with:colon", FileGraphMaker
060: .toGraphname("with_Ccolon"));
061: assertEquals("with_underbar", FileGraphMaker
062: .toGraphname("with_Uunderbar"));
063: assertEquals("a/mixture_of:things", FileGraphMaker
064: .toGraphname("a_Smixture_Uof_Cthings"));
065: assertEquals("with/two/slashes", FileGraphMaker
066: .toGraphname("with_Stwo_Sslashes"));
067: }
068:
069: public void testDetectsExistingFiles() {
070: File scratch = FileUtils
071: .getScratchDirectory("jena-test-FileGraphMaker-already");
072: Graph content = graphWith("something hasProperty someValue");
073: FileGraphMaker A = new FileGraphMaker(scratch.getPath(),
074: ReificationStyle.Minimal, true);
075: FileGraphMaker B = new FileGraphMaker(scratch.getPath(),
076: ReificationStyle.Minimal, true);
077: FileGraph gA = (FileGraph) A.createGraph("already", true);
078: gA.getBulkUpdateHandler().add(content);
079: gA.close();
080: FileGraph gB = (FileGraph) B.openGraph("already", false);
081: assertIsomorphic(content, gB);
082: gB.close();
083: gB.delete();
084: gA.delete();
085: }
086:
087: public void testDeletesFilesOfClosedMaker() {
088: File scratch = FileUtils
089: .getScratchDirectory("jena-test-FileGraphMaker-forgets");
090: FileGraphMaker A = new FileGraphMaker(scratch.getPath(),
091: ReificationStyle.Minimal, true);
092: A.createGraph("empty").close();
093: assertTrue("file 'empty' should exist in '" + scratch + "'",
094: new File(scratch, "empty").exists());
095: A.close();
096: assertFalse("file 'empty' should no longer exist in '"
097: + scratch + "'", new File(scratch, "empty").exists());
098: }
099:
100: public void testForgetsClosedGraphs() {
101: File scratch = FileUtils
102: .getScratchDirectory("jena-test-FileGraphMaker-forgets");
103: FileGraphMaker m = new FileGraphMaker(scratch.getPath(),
104: ReificationStyle.Minimal, true);
105: m.createGraph("example").close();
106: assertEquals(new HashSet(), iteratorToSet(m.listGraphs()));
107: m.close();
108: }
109:
110: public void testDoesntReusedClosedGraphs() {
111: File scratch = FileUtils
112: .getScratchDirectory("jena-test-FileGraphMaker-noReuse");
113: FileGraphMaker m = new FileGraphMaker(scratch.getPath(),
114: ReificationStyle.Minimal, true);
115: Graph m1 = m.createGraph("hello");
116: m1.close();
117: Graph m2 = m.createGraph("hello");
118: assertNotSame(m1, m2);
119: m2.add(triple("this graph isOpen"));
120: m.close();
121: }
122: }
123:
124: /*
125: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
126: All rights reserved.
127:
128: Redistribution and use in source and binary forms, with or without
129: modification, are permitted provided that the following conditions
130: are met:
131:
132: 1. Redistributions of source code must retain the above copyright
133: notice, this list of conditions and the following disclaimer.
134:
135: 2. Redistributions in binary form must reproduce the above copyright
136: notice, this list of conditions and the following disclaimer in the
137: documentation and/or other materials provided with the distribution.
138:
139: 3. The name of the author may not be used to endorse or promote products
140: derived from this software without specific prior written permission.
141:
142: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
143: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
144: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
145: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
146: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
147: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
148: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
149: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
150: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
151: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
152: */
|