jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sankaran, Nambi" <nsanka...@ebay.com>
Subject how to create a customm assertion
Date Wed, 10 Sep 2014 23:59:58 GMT
Hi 

I followed the tutorial provided in the jmeter website.
I have questions on building custom assertions,

1) The custom assertion is not getting invoked during execution. Why?
2) The custom assertion is not persisted in the while saving the project. 
    The JMX file doesn't have the configuration for the custom assertion.
    How to save the configuration?

For reference I have attached the Assertion class.

Thanks
Nambi

=============================================================================

package com.testers.jmeter.assertionlib;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.jmeter.assertions.AssertionResult;
import org.apache.jmeter.assertions.gui.AbstractAssertionGui;
import org.apache.jmeter.extractor.RegexExtractor;
import org.apache.jmeter.gui.util.HorizontalPanel;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.property.BooleanProperty;

public class TestAssertion extends AbstractAssertionGui {

	    private static final long serialVersionUID = 1397205492925472603L;
	    private JTextField oldVersionText;
	    private JTextField newVersionText;
		
		public TestAssertion(){
			super();
			init();
		}
		
		protected void init(){
	        setLayout(new BorderLayout());
	        setBorder(makeBorder());

	        Box box = Box.createVerticalBox();
	        box.add(makeTitlePanel());
	        box.add(createScopePanel(true));
	        box.add( makeSourcePanel() );
	        add(box, BorderLayout.NORTH);
		}
		
	    private JPanel makeSourcePanel() {
	        JPanel panel = new VerticalPanel();
	        panel.setBorder(BorderFactory.createTitledBorder("Text Input")); //$NON-NLS-1$

	        JPanel oldPanel = new HorizontalPanel();
	        JLabel label = new JLabel();
	        label.setText("Old Version: Enter text to match");
	        label.setSize(100, 10);
	        oldVersionText = new JTextField(1);
	        oldVersionText.setSize(100, 10);
	        
	        oldPanel.add(label);
	        oldPanel.add( oldVersionText);
	        
	        JPanel newPanel = new HorizontalPanel();
	        JLabel newLabel = new JLabel();
	        newLabel.setText("New Version: Enter Text To Match");
	        newLabel.setSize(100, 10);
	        newVersionText = new JTextField(1);
	        newVersionText.setSize(100, 10);
	        
	        newPanel.add(newLabel);
	        newPanel.add(newVersionText);
	        
	        panel.add(oldPanel);
	        panel.add(newPanel);
	        
	        //panel.add(newVersionText, BorderLayout.WEST);

	        return panel;
	    }

		public AssertionResult getResult(SampleResult result) {
			result.getResponseDataAsString();
			
			AssertionResult assertion = new AssertionResult("TEST");
			return assertion;
		}

		public TestElement createTestElement() {
			RegexExtractor extractor =new RegexExtractor();
			modifyTestElement(extractor);
			return extractor;
		}

		public String getStaticLabel(){
			return getLabelResource();
		}
		
		public String getLabelResource() {
			return "TEST  Assertion";
		}
		
		public void configure( TestElement el){
			super.configure(el);
		}

		public void modifyTestElement(TestElement elem) {
			super.configure(elem);
			
			elem.setProperty( new BooleanProperty(RegexExtractor.USE_HDRS, true) );
			elem.setProperty("Number", 4);
			elem.setName("Test Assertion");
			
			if( elem instanceof RegexExtractor ){
				RegexExtractor regex = ( RegexExtractor) elem;
				regex.setRefName("Name");
				regex.setRegex("");
				regex.setTemplate("");
				regex.setDefaultValue("gege");
			}
		}

	}



Mime
View raw message