View | Details | Raw Unified | Return to bug 47907
Collapse All | Expand All

(-)/src/components/org/apache/jmeter/assertions/CompareAssertion.java (-141 / +161 lines)
Lines 20-28 Link Here
20
20
21
import java.io.Serializable;
21
import java.io.Serializable;
22
import java.util.Collection;
22
import java.util.Collection;
23
import java.util.Iterator;
24
import java.util.LinkedList;
23
import java.util.LinkedList;
25
import java.util.List;
26
24
27
import org.apache.jmeter.engine.event.LoopIterationEvent;
25
import org.apache.jmeter.engine.event.LoopIterationEvent;
28
import org.apache.jmeter.engine.event.LoopIterationListener;
26
import org.apache.jmeter.engine.event.LoopIterationListener;
Lines 34-131 Link Here
34
import org.apache.oro.text.regex.Util;
32
import org.apache.oro.text.regex.Util;
35
33
36
public class CompareAssertion extends AbstractTestElement implements Assertion, TestBean, Serializable,
34
public class CompareAssertion extends AbstractTestElement implements Assertion, TestBean, Serializable,
37
		LoopIterationListener {
35
        LoopIterationListener {
38
36
39
    private static final long serialVersionUID = 240L;
37
    private static final long serialVersionUID = 240L;
40
    
38
    
41
	private transient List<SampleResult> responses;
39
    private static final String NL = "\n"; // $NON-NLS-1$
40
    
41
    private static final String NL2 = "\n\n"; // $NON-NLS-1$
42
42
43
	private transient final StringSubstitution emptySub = new StringSubstitution("");
43
    private transient LinkedList<SampleResult> responses;
44
44
45
	private boolean compareContent = true;
45
    private transient final StringSubstitution emptySub = new StringSubstitution("");
46
46
47
	private long compareTime = -1;
47
    private boolean compareContent = true;
48
48
49
	private Collection<SubstitutionElement> stringsToSkip;
49
    private long compareTime = -1;
50
50
51
	public CompareAssertion() {
51
    private Collection<SubstitutionElement> stringsToSkip;
52
		super();
53
	}
54
52
55
	public AssertionResult getResult(SampleResult response) {
53
    public CompareAssertion() {
56
		responses.add(response);
54
        super();
57
		if (responses.size() > 1) {
55
    }
58
			CompareAssertionResult result = new CompareAssertionResult(getName());
59
			compareContent(result);
60
			compareTime(result);
61
			return result;
62
		} else
63
			return new AssertionResult(getName());
64
	}
65
56
66
	private void compareTime(CompareAssertionResult result) {
57
    public AssertionResult getResult(SampleResult response) {
67
		if (compareTime >= 0) {
58
        responses.addLast(response);
68
			Iterator<SampleResult> iter = responses.iterator();
59
        if (responses.size() > 1) {
69
			long prevTime = -1;
60
            CompareAssertionResult result = new CompareAssertionResult(getName());
70
			SampleResult prevResult = null;
61
            if (compareTime >= 0) {
71
			boolean success = true;
62
                compareTime(result);
72
			while (iter.hasNext()) {
63
            }
73
				SampleResult sResult = iter.next();
64
            if (compareContent) {
74
				long currentTime = sResult.getTime();
65
                compareContent(result);
75
				if (prevTime != -1) {
66
            }
76
					success = Math.abs(prevTime - currentTime) <= compareTime;
67
            return result;
77
					prevResult = sResult;
68
        } else {
78
				}
69
            CompareAssertionResult assRes = new CompareAssertionResult(getName());
79
				if (!success) {
70
            assRes.setFailure(false);
80
					result.setFailure(true);
71
            assRes.addToBaseResult("No previous");
81
                    StringBuffer buf = new StringBuffer();
72
82
                    appendResultDetails(buf, prevResult);
73
            SampleResult firstResult = responses.getFirst();
83
                    buf.append("Response Time: ").append(prevTime);
74
            long prevTime = responses.getFirst().getTime();
84
					result.addToBaseResult(buf.toString());
75
            StringBuffer buf = new StringBuffer();
85
					buf = new StringBuffer();
76
            appendResultDetails(buf, firstResult);
86
                    appendResultDetails(buf, sResult);
77
            buf.append("Response Time (ms): ").append(prevTime + NL2);
87
					buf.append("Response Time: ").append(currentTime);
78
            buf.append(filterString(firstResult.getResponseDataAsString()));
88
					result.addToSecondaryResult(buf.toString());
79
            assRes.addToSecondaryResult(buf.toString());
89
					result.setFailureMessage("Responses differ in response time by more than "+compareTime+" ms");
80
90
					break;
81
            return assRes;
91
				}
82
        }
92
				prevResult = sResult;
83
    }
93
				prevTime = currentTime;
84
94
			}
85
    private void compareTime(CompareAssertionResult result) {
95
		}
86
        SampleResult prevResult = responses.getFirst();
96
	}
87
        long prevTime = prevResult.getTime();
88
        StringBuffer buf = new StringBuffer();
89
        appendResultDetails(buf, prevResult);
90
        buf.append("Response Time (ms): ").append(prevTime);
91
        result.addToBaseResult(buf.toString());
92
        
93
        boolean success = true;
94
        SampleResult sResult = responses.getLast();
95
        if (sResult != null) {
96
            long currentTime = sResult.getTime();
97
            success = Math.abs(prevTime - currentTime) <= compareTime;
98
            if (!success) {
99
                result.setFailure(true);
100
                buf = new StringBuffer();
101
                appendResultDetails(buf, sResult);
102
                buf.append("Response Time (ms): ").append(currentTime);
103
                result.addToSecondaryResult(buf.toString());
104
                result.setFailureMessage("Responses differ in response time by more than "
105
                                + compareTime + " ms");
106
            } else {
107
                buf = new StringBuffer();
108
                buf.append("Compare time less than " + compareTime + " ms" + NL);
109
                buf.append(NL2 + "Response Time (ms): ").append(currentTime);
110
                result.addToSecondaryResult(buf.toString());
111
            }
112
        }
113
    }
97
114
98
    private void compareContent(CompareAssertionResult result) {
115
    private void compareContent(CompareAssertionResult result) {
99
		if (compareContent) {
116
        SampleResult prevResult = responses.getFirst();
100
			Iterator<SampleResult> iter = responses.iterator();
117
        String prevContent = filterString(prevResult.getResponseDataAsString());
101
			String prevContent = null;
118
        StringBuffer buf = new StringBuffer();
102
			SampleResult prevResult = null;
119
        // no append if compare time already pass
103
			boolean success = true;
120
        if (compareTime < 0) {
104
			while (iter.hasNext()) {
121
            appendResultDetails(buf, prevResult);
105
				SampleResult sResult = iter.next();
122
        } else {
106
				String currentContent = sResult.getResponseDataAsString();
123
            buf.append(NL2);
107
				currentContent = filterString(currentContent);
124
        }
108
				if (prevContent != null) {
125
        buf.append(prevContent);
109
					success = prevContent.equals(currentContent);
126
        result.addToBaseResult(buf.toString());
110
				}
127
        
111
				if (!success) {
128
        SampleResult sResult = responses.getLast();
112
					result.setFailure(true);
129
        if (sResult != null) {
113
                    StringBuffer buf = new StringBuffer();
130
            String currentContent = sResult.getResponseDataAsString();
114
                    appendResultDetails(buf, prevResult);
131
            currentContent = filterString(currentContent);
115
					buf.append(prevContent);
132
            if (!prevContent.equals(currentContent)) {
116
					result.addToBaseResult(buf.toString());
133
                result.setFailure(true);
117
					buf = new StringBuffer();
134
                buf = new StringBuffer();
118
					appendResultDetails(buf, sResult);
135
                // no append if compare time already pass
119
					buf.append(currentContent);
136
                if (compareTime < 0) {
120
					result.addToSecondaryResult(buf.toString());
137
                    appendResultDetails(buf, sResult);
121
					result.setFailureMessage("Responses differ in content");
138
                } else {
122
					break;
139
                    buf.append(NL2);
123
				}
140
                }
124
				prevResult = sResult;
141
                buf.append(currentContent);
125
				prevContent = currentContent;
142
                result.addToSecondaryResult(buf.toString());
126
			}
143
                result.setFailureMessage("Responses differ in content");
127
		}
144
            } else {
128
	}
145
                result.addToSecondaryResult("Same content");
146
            }
147
        }
148
    }
129
149
130
    private void appendResultDetails(StringBuffer buf, SampleResult result) {
150
    private void appendResultDetails(StringBuffer buf, SampleResult result) {
131
        final String samplerData = result.getSamplerData();
151
        final String samplerData = result.getSamplerData();
Lines 132-138 Link Here
132
        if (samplerData != null){
152
        if (samplerData != null){
133
            buf.append(samplerData.trim());
153
            buf.append(samplerData.trim());
134
        }
154
        }
135
        buf.append("\n");
155
        buf.append(NL);
136
        final String requestHeaders = result.getRequestHeaders();
156
        final String requestHeaders = result.getRequestHeaders();
137
        if (requestHeaders != null){
157
        if (requestHeaders != null){
138
            buf.append(requestHeaders);
158
            buf.append(requestHeaders);
Lines 137-209 Link Here
137
        if (requestHeaders != null){
157
        if (requestHeaders != null){
138
            buf.append(requestHeaders);
158
            buf.append(requestHeaders);
139
        }
159
        }
140
        buf.append("\n\n");        
160
        buf.append(NL2);
141
    }
161
    }
142
162
143
	private String filterString(String content) {
163
    private String filterString(String content) {
144
		if (stringsToSkip == null || stringsToSkip.size() == 0) {
164
        if (stringsToSkip == null || stringsToSkip.size() == 0) {
145
			return content;
165
            return content;
146
		} else {
166
        } else {
147
			for (SubstitutionElement regex : stringsToSkip) {
167
            for (SubstitutionElement regex : stringsToSkip) {
148
				emptySub.setSubstitution(regex.getSubstitute());
168
                emptySub.setSubstitution(regex.getSubstitute());
149
				content = Util.substitute(JMeterUtils.getMatcher(), JMeterUtils.getPatternCache().getPattern(regex.getRegex()),
169
                content = Util.substitute(JMeterUtils.getMatcher(), JMeterUtils.getPatternCache().getPattern(regex.getRegex()),
150
						emptySub, content, Util.SUBSTITUTE_ALL);
170
                        emptySub, content, Util.SUBSTITUTE_ALL);
151
			}
171
            }
152
		}
172
        }
153
		return content;
173
        return content;
154
	}
174
    }
155
175
156
	public void iterationStart(LoopIterationEvent iterEvent) {
176
    public void iterationStart(LoopIterationEvent iterEvent) {
157
		responses = new LinkedList<SampleResult>();
177
        responses = new LinkedList<SampleResult>();
158
	}
178
    }
159
179
160
	public void iterationEnd(LoopIterationEvent iterEvent) {
180
    public void iterationEnd(LoopIterationEvent iterEvent) {
161
		responses = null;
181
        responses = null;
162
	}
182
    }
163
183
164
	/**
184
    /**
165
	 * @return Returns the compareContent.
185
     * @return Returns the compareContent.
166
	 */
186
     */
167
	public boolean isCompareContent() {
187
    public boolean isCompareContent() {
168
		return compareContent;
188
        return compareContent;
169
	}
189
    }
170
190
171
	/**
191
    /**
172
	 * @param compareContent
192
     * @param compareContent
173
	 *            The compareContent to set.
193
     *            The compareContent to set.
174
	 */
194
     */
175
	public void setCompareContent(boolean compareContent) {
195
    public void setCompareContent(boolean compareContent) {
176
		this.compareContent = compareContent;
196
        this.compareContent = compareContent;
177
	}
197
    }
178
198
179
	/**
199
    /**
180
	 * @return Returns the compareTime.
200
     * @return Returns the compareTime.
181
	 */
201
     */
182
	public long getCompareTime() {
202
    public long getCompareTime() {
183
		return compareTime;
203
        return compareTime;
184
	}
204
    }
185
205
186
	/**
206
    /**
187
	 * @param compareTime
207
     * @param compareTime
188
	 *            The compareTime to set.
208
     *            The compareTime to set.
189
	 */
209
     */
190
	public void setCompareTime(long compareTime) {
210
    public void setCompareTime(long compareTime) {
191
		this.compareTime = compareTime;
211
        this.compareTime = compareTime;
192
	}
212
    }
193
213
194
	/**
214
    /**
195
	 * @return Returns the stringsToSkip.
215
     * @return Returns the stringsToSkip.
196
	 */
216
     */
197
	public Collection<SubstitutionElement> getStringsToSkip() {
217
    public Collection<SubstitutionElement> getStringsToSkip() {
198
		return stringsToSkip;
218
        return stringsToSkip;
199
	}
219
    }
200
220
201
	/**
221
    /**
202
	 * @param stringsToSkip
222
     * @param stringsToSkip
203
	 *            The stringsToSkip to set.
223
     *            The stringsToSkip to set.
204
	 */
224
     */
205
	public void setStringsToSkip(Collection<SubstitutionElement> stringsToSkip) {
225
    public void setStringsToSkip(Collection<SubstitutionElement> stringsToSkip) {
206
		this.stringsToSkip = stringsToSkip;
226
        this.stringsToSkip = stringsToSkip;
207
	}
227
    }
208
228
209
}
229
}
(-)/src/components/org/apache/jmeter/assertions/CompareAssertionBeanInfo.java (-23 / +23 lines)
Lines 26-53 Link Here
26
26
27
public class CompareAssertionBeanInfo extends BeanInfoSupport {
27
public class CompareAssertionBeanInfo extends BeanInfoSupport {
28
28
29
	public CompareAssertionBeanInfo() {
29
    public CompareAssertionBeanInfo() {
30
		super(CompareAssertion.class);
30
        super(CompareAssertion.class);
31
		createPropertyGroup("compareChoices", new String[] { "compareContent", "compareTime" });
31
        createPropertyGroup("compareChoices", new String[] { "compareContent", "compareTime" });
32
		createPropertyGroup("comparison_filters", new String[]{"stringsToSkip"});
32
        createPropertyGroup("comparison_filters", new String[]{"stringsToSkip"});
33
		PropertyDescriptor p = property("compareContent");
33
        PropertyDescriptor p = property("compareContent");
34
		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
34
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
35
		p.setValue(DEFAULT, Boolean.TRUE);
35
        p.setValue(DEFAULT, Boolean.TRUE);
36
		p.setValue(NOT_EXPRESSION, Boolean.TRUE);
36
        p.setValue(NOT_EXPRESSION, Boolean.TRUE);
37
		p = property("compareTime");
37
        p = property("compareTime");
38
		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
38
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
39
		p.setValue(DEFAULT, new Long(-1));
39
        p.setValue(DEFAULT, new Long(-1));
40
		p.setValue(NOT_EXPRESSION, Boolean.FALSE);	
40
        p.setValue(NOT_EXPRESSION, Boolean.FALSE);    
41
		p = property("stringsToSkip");
41
        p = property("stringsToSkip");
42
		p.setPropertyEditorClass(TableEditor.class);
42
        p.setPropertyEditorClass(TableEditor.class);
43
		p.setValue(TableEditor.CLASSNAME,SubstitutionElement.class.getName());
43
        p.setValue(TableEditor.CLASSNAME,SubstitutionElement.class.getName());
44
		p.setValue(TableEditor.HEADERS,new String[]{"Regex String","Substitution"}); // TODO I18n
44
        p.setValue(TableEditor.HEADERS,new String[]{"Regex String","Substitution"}); // TODO I18n
45
		p.setValue(TableEditor.OBJECT_PROPERTIES, // These are the names of the get/set methods
45
        p.setValue(TableEditor.OBJECT_PROPERTIES, // These are the names of the get/set methods
46
		        new String[]{SubstitutionElement.REGEX, SubstitutionElement.SUBSTITUTE});
46
                new String[]{SubstitutionElement.REGEX, SubstitutionElement.SUBSTITUTE});
47
		p.setValue(NOT_UNDEFINED,Boolean.TRUE);
47
        p.setValue(NOT_UNDEFINED,Boolean.TRUE);
48
		p.setValue(DEFAULT,new ArrayList<Object>());
48
        p.setValue(DEFAULT,new ArrayList<Object>());
49
		p.setValue(MULTILINE,Boolean.TRUE);
49
        p.setValue(MULTILINE,Boolean.TRUE);
50
		
50
        
51
	}
51
    }
52
52
53
}
53
}
(-)/src/components/org/apache/jmeter/visualizers/ComparisonVisualizer.java (-101 / +109 lines)
Lines 40-163 Link Here
40
import org.apache.jmeter.samplers.Clearable;
40
import org.apache.jmeter.samplers.Clearable;
41
import org.apache.jmeter.samplers.SampleResult;
41
import org.apache.jmeter.samplers.SampleResult;
42
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
42
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
43
import org.apache.jorphan.logging.LoggingManager;
44
import org.apache.log.Logger;
43
45
44
public class ComparisonVisualizer extends AbstractVisualizer implements Clearable {
46
public class ComparisonVisualizer extends AbstractVisualizer implements Clearable {
45
	private JTree resultsTree;
47
    
48
    private static final long serialVersionUID = 240L;
46
49
47
	private DefaultTreeModel treeModel;
50
    private JTree resultsTree;
48
51
49
	private DefaultMutableTreeNode root;
52
    private DefaultTreeModel treeModel;
50
53
51
	private JTextPane base, secondary;
54
    private DefaultMutableTreeNode root;
52
55
53
	public ComparisonVisualizer() {
56
    private JTextPane base, secondary;
54
		super();
55
		init();
56
	}
57
57
58
	public void add(SampleResult sample) {
58
    public ComparisonVisualizer() {
59
        super();
60
        init();
61
    }
59
62
60
		DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(sample);
63
    public void add(SampleResult sample) {
61
		treeModel.insertNodeInto(currNode, root, root.getChildCount());
62
		if (root.getChildCount() == 1) {
63
			resultsTree.expandPath(new TreePath(root));
64
		}
65
	}
66
64
67
	public String getLabelResource() {
65
        DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(sample);
68
		return "comparison_visualizer_title";
66
        treeModel.insertNodeInto(currNode, root, root.getChildCount());
69
	}
67
        if (root.getChildCount() == 1) {
68
            resultsTree.expandPath(new TreePath(root));
69
        }
70
    }
70
71
71
	private void init() {
72
    public String getLabelResource() {
72
		setLayout(new BorderLayout());
73
        return "comparison_visualizer_title"; // $NON-NLS-1$
73
		setBorder(makeBorder());
74
    }
74
		add(makeTitlePanel(), BorderLayout.NORTH);
75
		JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
76
		split.add(getTreePanel());
77
		split.add(getSideBySidePanel());
78
		add(split, BorderLayout.CENTER);
79
	}
80
75
81
	private JComponent getSideBySidePanel() {
76
    private void init() {
82
		JPanel main = new JPanel(new GridLayout(1, 2));
77
        setLayout(new BorderLayout());
83
		JScrollPane base = new JScrollPane(getBaseTextPane());
78
        setBorder(makeBorder());
84
		base.setPreferredSize(base.getMinimumSize());
79
        add(makeTitlePanel(), BorderLayout.NORTH);
85
		JScrollPane secondary = new JScrollPane(getSecondaryTextPane());
80
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
86
		secondary.setPreferredSize(secondary.getMinimumSize());
81
        split.add(getTreePanel());
87
		main.add(base);
82
        split.add(getSideBySidePanel());
88
		main.add(secondary);
83
        add(split, BorderLayout.CENTER);
89
		main.setPreferredSize(main.getMinimumSize());
84
    }
90
		return main;
91
	}
92
85
93
	private JTextPane getBaseTextPane() {
86
    private JComponent getSideBySidePanel() {
94
		base = new JTextPane();
87
        JPanel main = new JPanel(new GridLayout(1, 2));
95
		return base;
88
        JScrollPane base = new JScrollPane(getBaseTextPane());
96
	}
89
        base.setPreferredSize(base.getMinimumSize());
90
        JScrollPane secondary = new JScrollPane(getSecondaryTextPane());
91
        secondary.setPreferredSize(secondary.getMinimumSize());
92
        main.add(base);
93
        main.add(secondary);
94
        main.setPreferredSize(main.getMinimumSize());
95
        return main;
96
    }
97
97
98
	private JTextPane getSecondaryTextPane() {
98
    private JTextPane getBaseTextPane() {
99
		secondary = new JTextPane();
99
        base = new JTextPane();
100
		return secondary;
100
        base.setEditable(false);
101
	}
101
        base.setBackground(getBackground());
102
        return base;
103
    }
102
104
103
	private JComponent getTreePanel() {
105
    private JTextPane getSecondaryTextPane() {
104
		root = new DefaultMutableTreeNode("Root");
106
        secondary = new JTextPane();
105
		treeModel = new DefaultTreeModel(root);
107
        secondary.setEditable(false);
106
		resultsTree = new JTree(treeModel);
108
        return secondary;
107
		resultsTree.setCellRenderer(new TreeNodeRenderer());
109
    }
108
		resultsTree.setCellRenderer(new TreeNodeRenderer());
109
		resultsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
110
		resultsTree.addTreeSelectionListener(new Selector());
111
		resultsTree.setRootVisible(false);
112
		resultsTree.setShowsRootHandles(true);
113
110
114
		JScrollPane treePane = new JScrollPane(resultsTree);
111
    private JComponent getTreePanel() {
115
		treePane.setPreferredSize(new Dimension(150, 50));
112
        root = new DefaultMutableTreeNode("Root"); // $NON-NLS-1$
116
		JPanel panel = new JPanel(new GridLayout(1, 1));
113
        treeModel = new DefaultTreeModel(root);
117
		panel.add(treePane);
114
        resultsTree = new JTree(treeModel);
118
		return panel;
115
        resultsTree.setCellRenderer(new TreeNodeRenderer());
119
	}
116
        resultsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
117
        resultsTree.addTreeSelectionListener(new Selector());
118
        resultsTree.setRootVisible(false);
119
        resultsTree.setShowsRootHandles(true);
120
120
121
	private class Selector implements TreeSelectionListener {
121
        JScrollPane treePane = new JScrollPane(resultsTree);
122
		/*
122
        treePane.setPreferredSize(new Dimension(150, 50));
123
		 * (non-Javadoc)
123
        JPanel panel = new JPanel(new GridLayout(1, 1));
124
		 * 
124
        panel.add(treePane);
125
		 * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
125
        return panel;
126
		 */
126
    }
127
		public void valueChanged(TreeSelectionEvent e) {
128
			try {
129
				DefaultMutableTreeNode node = (DefaultMutableTreeNode) resultsTree.getLastSelectedPathComponent();
130
				SampleResult sr = (SampleResult) node.getUserObject();
131
				AssertionResult[] results = sr.getAssertionResults();
132
				CompareAssertionResult result = null;
133
				for (AssertionResult r : results) {
134
					if (r instanceof CompareAssertionResult) {
135
						result = (CompareAssertionResult) r;
136
						break;
137
					}
138
				}
139
				if (result == null)
140
					result = new CompareAssertionResult();
141
				base.setText(result.getBaseResult());
142
				secondary.setText(result.getSecondaryResult());
143
			} catch (Exception err) {
144
				base.setText("Invalid Node " + err);
145
				secondary.setText("Invalid Node " + err);
146
			}
147
			base.setCaretPosition(0);
148
			secondary.setCaretPosition(0);
149
		}
150
127
151
	}
128
    private class Selector implements TreeSelectionListener {
129
        /*
130
         * (non-Javadoc)
131
         * 
132
         * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
133
         */
134
        public void valueChanged(TreeSelectionEvent e) {
135
            try {
136
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) resultsTree.getLastSelectedPathComponent();
137
                SampleResult sr = (SampleResult) node.getUserObject();
138
                AssertionResult[] results = sr.getAssertionResults();
139
                CompareAssertionResult result = null;
140
                for (AssertionResult assRes : results) {
141
                    if (assRes instanceof CompareAssertionResult) {
142
                        result = (CompareAssertionResult) assRes;
143
                        break;
144
                    }
145
                }
146
                if (result == null) {
147
                    result = new CompareAssertionResult();
148
                }
149
                base.setText(result.getBaseResult());
150
                secondary.setText(result.getSecondaryResult());
151
            } catch (Exception err) {
152
                base.setText("Invalid Node " + err);
153
                secondary.setText("Invalid Node " + err);
154
            }
155
            base.setCaretPosition(0);
156
            secondary.setCaretPosition(0);
157
        }
152
158
153
	public void clearData() {
159
    }
154
		while (root.getChildCount() > 0) {
160
155
			// the child to be removed will always be 0 'cos as the nodes are
161
    public void clearData() {
156
			// removed the nth node will become (n-1)th
162
        while (root.getChildCount() > 0) {
157
			treeModel.removeNodeFromParent((DefaultMutableTreeNode) root.getChildAt(0));
163
            // the child to be removed will always be 0 'cos as the nodes are
158
			base.setText("");
164
            // removed the nth node will become (n-1)th
159
			secondary.setText("");
165
            treeModel.removeNodeFromParent((DefaultMutableTreeNode) root.getChildAt(0));
160
		}
166
            base.setText(""); // $NON-NLS-1$
161
	}
167
            secondary.setText(""); // $NON-NLS-1$
168
        }
169
    }
162
170
163
}
171
}
(-)/src/components/org/apache/jmeter/visualizers/TreeNodeRenderer.java (-16 / +31 lines)
Lines 21-26 Link Here
21
import java.awt.Color;
21
import java.awt.Color;
22
import java.awt.Component;
22
import java.awt.Component;
23
23
24
import javax.swing.ImageIcon;
24
import javax.swing.JTree;
25
import javax.swing.JTree;
25
import javax.swing.tree.DefaultMutableTreeNode;
26
import javax.swing.tree.DefaultMutableTreeNode;
26
import javax.swing.tree.DefaultTreeCellRenderer;
27
import javax.swing.tree.DefaultTreeCellRenderer;
Lines 26-31 Link Here
26
import javax.swing.tree.DefaultTreeCellRenderer;
27
import javax.swing.tree.DefaultTreeCellRenderer;
27
28
28
import org.apache.jmeter.samplers.SampleResult;
29
import org.apache.jmeter.samplers.SampleResult;
30
import org.apache.jmeter.util.JMeterUtils;
29
31
30
/**
32
/**
31
 * Tree cell renderer used by ComparisonVisualizer.
33
 * Tree cell renderer used by ComparisonVisualizer.
Lines 32-53 Link Here
32
 */
34
 */
33
public class TreeNodeRenderer extends DefaultTreeCellRenderer {
35
public class TreeNodeRenderer extends DefaultTreeCellRenderer {
34
36
35
	public TreeNodeRenderer() {
37
    private static final long serialVersionUID = 240L;
36
		super();
38
37
	}
39
    // Same ViewResultsTree
38
	
40
    private static final ImageIcon imageSuccess = JMeterUtils.getImage(
39
	@Override
41
            JMeterUtils.getPropDefault("viewResultsTree.success",  //$NON-NLS-1$
42
                    "icon_success_sml.gif")); //$NON-NLS-1$
43
44
    private static final ImageIcon imageFailure = JMeterUtils.getImage(
45
            JMeterUtils.getPropDefault("viewResultsTree.failure",  //$NON-NLS-1$
46
                    "icon_warning_sml.gif")); //$NON-NLS-1$
47
48
    public TreeNodeRenderer() {
49
        super();
50
    }
51
    
52
    @Override
40
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
53
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
41
			boolean leaf, int row, boolean focus) {
54
            boolean leaf, int row, boolean focus) {
42
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, focus);
55
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, focus);
43
		Object obj = ((DefaultMutableTreeNode) value).getUserObject();
56
        Object obj = ((DefaultMutableTreeNode) value).getUserObject();
44
		if(obj instanceof SampleResult)
57
        if (obj instanceof SampleResult) {
45
		{
58
            if (!((SampleResult) obj).isSuccessful()) {
46
			if (!((SampleResult) obj).isSuccessful()) {
59
                this.setForeground(Color.red);
47
				this.setForeground(Color.red);
60
                this.setIcon(imageFailure);
48
			}
61
            } else {
49
		}
62
                this.setIcon(imageSuccess);
50
		return this;
63
            }
51
	}
64
        }
