001    // This file is part of the program FRYSK.
002    //
003    // Copyright 2005, 2008, Red Hat Inc.
004    //
005    // FRYSK is free software; you can redistribute it and/or modify it
006    // under the terms of the GNU General Public License as published by
007    // the Free Software Foundation; version 2 of the License.
008    //
009    // FRYSK is distributed in the hope that it will be useful, but
010    // WITHOUT ANY WARRANTY; without even the implied warranty of
011    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012    // General Public License for more details.
013    // type filter text
014    // You should have received a copy of the GNU General Public License
015    // along with FRYSK; if not, write to the Free Software Foundation,
016    // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
017    // 
018    // In addition, as a special exception, Red Hat, Inc. gives You the
019    // additional right to link the code of FRYSK with code not covered
020    // under the GNU General Public License ("Non-GPL Code") and to
021    // distribute linked combinations including the two, subject to the
022    // limitations in this paragraph. Non-GPL Code permitted under this
023    // exception must only link to the code of FRYSK through those well
024    // defined interfaces identified in the file named EXCEPTION found in
025    // the source code files (the "Approved Interfaces"). The files of
026    // Non-GPL Code may instantiate templates or use macros or inline
027    // functions from the Approved Interfaces without causing the
028    // resulting work to be covered by the GNU General Public
029    // License. Only Red Hat, Inc. may make changes or additions to the
030    // list of Approved Interfaces. You must obey the GNU General Public
031    // License in all respects for all of the FRYSK code and other code
032    // used in conjunction with FRYSK except the Non-GPL Code covered by
033    // this exception. If you modify this file, you may extend this
034    // exception to your version of the file, but you are not obligated to
035    // do so. If you do not wish to provide this exception without
036    // modification, you must delete this exception statement from your
037    // version and license this file solely under the GPL without
038    // exception.
039    
040    package frysk.gui.test;
041    
042    import java.io.File;
043    
044    import frysk.junit.TestCase;
045    import frysk.testbed.TearDownFile;
046    
047    public class GuiTestCase extends TestCase{
048      public static File TEST_DIR;
049      public static File OBSERVERS_TEST_DIR;
050      public static File SESSIONS_TEST_DIR ;
051      public static File TAGSETS_TEST_DIR;
052      
053    
054        /**
055         * FIXME: Should have a frysk.testbed.TearDownDirectory factory
056         * that handles all this.
057         */
058        private File getFryskTestDir() throws Exception {
059            File file = null;
060            file = TearDownFile.create();
061            
062            String path = file.getAbsolutePath();
063            file.delete();
064            file = new File(path);
065            
066            if(!file.mkdirs()){
067                throw new Exception("Could not create test directory " + file.getAbsolutePath());
068            }
069            
070            // FIXME: deleteOnExit() isn't really reliable; especially
071            // when there's no guarentee that the directory contains no
072            // files; should be a TearDownDirectory object.
073            file.deleteOnExit();
074            return file;
075        }
076    
077      protected void setUp () throws Exception
078      {
079        super.setUp();
080        
081        TEST_DIR = getFryskTestDir();
082        OBSERVERS_TEST_DIR = new File(TEST_DIR.getPath() + "/Observers/");
083        SESSIONS_TEST_DIR = new File(TEST_DIR.getPath() + "/Sessions/");
084        TAGSETS_TEST_DIR = new File(TEST_DIR.getPath() + "/Tagsets/");
085          
086        cleanDir(TEST_DIR);
087        
088        OBSERVERS_TEST_DIR.mkdirs();
089        cleanDir(OBSERVERS_TEST_DIR);
090        
091        SESSIONS_TEST_DIR.mkdirs();
092        cleanDir(SESSIONS_TEST_DIR);
093        
094        TAGSETS_TEST_DIR.mkdirs();
095        cleanDir(TAGSETS_TEST_DIR);
096      }
097            
098      protected void tearDown () throws Exception
099      {
100        super.tearDown();
101        
102        cleanDir(TEST_DIR);
103        TEST_DIR.delete();
104        
105        cleanDir(OBSERVERS_TEST_DIR);
106        OBSERVERS_TEST_DIR.delete();
107        
108        cleanDir(SESSIONS_TEST_DIR);
109        SESSIONS_TEST_DIR.delete();
110        
111        cleanDir(TAGSETS_TEST_DIR);
112        TAGSETS_TEST_DIR.delete();
113        
114      }
115            
116      public void cleanDir(File dir){
117        File[] files = dir.listFiles();
118        if(files!=null){
119          for (int i = 0; i < files.length; i++){
120            files[i].delete();
121          }
122        }
123      }
124      
125    }