woolfel     2005/08/03 20:34:10

  Modified:    src/junit/org/apache/jmeter/protocol/java/sampler
                        JUnitSampler.java
               src/junit/org/apache/jmeter/protocol/java/control/gui
                        JUnitTestSamplerGui.java
  Log:
  enhanced the JUnit sampler with error message and code. test plans written 
with
  previous builds should still work.
  peter
  
  Revision  Changes    Path
  1.8       +46 -2     
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JUnitSampler.java 3 Aug 2005 04:33:28 -0000       1.7
  +++ JUnitSampler.java 4 Aug 2005 03:34:10 -0000       1.8
  @@ -46,6 +46,8 @@
        */
       public static final String CLASSNAME = "junitSampler.classname";
       public static final String METHOD = "junitsampler.method";
  +    public static final String ERROR = "junitsampler.error";
  +    public static final String ERRORCODE = "junitsampler.error.code";
       public static final String FAILURE = "junitsampler.failure";
       public static final String FAILURECODE = "junitsampler.failure.code";
       public static final String SUCCESS = "junitsampler.success";
  @@ -190,6 +192,43 @@
       }
   
       /**
  +     * return the descriptive error for the test
  +     * @return
  +     */
  +    public String getError(){
  +        return getPropertyAsString(ERROR);
  +    }
  +    
  +    /**
  +     * provide a descriptive error for the test method. For
  +     * a description of the difference between failure and
  +     * error, please refer to the following url
  +     * http://junit.sourceforge.net/doc/faq/faq.htm#tests_9
  +     * @param error
  +     */
  +    public void setError(String error){
  +        setProperty(ERROR,error);
  +    }
  +    
  +    /**
  +     * return the error code for the test method. it should
  +     * be an unique error code.
  +     * @return
  +     */
  +    public String getErrorCode(){
  +        return getPropertyAsString(ERRORCODE);
  +    }
  +    
  +    /**
  +     * provide an unique error code for when the test
  +     * does not pass the assert test.
  +     * @param code
  +     */
  +    public void setErrorCode(String code){
  +        setProperty(ERRORCODE,code);
  +    }
  +    
  +    /**
        * return the comma separated string for the filter
        * @return
        */
  @@ -233,7 +272,6 @@
               try {
                   if (!getDoNotSetUpTearDown() && SETUP_METHOD != null){
                       SETUP_METHOD.invoke(TEST_INSTANCE,new Class[0]);
  -                    log.info("called setUp");
                   }
                   Method m = getMethod(TEST_INSTANCE,getMethod());
                   sresult.sampleStart();
  @@ -242,12 +280,18 @@
                   // log.info("invoked " + getMethod());
                   if (!getDoNotSetUpTearDown() && TDOWN_METHOD != null){
                       TDOWN_METHOD.invoke(TEST_INSTANCE,new Class[0]);
  -                    log.info("called tearDown");
                   }
               } catch (InvocationTargetException e) {
                   log.warn(e.getMessage());
  +                sresult.setResponseCode(getErrorCode());
  +                sresult.setResponseMessage(getError());
               } catch (IllegalAccessException e) {
                   log.warn(e.getMessage());
  +                sresult.setResponseCode(getErrorCode());
  +                sresult.setResponseMessage(getError());
  +            } catch (Exception e) {
  +                sresult.setResponseCode(getErrorCode());
  +                sresult.setResponseMessage(getError());
               }
               if ( !tr.wasSuccessful() ){
                   sresult.setSuccessful(false);
  
  
  
  1.10      +21 -1     
jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
  
  Index: JUnitTestSamplerGui.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JUnitTestSamplerGui.java  3 Aug 2005 04:33:28 -0000       1.9
  +++ JUnitTestSamplerGui.java  4 Aug 2005 03:34:10 -0000       1.10
  @@ -73,6 +73,10 @@
           new JLabeledTextField(
               JMeterUtils.getResString("junit_failure_msg"));
       
  +    JLabeledTextField errorMsg =
  +        new JLabeledTextField(
  +            JMeterUtils.getResString("junit_error_msg"));
  +
       JLabeledTextField successCode =
           new JLabeledTextField(
               JMeterUtils.getResString("junit_success_code"));
  @@ -81,6 +85,10 @@
           new JLabeledTextField(
               JMeterUtils.getResString("junit_failure_code"));
   
  +    JLabeledTextField errorCode =
  +        new JLabeledTextField(
  +            JMeterUtils.getResString("junit_error_code"));
  +
       JLabeledTextField filterpkg =
           new JLabeledTextField(
               JMeterUtils.getResString("junit_pkg_filter"));
  @@ -179,6 +187,8 @@
           panel.add(successCode);
           panel.add(failureMsg);
           panel.add(failureCode);
  +        panel.add(errorMsg);
  +        panel.add(errorCode);
           panel.add(doSetup);
           return panel;
       }
  @@ -242,6 +252,16 @@
           } else {
               
failureMsg.setText(JMeterUtils.getResString("junit_failure_default_msg"));
           }
  +        if (sampler.getError().length() > 0) {
  +            errorMsg.setText(sampler.getError());
  +        } else {
  +            
errorMsg.setText(JMeterUtils.getResString("junit_error_default_msg"));
  +        }
  +        if (sampler.getErrorCode().length() > 0) {
  +            errorCode.setText(sampler.getErrorCode());
  +        } else {
  +            
errorCode.setText(JMeterUtils.getResString("junit_error_default_code"));
  +        }
           doSetup.setSelected(sampler.getDoNotSetUpTearDown());
       }
       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to