1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/junit/JMeterTestCase.java,v 1.13 2005/07/12 20:50:50 mstover1 Exp $ 2 /* 3 * Copyright 2003-2004 The Apache Software Foundation. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package org.apache.jmeter.junit; 20 21 import java.io.File; 22 import java.util.MissingResourceException; 23 24 import junit.framework.TestCase; 25 import org.apache.jmeter.util.JMeterUtils; 26 import org.apache.jorphan.logging.LoggingManager; 27 import org.apache.log.Logger; 28 29 /** 30 * @author ano ano 31 * 32 * To change the template for this generated type comment go to 33 * Window>Preferences>Java>Code Generation>Code and Comments 34 */ 35 public abstract class JMeterTestCase extends TestCase { 36 // Used by findTestFile 37 private static final String filePrefix; 38 39 public JMeterTestCase() { 40 super(); 41 } 42 43 public JMeterTestCase(String name) { 44 super(name); 45 } 46 47 /* 48 * If not running under AllTests.java, make sure that the properties (and 49 * log file) are set up correctly. 50 * 51 * N.B. In order for this to work correctly, the JUnit test must be started 52 * in the bin directory, and all the JMeter jars (plus any others needed at 53 * run-time) need to be on the classpath. 54 * 55 */ 56 static { 57 if (JMeterUtils.getJMeterProperties() == null) { 58 String file = "jmetertest.properties"; 59 File f = new File(file); 60 if (!f.canRead()) { 61 System.out.println("Can't find " + file + " - trying bin directory"); 62 file = "bin/" + file;// JMeterUtils assumes Unix-style 63 // separators 64 // Also need to set working directory so test files can be found 65 System.setProperty("user.dir", System.getProperty("user.dir") + File.separatorChar + "bin"); 66 System.out.println("Setting user.dir=" + System.getProperty("user.dir")); 67 filePrefix = "bin/"; 68 } else { 69 filePrefix = ""; 70 } 71 JMeterUtils jmu = new JMeterUtils(); 72 try { 73 jmu.initializeProperties(file); 74 } catch (MissingResourceException e) { 75 System.out.println("** Can't find resources - continuing anyway **"); 76 } 77 logprop("java.version"); 78 logprop("java.vendor"); 79 logprop("java.home"); 80 logprop("user.home"); 81 logprop("user.dir"); 82 logprop("java.class.version"); 83 logprop("os.name"); 84 logprop("os.version"); 85 logprop("os.arch"); 86 logprop("java.class.path"); 87 // String cp = System.getProperty("java.class.path"); 88 // String cpe[]= JOrphanUtils.split(cp,File.pathSeparator); 89 // System.out.println("java.class.path="); 90 // for (int i=0;i<cpe.length;i++){ 91 // System.out.println(cpe[i]); 92 // } 93 } else { 94 filePrefix = ""; 95 } 96 } 97 98 private static void logprop(String prop) { 99 System.out.println(prop + "=" + System.getProperty(prop)); 100 } 101 102 // Helper method to find a file 103 protected static File findTestFile(String file) { 104 File f = new File(file); 105 if (filePrefix.length() > 0 && !f.isAbsolute()) { 106 f = new File(filePrefix + file);// Add the offset 107 } 108 return f; 109 } 110 111 protected static final Logger testLog = LoggingManager.getLoggerForClass(); 112 }