Coverage report

  %line %branch
nl.toolforge.karma.core.test.BaseTest
91% 
100% 

 1  
 /*
 2  
 Karma core - Core of the Karma application
 3  
 Copyright (C) 2004  Toolforge <www.toolforge.nl>
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, write to the Free Software
 17  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 */
 19  
 package nl.toolforge.karma.core.test;
 20  
 
 21  
 import junit.framework.TestCase;
 22  
 import nl.toolforge.core.util.file.MyFileUtils;
 23  
 import nl.toolforge.karma.core.boot.WorkingContext;
 24  
 import nl.toolforge.karma.core.boot.WorkingContextConfiguration;
 25  
 import nl.toolforge.karma.core.boot.WorkingContextException;
 26  
 import org.apache.commons.io.FileUtils;
 27  
 
 28  
 import java.io.File;
 29  
 import java.io.IOException;
 30  
 
 31  
 /**
 32  
  * This testclass is highly recommended when writing JUnit testclasses for Karma. It initializes some basic stuff. Just
 33  
  * check this implementation to see how it may help.
 34  
  *
 35  
  * @author D.A. Smedes
 36  
  * @version $Id: BaseTest.java,v 1.38 2004/11/03 21:03:13 asmedes Exp $
 37  
  */
 38  774
 public class BaseTest extends TestCase {
 39  
 
 40  774
   private File wcBaseDir = null;
 41  805
   private File projectBaseDir = null;
 42  805
   private File localRepo = null;
 43  805
   private WorkingContext ctx = null;
 44  62
 
 45  62
   public void setUp() {
 46  62
 
 47  31
     // The following is required to allow the Preferences class to use the test-classpath
 48  
     //
 49  774
     System.setProperty("TESTMODE", "true"); //??
 50  774
     System.setProperty("locale", "en");
 51  
 
 52  31
     try {
 53  836
       wcBaseDir = MyFileUtils.createTempDirectory();
 54  805
       projectBaseDir = MyFileUtils.createTempDirectory();
 55  774
       localRepo = MyFileUtils.createTempDirectory();
 56  31
 
 57  496
       String wc = "test";
 58  836
       ctx = new WorkingContext(wc, wcBaseDir);
 59  31
 
 60  465
       MyFileUtils.writeFile(
 61  31
           ctx.getWorkingContextConfigurationBaseDir(),
 62  371
           new File("test/test-working-context.xml"),
 63  31
           new File("working-context.xml"),
 64  31
           this.getClass().getClassLoader()
 65  371
       );
 66  31
 
 67  465
       WorkingContextConfiguration config = new WorkingContextConfiguration(ctx);
 68  
       try {
 69  465
         config.load();
 70  402
       } catch (WorkingContextException e) {
 71  31
         fail(e.getMessage());
 72  434
       }
 73  774
       ctx.configure(config);
 74  
 
 75  774
       config.setProperty(WorkingContext.PROJECT_BASE_DIRECTORY_PROPERTY, projectBaseDir.getPath());
 76  
 
 77  774
       MyFileUtils.writeFile(WorkingContext.getConfigurationBaseDir(), new File("test/authenticators.xml"), new File("authenticators.xml"), this.getClassLoader());
 78  
 
 79  774
       File mStore = ctx.getConfiguration().getManifestStore().getModule().getBaseDir();
 80  465
       File lStore = ctx.getConfiguration().getLocationStore().getModule().getBaseDir();
 81  402
 
 82  465
       MyFileUtils.writeFile(lStore, new File("test/test-locations.xml"), new File("test-locations.xml"), this.getClassLoader());
 83  805
       MyFileUtils.writeFile(lStore, new File("test/test-locations-2.xml"), new File("test-locations-2.xml"), this.getClassLoader());
 84  402
 
 85  496
       MyFileUtils.writeFile(mStore, new File("test/test-manifest-1.xml"), new File("test-manifest-1.xml"), this.getClassLoader());
 86  836
       MyFileUtils.writeFile(mStore, new File("test/test-manifest-2.xml"), new File("test-manifest-2.xml"), this.getClassLoader());
 87  836
       MyFileUtils.writeFile(mStore, new File("test/test-manifest-3.xml"), new File("test-manifest-3.xml"), this.getClassLoader());
 88  371
 
 89  465
       MyFileUtils.writeFile(mStore, new File("test/included-test-manifest-1.xml"), new File("included-test-manifest-1.xml"), this.getClassLoader());
 90  836
       MyFileUtils.writeFile(mStore, new File("test/included-test-manifest-2.xml"), new File("included-test-manifest-2.xml"), this.getClassLoader());
 91  402
 
 92  62
 
 93  62
     } catch (IOException e) {
 94  31
       e.printStackTrace();
 95  0
       fail(e.getMessage());
 96  774
     }
 97  774
   }
 98  
 
 99  
   public WorkingContext getWorkingContext() {
 100  1018
     return ctx;
 101  31
   }
 102  31
 
 103  31
   public void tearDown() {
 104  31
     try {
 105  805
       MyFileUtils.makeWriteable(wcBaseDir, true);
 106  836
       MyFileUtils.makeWriteable(projectBaseDir, true);
 107  805
       MyFileUtils.makeWriteable(localRepo, true);
 108  31
 
 109  836
       FileUtils.deleteDirectory(wcBaseDir);
 110  805
       FileUtils.deleteDirectory(projectBaseDir);
 111  805
       FileUtils.deleteDirectory(localRepo);
 112  62
     } catch (IOException e) {
 113  62
       fail(e.getMessage());
 114  31
     }
 115  31
     catch (InterruptedException e) {
 116  62
       fail(e.getMessage());
 117  805
     }
 118  774
   }
 119  
 
 120  
   /**
 121  
    * Helper method to retrieve the this class' classloader.
 122  31
    */
 123  62
   public ClassLoader getClassLoader() {
 124  6223
     return this.getClass().getClassLoader();
 125  
   }
 126  37
 
 127  37
 //  /**
 128  
 //   * When this class is run (it is a test class), it won't bother you with 'no tests found'.
 129  
 //   */
 130  
 //  public void testNothing() {
 131  31
 //    assertTrue(true);
 132  62
 //  }
 133  62
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.