You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by wo...@apache.org on 2005/09/02 02:59:24 UTC
cvs commit: jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/sampler JUnitSampler.java
woolfel 2005/09/01 17:59:24
Added: src/junit/org/apache/jmeter/protocol/java/control/gui Tag:
rel-2-1 JUnitTestSamplerGui.java ClassFilter.java
src/junit/org/apache/jmeter/protocol/java/sampler Tag:
rel-2-1 JUnitSampler.java
Log:
adding the JUnitSampler classes to 2.1 branch
peter
Revision Changes Path
No revision
No revision
1.13.2.1 +1 -1 jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
1.2.2.1 +0 -0 jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/control/gui/ClassFilter.java
No revision
No revision
1.11.2.1 +40 -5 jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java
Index: JUnitSampler.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -r1.11 -r1.11.2.1
--- JUnitSampler.java 25 Aug 2005 21:08:49 -0000 1.11
+++ JUnitSampler.java 2 Sep 2005 00:59:24 -0000 1.11.2.1
@@ -21,6 +21,7 @@
import java.lang.reflect.Method;
import java.util.Enumeration;
+import junit.framework.ComparisonFailure;
import junit.framework.TestCase;
import junit.framework.TestResult;
@@ -58,9 +59,11 @@
public static final String SETUP = "setUp";
public static final String TEARDOWN = "tearDown";
+ public static final String RUNTEST = "run";
/// the Method objects for setUp and tearDown methods
protected Method SETUP_METHOD = null;
protected Method TDOWN_METHOD = null;
+ protected Method RUN_METHOD = null;
protected boolean checkStartUpTearDown = false;
protected TestCase TEST_INSTANCE = null;
@@ -295,15 +298,24 @@
initMethodObjects(this.TEST_INSTANCE);
// create a new TestResult
TestResult tr = new TestResult();
+ this.TEST_INSTANCE.setName(getMethod());
try {
if (!getDoNotSetUpTearDown() && SETUP_METHOD != null){
- SETUP_METHOD.invoke(TEST_INSTANCE,new Class[0]);
+ SETUP_METHOD.invoke(this.TEST_INSTANCE,new Class[0]);
}
- Method m = getMethod(TEST_INSTANCE,getMethod());
+ if (RUN_METHOD == null) {
+ RUN_METHOD = getRunTestMethod(this.TEST_INSTANCE);
+ }
+ Method m = getMethod(this.TEST_INSTANCE,getMethod());
sresult.sampleStart();
- m.invoke(TEST_INSTANCE,null);
+ // use runTest method to run the test instead of the method directly
+ if (RUN_METHOD != null) {
+ Object[] p = {tr};
+ RUN_METHOD.invoke(this.TEST_INSTANCE,p);
+ } else {
+ m.invoke(this.TEST_INSTANCE,new Class[0]);
+ }
sresult.sampleEnd();
- // log.info("invoked " + getMethod());
if (!getDoNotSetUpTearDown() && TDOWN_METHOD != null){
TDOWN_METHOD.invoke(TEST_INSTANCE,new Class[0]);
}
@@ -319,6 +331,11 @@
sresult.setResponseMessage(getError());
sresult.setResponseData(e.getMessage().getBytes());
sresult.setSuccessful(false);
+ } catch (ComparisonFailure e) {
+ sresult.setResponseCode(getErrorCode());
+ sresult.setResponseMessage(getError());
+ sresult.setResponseData(e.getMessage().getBytes());
+ sresult.setSuccessful(false);
} catch (IllegalArgumentException e) {
sresult.setResponseCode(getErrorCode());
sresult.setResponseMessage(getError());
@@ -389,7 +406,11 @@
try {
con = theclazz.getDeclaredConstructor(
new Class[] {String.class});
- params = new Object[]{label};
+ if (con.isAccessible()) {
+ params = new Object[]{label};
+ } else {
+ con = null;
+ }
} catch (NoSuchMethodException e) {
log.info("String constructor:: " + e.getMessage());
}
@@ -437,4 +458,18 @@
}
return null;
}
+
+ public Method getRunTestMethod(Object clazz){
+ if (clazz != null){
+ log.info("class " + clazz.getClass().getName() +
+ " method name is " + RUNTEST);
+ try {
+ Class[] param = {TestResult.class};
+ return clazz.getClass().getMethod(RUNTEST,param);
+ } catch (NoSuchMethodException e) {
+ log.warn(e.getMessage());
+ }
+ }
+ return null;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org