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/11/18 16:37:53 UTC

svn commit: r345503 - in /jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java: control/gui/JUnitTestSamplerGui.java sampler/JUnitSampler.java

Author: woolfel
Date: Fri Nov 18 07:37:49 2005
New Revision: 345503

URL: http://svn.apache.org/viewcvs?rev=345503&view=rev
Log:
I've enhanced the sampler with 2 new options. Now by default, the sampler will not append the junit error and exception to the message.
To see the message, users have to explicitly check it in the sampler. This was done so that those using jmeter in CSV format will see the results in one line.
peter

Modified:
    jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
    jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java

Modified: jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java?rev=345503&r1=345502&r2=345503&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java Fri Nov 18 07:37:49 2005
@@ -103,6 +103,8 @@
             JMeterUtils.getResString("junit_pkg_filter"));
 
     JCheckBox doSetup = new JCheckBox(JMeterUtils.getResString("junit_do_setup_teardown"));
+    JCheckBox appendError = new JCheckBox(JMeterUtils.getResString("junit_append_error"));
+    JCheckBox appendExc = new JCheckBox(JMeterUtils.getResString("junit_append_exception"));
     
     /** A combo box allowing the user to choose a test class. */
     private JComboBox classnameCombo;
@@ -205,6 +207,8 @@
         panel.add(errorMsg);
         panel.add(errorCode);
         panel.add(doSetup);
+        panel.add(appendError);
+        panel.add(appendExc);
         return panel;
     }
 
@@ -237,6 +241,8 @@
         sampler.setFailure(failureMsg.getText());
         sampler.setFailureCode(failureCode.getText());
         sampler.setDoNotSetUpTearDown(doSetup.isSelected());
+        sampler.setAppendError(appendError.isSelected());
+        sampler.setAppendException(appendExc.isSelected());
     }
 
     /* Overrides AbstractJMeterGuiComponent.configure(TestElement) */
@@ -280,6 +286,8 @@
             errorCode.setText(JMeterUtils.getResString("junit_error_default_code"));
         }
         doSetup.setSelected(sampler.getDoNotSetUpTearDown());
+        appendError.setSelected(sampler.getAppendError());
+        appendExc.setSelected(sampler.getAppendException());
     }
     
     public void instantiateClass(){

Modified: jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java?rev=345503&r1=345502&r2=345503&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/junit/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java Fri Nov 18 07:37:49 2005
@@ -59,6 +59,8 @@
     public static final String SUCCESSCODE = "junitsampler.success.code";
     public static final String FILTER = "junitsampler.pkg.filter";
     public static final String DOSETUP = "junitsampler.exec.setup";
+    public static final String APPEND_ERROR = "junitsampler.append.error";
+    public static final String APPEND_EXCEPTION = "junitsampler.append.exception";
     
     public static final String SETUP = "setUp";
     public static final String TEARDOWN = "tearDown";
@@ -269,13 +271,52 @@
         setProperty(FILTER,text);
     }
     
+    /**
+     * if the sample shouldn't call setup/teardown, the
+     * method returns true. It's meant for onetimesetup
+     * and onetimeteardown.
+     * @return
+     */
     public boolean getDoNotSetUpTearDown(){
         return getPropertyAsBoolean(DOSETUP);
     }
-    
+
+    /**
+     * set the setup/teardown option
+     * @param setup
+     */
     public void setDoNotSetUpTearDown(boolean setup){
         setProperty(DOSETUP,String.valueOf(setup));
     }
+
+    /**
+     * If append error is not set, by default it is set to false,
+     * which means users have to explicitly set the sampler to
+     * append the assert errors. Because of how junit works, there
+     * should only be one error
+     * @return
+     */
+    public boolean getAppendError() {
+        return getPropertyAsBoolean(APPEND_ERROR,false);
+    }
+    
+    public void setAppendError(boolean error) {
+        setProperty(APPEND_ERROR,String.valueOf(error));
+    }
+
+    /**
+     * If append exception is not set, by default it is set to false.
+     * Users have to explicitly set it to true to see the exceptions
+     * in the result tree.
+     * @return
+     */
+    public boolean getAppendException() {
+        return getPropertyAsBoolean(APPEND_EXCEPTION,false);
+    }
+    
+    public void setAppendException(boolean exc) {
+        setProperty(APPEND_EXCEPTION,String.valueOf(exc));
+    }
     
     /* (non-Javadoc)
 	 * @see org.apache.jmeter.samplers.Sampler#sample(org.apache.jmeter.samplers.Entry)
@@ -362,16 +403,16 @@
             if ( !tr.wasSuccessful() ){
                 sresult.setSuccessful(false);
                 StringBuffer buf = new StringBuffer();
-                buf.append(getFailure() + System.getProperty("line.separator"));
+                buf.append( getFailure() );
                 Enumeration en = tr.errors();
                 while (en.hasMoreElements()){
                     Object item = en.nextElement();
-                    if (item instanceof TestFailure) {
+                    if (getAppendError() && item instanceof TestFailure) {
                         buf.append( "Trace -- ");
                         buf.append( ((TestFailure)item).trace() );
                         buf.append( "Failure -- ");
                         buf.append( ((TestFailure)item).toString() );
-                    } else if (item instanceof Throwable) {
+                    } else if (getAppendException() && item instanceof Throwable) {
                         buf.append( ((Throwable)item).getMessage() );
                     }
                 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org