65
        return this;
66
    }
52
67
53
}
68
}
(-)/src/core/org/apache/jmeter/assertions/CompareAssertionResult.java (-69 / +54 lines)
Lines 13-19 Link Here
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
15
 * limitations under the License.
16
 * 
16
 *
17
 */
17
 */
18
18
19
package org.apache.jmeter.assertions;
19
package org.apache.jmeter.assertions;
Lines 18-94 Link Here
18
18
19
package org.apache.jmeter.assertions;
19
package org.apache.jmeter.assertions;
20
20
21
public class CompareAssertionResult extends AssertionResult {
22
    private static final long serialVersionUID = 1;
21
23
22
public class CompareAssertionResult extends AssertionResult {
24
    private transient final ResultHolder comparedResults = new ResultHolder();
23
	private static final long serialVersionUID = 1;
24
	
25
	private transient final ResultHolder comparedResults = new ResultHolder();
26
25
27
	/**
26
    /**
28
	 * For testing only
27
     * For testing only
29
	 * @deprecated Use the other ctor
28
     * 
30
	 */
29
     * @deprecated Use the other ctor
31
	@Deprecated
30
     */
31
    @Deprecated
32
    public CompareAssertionResult() { // needs to be public for testing
32
    public CompareAssertionResult() { // needs to be public for testing
33
		super();
33
        super();
34
	}
34
    }
35
36
    public CompareAssertionResult(String name) {
37
        super(name);
38
    }
39
40
    public void addToBaseResult(String resultData) {
41
        comparedResults.addToBaseResult(resultData);
42
    }
43
44
    public void addToSecondaryResult(String resultData) {
45
        comparedResults.addToSecondaryResult(resultData);
46
    }
35
47
36
	public CompareAssertionResult(String name) {
48
    public String getBaseResult() {
37
		super(name);
49
        return comparedResults.baseResult;
38
	}
50
    }
39
	
40
	public void addToBaseResult(String resultData)
41
	{
42
		comparedResults.addToBaseResult(resultData);
43
	}
44
	
45
	public void addToSecondaryResult(String resultData)
46
	{
47
		comparedResults.addToSecondaryResult(resultData);
48
	}
49
	
50
	public String getBaseResult()
51
	{
52
		return comparedResults.baseResult;
53
	}
54
	
55
	public String getSecondaryResult()
56
	{
57
		return comparedResults.secondaryResult;
58
	}
59
51
60
	private static class ResultHolder
52
    public String getSecondaryResult() {
61
	{
53
        return comparedResults.secondaryResult;
62
		private String baseResult;
54
    }
63
		private String secondaryResult;
55
64
		
56
    private static class ResultHolder {
65
		public ResultHolder()
57
        private String baseResult;
66
		{
58
        private String secondaryResult;
67
			
59
68
		}
60
        public ResultHolder() {
69
		
61
        }
70
		public void addToBaseResult(String r)
62
71
		{
63
        public void addToBaseResult(String r) {
72
			if(baseResult == null)
64
            if (baseResult == null) {
73
			{
65
                baseResult = r;
74
				baseResult = r;
66
            } else {
75
			}
67
                baseResult = baseResult + "\n\n" + r; // $NON-NLS-1$
76
			else
68
            }
77
			{
69
        }
78
				baseResult = baseResult + "\n\n" + r;
70
79
			}
71
        public void addToSecondaryResult(String r) {
80
		}
72
            if (secondaryResult == null) {
81
		
73
                secondaryResult = r;
82
		public void addToSecondaryResult(String r)
74
            } else {
83
		{
75
                secondaryResult = secondaryResult + "\n\n" + r; // $NON-NLS-1$
84
			if(secondaryResult == null)
76
            }
85
			{
77
        }
86
				secondaryResult = r;
78
    }
87
			}
88
			else
89
			{
90
				secondaryResult = secondaryResult + "\n\n" + r;
91
			}
92
		}
93
	}
94
}
79
}
(-)/xdocs/usermanual/component_reference.xml (-2 / +2 lines)
Lines 3413-3420 Link Here
3413
<properties>
3413
<properties>
3414
    <property name="Name" required="No">Descriptive name for this element that is shown in the tree.</property>
3414
    <property name="Name" required="No">Descriptive name for this element that is shown in the tree.</property>
3415
    <property name="Compare Content" required="Yes">Whether or not to compare the content (response data)</property>
3415
    <property name="Compare Content" required="Yes">Whether or not to compare the content (response data)</property>
3416
    <property name="Compare Time" required="Yes">If the value is >=0, then check if the time difference is no greater than the value. 
3416
    <property name="Compare Time" required="Yes">If the value is >=0, then check if the response time difference is no greater than the value. 
3417
    I.e. if the value is 0, then the times must be exactly equal.</property>
3417
    I.e. if the value is 0, then the response times must be exactly equal.</property>
3418
    <property name="Comparison Filters" required="No">Filters can be used to remove strings from the content comparison.
3418
    <property name="Comparison Filters" required="No">Filters can be used to remove strings from the content comparison.
3419
    For example, if the page has a time-stamp, it might be matched with: "Time: \d\d:\d\d:\d\d" and replaced with a dummy fixed time "Time: HH:MM:SS".
3419
    For example, if the page has a time-stamp, it might be matched with: "Time: \d\d:\d\d:\d\d" and replaced with a dummy fixed time "Time: HH:MM:SS".
3420
    </property>
3420
    </property>

Return to bug 47907