mstover1    2002/12/11 08:07:08

  Modified:    .        build.xml
               lib      jorphan.jar
               src/core/org/apache/jmeter/resources messages.properties
                        messages_de.properties messages_ja.properties
                        messages_no.properties
  Added:       src/components/org/apache/jmeter/assertions
                        SizeAssertion.java
               src/components/org/apache/jmeter/assertions/gui
                        SizeAssertionGui.java
  Log:
  New Size Assertion (Drew Gulino)
  
  Revision  Changes    Path
  1.75      +1 -5      jakarta-jmeter/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/build.xml,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- build.xml 17 Oct 2002 19:47:14 -0000      1.74
  +++ build.xml 11 Dec 2002 16:07:08 -0000      1.75
  @@ -42,10 +42,6 @@
   
     <path id="testClasspath">
                <path refid="classpath"/>
  -             <fileset dir="./lib/ext">
  -                     <include name="*.jar"/>
  -                     <include name="*.jar"/>
  -             </fileset>
     </path>
     
     <path id="srcpaths">
  @@ -439,7 +435,7 @@
        </target>
   
        <target name="test" depends="install">
  -       <java classname="org.jorphan.test.AllTests" fork="yes" dir="${basedir}/bin">
  +       <java classname="org.apache.jorphan.test.AllTests" fork="yes" 
dir="${basedir}/bin">
                 <classpath refid="testClasspath"/>
                 <arg value="../lib/ext"/>
                 <arg value="./jmeter.properties"/>
  
  
  
  1.4       +61 -61    jakarta-jmeter/lib/jorphan.jar
  
        <<Binary file>>
  
  
  1.1                  
jakarta-jmeter/src/components/org/apache/jmeter/assertions/SizeAssertion.java
  
  Index: SizeAssertion.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.jmeter.assertions;
  
  import java.io.Serializable;
  import java.text.MessageFormat;
  import org.apache.jmeter.util.JMeterUtils;
  import org.apache.jmeter.testelement.AbstractTestElement;
  import org.apache.jmeter.samplers.SampleResult;
  
  /**
   * Checks if an Sample is sampled within a specified time-frame. If the
   * duration is larger than the timeframe the Assertion is considered
   * a failure.
   *
   Copyright: Copyright (c) 2001
   * Company: Apache
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Wolfram Rittmeyer</a>
   *
   * @version $Revision: 1.1 $, $Date: 2002/12/11 16:07:08 $
   */
  public class SizeAssertion extends AbstractTestElement implements Serializable, 
Assertion {
  
        /** Key for storing assertion-informations in the jmx-file. */
        private static final String SIZE_KEY = "SizeAssertion.size";
        byte[] resultData;
        /**
         * Returns the result of the Assertion. Here it checks wether the
         * Sample took to long to be considered successful. If so an AssertionResult
         * containing a FailureMessage will be returned. Otherwise the returned
         * AssertionResult will reflect the success of the Sample.
         */
        public AssertionResult getResult(SampleResult response) {
                AssertionResult result = new AssertionResult();
                result.setFailure(false);
  
                // is the Sample the correct size?
                resultData = getResultBody(response.getResponseData());
                long resultSize = resultData.length;
                if (((resultSize != getAllowedSize()) && (getAllowedSize() > 0))) {
                        result.setFailure(true);
                        Object[] arguments = { new Long(resultSize), new 
Long(getAllowedSize())};
                        String message = 
MessageFormat.format(JMeterUtils.getResString("size_assertion_failure"), arguments);
                        result.setFailureMessage(message);
                }
                return result;
        }
  
        /**
         * Returns the size in bytes to be asserted. A duration of 0 indicates this 
assertion is to 
         * be ignored.
         */
        public long getAllowedSize() {
                return getPropertyAsLong(SIZE_KEY);
        }
  
        /**
         * Set the size that shall be asserted.
         *
         * @param duration A number of bytes. Is not allowed to be negative. Use 
Double.MAX_VALUE to indicate illegal or empty inputs. This will result to not checking 
the assertion.
         *
         * @throws IllegalArgumentException If <code>duration</code> is negative.
         */
        public void setAllowedSize(long size) throws IllegalArgumentException {
                if (size < 0L) {
                        throw new 
IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative"));
                }
                if (size == Long.MAX_VALUE) {
                        setProperty(SIZE_KEY, new Long(0));
                }
                else {
                        setProperty(SIZE_KEY, new Long(size));
                }
        }
  
        /**
         * Return the body of the http return.
         *
         * 
         *
         * 
         */
        private byte[] getResultBody(byte[] resultData) {
                for (int i = 0; i < (resultData.length - 1) ; i++) {
                        if (resultData[i] == '\n' && resultData[i+1] == '\n') {
                                return 
getByteArraySlice(resultData,(i+3),resultData.length);
                        }
                }
                return resultData;
        }
         
        /**
         * Return a slice of a byte array
         *
         * 
         *
         * 
         */
        private byte[] getByteArraySlice(byte[] array, int begin, int end) {
                byte[] slice = new byte [(end - begin  + 1)];
                int count = 0;
                for (int i = begin; i < end ; i++) {
                        slice[count] = array[i];
                        count++;
                }
                return slice;
        }        
  
  }  
  
  
  1.1                  
jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/SizeAssertionGui.java
  
  Index: SizeAssertionGui.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.jmeter.assertions.gui;
  
  import java.awt.FlowLayout;
  import java.awt.Font;
  import java.awt.event.FocusEvent;
  import java.awt.event.FocusListener;
  
  import javax.swing.BorderFactory;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  import javax.swing.border.Border;
  import javax.swing.border.EmptyBorder;
  
  import org.apache.jmeter.assertions.SizeAssertion;
  import org.apache.jmeter.testelement.TestElement;
  import org.apache.jmeter.util.JMeterUtils;
  import org.apache.log.Hierarchy;
  import org.apache.log.Logger;
  import org.apache.jorphan.gui.layout.VerticalLayout;
  
  
  /****************************************
   * Title: Jakarta-JMeter Description: Copyright: Copyright (c) 2001 Company:
   * Apache
   *
   *@author    Michael Stover
   *@created   $Date: 2002/12/11 16:07:08 $
   *@version   1.0
   ***************************************/
  
  public class SizeAssertionGui extends AbstractAssertionGui implements FocusListener
  {
        transient private static Logger log = 
Hierarchy.getDefaultHierarchy().getLoggerFor(
                        "jmeter.elements");
  
        private JTextField size;
  
        /****************************************
         * !ToDo (Constructor description)
         ***************************************/
        public SizeAssertionGui()
        {
                init();
        }
  
        /**
         * Returns the label to be shown within the JTree-Component.
         */
        public String getStaticLabel()
        {
                return JMeterUtils.getResString("size_assertion_title");
        }
  
        public String getSizeAttributesTitle()
        {
                return JMeterUtils.getResString("size_assertion_size_test");
        }
  
        public TestElement createTestElement()
        {
                //ResponseAssertion el = new ResponseAssertion();
                SizeAssertion el = new SizeAssertion();
                configureTestElement(el);
                String sizeString = size.getText();
                long assertionSize = 0;
                try {
                        assertionSize = Long.parseLong(sizeString);
                }
                catch (NumberFormatException e) {
                        assertionSize = Long.MAX_VALUE;
                }
                el.setAllowedSize(assertionSize);
                return el;
        }
  
        /****************************************
         * !ToDo (Method description)
         ***************************************/
        public void configure(TestElement el)
        {
                super.configure(el);
                SizeAssertion assertion = (SizeAssertion)el;
                size.setText(String.valueOf(assertion.getAllowedSize()));
        }
  
        private void init()
        {
                this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, 
VerticalLayout.TOP));
  
                // MAIN PANEL
                JPanel mainPanel = new JPanel();
                Border margin = new EmptyBorder(10, 10, 5, 10);
                mainPanel.setBorder(margin);
                mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
  
                // TITLE
                JLabel panelTitleLabel = new JLabel(getStaticLabel());
                Font curFont = panelTitleLabel.getFont();
                int curFontSize = curFont.getSize();
                curFontSize += 4;
                panelTitleLabel.setFont(new Font(curFont.getFontName(), 
curFont.getStyle(), curFontSize));
                mainPanel.add(panelTitleLabel);
  
                // NAME
                mainPanel.add(getNamePanel());
  
                // USER_INPUT
                JPanel sizePanel = new JPanel();
                
sizePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
 getSizeAttributesTitle()));
                FlowLayout layout = new FlowLayout();
                sizePanel.setLayout(layout);
  
                sizePanel.add(new 
JLabel(JMeterUtils.getResString("size_assertion_label")));
                size = new JTextField(5);
                size.addFocusListener(this);
                sizePanel.add(size);
  
                mainPanel.add(sizePanel);
                this.add(mainPanel);
  
        }
  
        /****************************************
         * Description of the Method
         *
         *@param e  Description of Parameter
         ***************************************/
        public void focusLost(FocusEvent e)
        {
                boolean isInvalid = false;
                String sizeString = size.getText();
                if (sizeString != null) {
                        try {
                                long assertionSize = Long.parseLong(sizeString);
                                if (assertionSize < 0) {
                                        isInvalid = true;
                                }
                        }
                        catch (NumberFormatException ex) {
                                isInvalid = true;
                        }
                        if (isInvalid) {
                                log.warn("SizeAssertionGui: Not a valid number!");
                                JOptionPane.showMessageDialog(null, 
JMeterUtils.getResString("size_assertion_input_error"), "Error", 
JOptionPane.ERROR_MESSAGE);
                        }
                }
        }
  
        /****************************************
         * Description of the Method
         *
         *@param e  Description of Parameter
         ***************************************/
        public void focusGained(FocusEvent e) {
        }
  
  }
  
  
  
  1.15      +6 -1      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- messages.properties       30 Aug 2002 18:28:16 -0000      1.14
  +++ messages.properties       11 Dec 2002 16:07:08 -0000      1.15
  @@ -301,4 +301,9 @@
   counter_per_user=Track counter independently for each user
   max=Maximum
   error_loading_help=Error loading help page
  -log_errors_only=Log Errors Only
  \ No newline at end of file
  +log_errors_only=Log Errors Only
  +size_assertion_failure=The result was the wrong size: It was {0} bytes, but should 
have been {1} bytes.
  +size_assertion_input_error=Please enter a valid positive integer.
  +size_assertion_label=Size in bytes:
  +size_assertion_size_test=Size to Assert
  +size_assertion_title=Size Assertion
  \ No newline at end of file
  
  
  
  1.17      +6 -1      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties
  
  Index: messages_de.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- messages_de.properties    3 Sep 2002 15:37:16 -0000       1.16
  +++ messages_de.properties    11 Dec 2002 16:07:08 -0000      1.17
  @@ -301,4 +301,9 @@
   counter_per_user=Track counter independently for each user
   max=Maximum
   error_loading_help=Error loading help page
  -log_errors_only=Log Errors Only
  \ No newline at end of file
  +log_errors_only=Log Errors Only
  +size_assertion_failure=The result was the wrong size: It was {0} bytes, but should 
have been {1} bytes.
  +size_assertion_input_error=Please enter a valid positive integer.
  +size_assertion_label=Size in bytes:
  +size_assertion_size_test=Size to Assert
  +size_assertion_title=Size Assertion
  \ No newline at end of file
  
  
  
  1.14      +6 -1      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties
  
  Index: messages_ja.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- messages_ja.properties    30 Aug 2002 18:28:16 -0000      1.13
  +++ messages_ja.properties    11 Dec 2002 16:07:08 -0000      1.14
  @@ -296,4 +296,9 @@
   counter_per_user=Track counter independently for each user
   max=Maximum
   error_loading_help=Error loading help page
  -log_errors_only=Log Errors Only
  \ No newline at end of file
  +log_errors_only=Log Errors Only
  +size_assertion_failure=The result was the wrong size: It was {0} bytes, but should 
have been {1} bytes.
  +size_assertion_input_error=Please enter a valid positive integer.
  +size_assertion_label=Size in bytes:
  +size_assertion_size_test=Size to Assert
  +size_assertion_title=Size Assertion
  \ No newline at end of file
  
  
  
  1.14      +6 -1      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties
  
  Index: messages_no.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- messages_no.properties    30 Aug 2002 18:28:16 -0000      1.13
  +++ messages_no.properties    11 Dec 2002 16:07:08 -0000      1.14
  @@ -288,4 +288,9 @@
   counter_per_user=Track counter independently for each user
   max=Maximum
   error_loading_help=Error loading help page
  -log_errors_only=Log Errors Only
  \ No newline at end of file
  +log_errors_only=Log Errors Only
  +size_assertion_failure=The result was the wrong size: It was {0} bytes, but should 
have been {1} bytes.
  +size_assertion_input_error=Please enter a valid positive integer.
  +size_assertion_label=Size in bytes:
  +size_assertion_size_test=Size to Assert
  +size_assertion_title=Size Assertion
  \ No newline at end of file
  
  
  

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

Reply via email to