KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > junit > JMeterTestCase


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/junit/JMeterTestCase.java,v 1.11.2.1 2004/11/03 00:16:54 sebb 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 JavaDoc;
22 import java.util.MissingResourceException JavaDoc;
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 {
37     // Used by findTestFile
38
private static final String JavaDoc filePrefix;
39     public JMeterTestCase(){
40         super();
41     }
42     
43     public JMeterTestCase(String JavaDoc name)
44     {
45         super(name);
46     }
47     
48     /*
49      * If not running under AllTests.java, make sure that the properties
50      * (and log file) are set up correctly.
51      *
52      * N.B. In order for this to work correctly, the JUnit test must be started
53      * in the bin directory, and all the JMeter jars (plus any others needed at
54      * run-time) need to be on the classpath.
55      *
56      */

57     static {
58         if (JMeterUtils.getJMeterProperties() == null){
59             String JavaDoc file="jmetertest.properties";
60             File JavaDoc f = new File JavaDoc(file);
61             if (!f.canRead()){
62                 System.out.println("Can't find "+file+" - trying bin directory");
63                 file="bin/"+file;// JMeterUtils assumes Unix-style 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 JavaDoc 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 JavaDoc prop)
99     {
100         System.out.println(prop+"="+System.getProperty(prop));
101     }
102
103     // Helper method to find a file
104
protected static File JavaDoc findTestFile(String JavaDoc file)
105     {
106         File JavaDoc f= new File JavaDoc(file);
107         if (filePrefix.length() > 0 && !f.isAbsolute())
108         {
109             f= new File JavaDoc(filePrefix+file);// Add the offset
110
}
111         return f;
112     }
113
114     protected static final Logger testLog = LoggingManager.getLoggerForClass();
115 }
116
117
Popular Tags