001: /*
002: * Bossa Workflow System
003: *
004: * $Id: SlowFileTests.java,v 1.1 2004/01/16 20:42:56 gdvieira Exp $
005: *
006: * Copyright (C) 2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa;
026:
027: import java.io.File;
028:
029: import junit.framework.TestCase;
030:
031: import com.bigbross.bossa.resource.Resource;
032: import com.bigbross.bossa.wfnet.WorkItem;
033:
034: public class SlowFileTests extends TestCase {
035:
036: private String testDirName;
037: private File testDir;
038:
039: public SlowFileTests(String name) {
040: super (name);
041: testDirName = "build/TestDir";
042: testDir = new File(testDirName);
043: }
044:
045: private boolean createTestDir() {
046: return testDir.mkdir();
047: }
048:
049: private boolean removeTestDir() {
050: if (testDir.exists()) {
051: File[] contents = testDir.listFiles();
052: for (int i = 0; i < contents.length; i++) {
053: if (!contents[i].delete()) {
054: return false;
055: }
056: }
057: return testDir.delete();
058: } else {
059: return true;
060: }
061: }
062:
063: protected void setUp() {
064: assertTrue(removeTestDir());
065: assertTrue(createTestDir());
066: }
067:
068: protected void tearDown() {
069: assertTrue(removeTestDir());
070: }
071:
072: public void testPersistentBossa() throws Exception {
073: BossaFactory factory = new BossaFactory();
074: factory.setStateDir(testDirName);
075: Bossa bossa = factory.createBossa();
076: BossaTestUtil.setupTestBossa(bossa);
077:
078: Resource r = bossa.getResourceManager().getResource("frank");
079: WorkItem wi = (WorkItem) bossa.getWorkManager().getWorkItems(r,
080: true).get(0);
081: wi.open(r).close();
082:
083: bossa = null;
084: r = null;
085: wi = null;
086: bossa = factory.createBossa();
087:
088: assertEquals(1, bossa.getCaseTypeManager().getCaseTypes()
089: .size());
090: assertEquals(3, bossa.getResourceManager().getResources()
091: .size());
092: assertEquals(1, bossa.getCaseTypeManager().getCaseType("test")
093: .getCases().size());
094: assertEquals(1, bossa.getCaseTypeManager().getWorkItems()
095: .size());
096:
097: r = bossa.getResourceManager().getResource("sally");
098: wi = (WorkItem) bossa.getWorkManager().getWorkItems(r).get(0);
099: wi.open(r).close();
100: bossa.takeSnapshot();
101:
102: bossa = null;
103: r = null;
104: wi = null;
105: bossa = factory.createBossa();
106:
107: r = bossa.getResourceManager().getResource("frank");
108: wi = (WorkItem) bossa.getWorkManager().getWorkItems(r).get(0);
109: wi.open(r).close();
110:
111: assertEquals(0, bossa.getCaseTypeManager().getCaseType("test")
112: .getCases().size());
113: }
114: }
|