KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > BaseTestCase


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 /*
14  * Created on Jun 18, 2003
15  *
16  */

17 package com.openedit;
18
19 import java.io.File JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import com.openedit.modules.BaseModule;
24 import com.openedit.page.Page;
25
26
27 /**
28  * DOCUMENT ME!
29  *
30  * @author cburkey
31  */

32 public class BaseTestCase extends TestCase
33 {
34     protected TestFixture fieldFixture;
35
36     /**
37      *
38      */

39     public BaseTestCase()
40     {
41         super(""); //this is not needed in newer versions of JUnit
42
}
43     /**
44      * Constructor for BaseTestCase.
45      *
46      * @param arg0
47      */

48     public BaseTestCase(String JavaDoc arg0)
49     {
50         super(arg0);
51     }
52
53     public Page getPage( String JavaDoc inPath ) throws OpenEditException
54     {
55         return getFixture().getPageManager().getPage( inPath );
56     }
57     /**
58      * DOCUMENT ME!
59      *
60      * @param inFixture
61      */

62     public void setFixture(TestFixture inFixture)
63     {
64         fieldFixture = inFixture;
65     }
66
67     /**
68      * DOCUMENT ME!
69      *
70      * @return
71      */

72     public TestFixture getFixture()
73     {
74         if (fieldFixture == null)
75         {
76             fieldFixture = new TestFixture();
77         }
78         return fieldFixture;
79     }
80     protected void tearDown() throws Exception JavaDoc
81     {
82         super.tearDown();
83         if ( fieldFixture != null)
84         {
85             getFixture().getWebServer().getOpenEditEngine().shutdown();
86         }
87     }
88     /** Delete the specified directory and all files within it */
89     protected void deleteDirectory(File JavaDoc directory)
90     {
91         File JavaDoc[] containedFiles = directory.listFiles();
92         if (containedFiles != null)
93         {
94             for (int n = 0; n < containedFiles.length; n++)
95             {
96                 File JavaDoc file = containedFiles[ n ];
97                 if (file.isDirectory())
98                 {
99                     deleteDirectory( file );
100                 }
101                 else
102                 {
103                     file.delete();
104                 }
105             }
106         }
107         directory.delete();
108     }
109     
110     protected File JavaDoc getRoot()
111     {
112         return getFixture().getWebServer().getRootDirectory();
113     }
114     
115     protected BaseModule getModule( String JavaDoc inKey )
116     {
117         return getFixture().getModuleManager().getModule( inKey );
118     }
119     
120     protected Object JavaDoc getBean( String JavaDoc inKey )
121     {
122         return getFixture().getModuleManager().getBean( inKey );
123     }
124 }
125
Popular Tags