woolfel     2005/09/05 11:30:36

  Modified:    src/junit/org/apache/jmeter/protocol/java/control/gui Tag:
                        rel-2-1 JUnitTestSamplerGui.java
               src/junit/org/apache/jmeter/protocol/java/sampler Tag:
                        rel-2-1 JUnitSampler.java
  Log:
  now the sampler handles constructor correctly, using isAccessible was wrong 
and results
  in NPE.
  peter
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.13.2.3  +8 -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.13.2.2
  retrieving revision 1.13.2.3
  diff -u -r1.13.2.2 -r1.13.2.3
  --- JUnitTestSamplerGui.java  4 Sep 2005 17:02:10 -0000       1.13.2.2
  +++ JUnitTestSamplerGui.java  5 Sep 2005 18:30:36 -0000       1.13.2.3
  @@ -27,6 +27,7 @@
   import javax.swing.JCheckBox;
   import javax.swing.JComboBox;
   import javax.swing.JLabel;
  +import javax.swing.JOptionPane;
   import javax.swing.JPanel;
   import javax.swing.event.ChangeEvent;
   import javax.swing.event.ChangeListener;
  @@ -289,6 +290,12 @@
           }
       }
   
  +    public void showErrorDialog() {
  +        JOptionPane.showConfirmDialog(this, 
  +                JMeterUtils.getResString("junit_constructor_error"), 
"Warning",
  +                JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
  +    }
  +    
       public void configureMethodCombo(){
           if (TESTCLASS != null) {
               clearMethodCombo();
  
  
  
  No                   revision
  No                   revision
  1.11.2.3  +11 -6     
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.2.2
  retrieving revision 1.11.2.3
  diff -u -r1.11.2.2 -r1.11.2.3
  --- JUnitSampler.java 2 Sep 2005 01:08:30 -0000       1.11.2.2
  +++ JUnitSampler.java 5 Sep 2005 18:30:36 -0000       1.11.2.3
  @@ -390,6 +390,7 @@
           Object testclass = null;
           if (className != null){
               Constructor con = null;
  +            Constructor strCon = null;
               Class theclazz = null;
               Object[] params = null;
               try
  @@ -407,16 +408,15 @@
                   // constructor. if it is doesn't we look for
                   // empty constructor.
                   try {
  -                    con = theclazz.getDeclaredConstructor(
  +                    strCon = theclazz.getDeclaredConstructor(
                               new Class[] {String.class});
                       // we have to check and make sure the constructor is
                       // accessible. if we didn't it would throw an exception
                       // and cause a NPE.
  -                    if (con.isAccessible()) {
  -                        params = new Object[]{label};
  -                    } else {
  -                        con = null;
  +                    if (label == null || label.length() == 0) {
  +                        label = className;
                       }
  +                    params = new Object[]{label};
                   } catch (NoSuchMethodException e) {
                       log.info("String constructor:: " + e.getMessage());
                   }
  @@ -431,7 +431,12 @@
                       }
                   }
                   try {
  -                    if (con != null){
  +                    // if the string constructor is not null, we use it.
  +                    // if the string constructor is null, we use the empty
  +                    // constructor to get a new instance
  +                    if (strCon != null) {
  +                        testclass = (TestCase)strCon.newInstance(params);
  +                    } else if (con != null){
                           testclass = (TestCase)con.newInstance(params);
                       }
                   } catch (InvocationTargetException e) {
  
  
  

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

Reply via email to