KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > visualizers > AssertionVisualizer


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/AssertionVisualizer.java,v 1.16.2.1 2004/06/12 18:32:05 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.visualizers;
20
21 import java.awt.BorderLayout JavaDoc;
22
23 import javax.swing.Box JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import javax.swing.JScrollPane JavaDoc;
26 import javax.swing.JTextArea JavaDoc;
27 import javax.swing.border.Border JavaDoc;
28 import javax.swing.border.EmptyBorder JavaDoc;
29
30 import org.apache.jmeter.assertions.AssertionResult;
31 import org.apache.jmeter.samplers.Clearable;
32 import org.apache.jmeter.samplers.SampleResult;
33 import org.apache.jmeter.util.JMeterUtils;
34 import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
35
36
37 /**
38  *
39  * @version $Revision: 1.16.2.1 $ on $Date: 2004/06/12 18:32:05 $
40  */

41 public class AssertionVisualizer extends AbstractVisualizer implements Clearable
42 {
43
44     private JTextArea JavaDoc textArea;
45
46     public AssertionVisualizer()
47     {
48         init();
49         setName(getStaticLabel());
50     }
51
52     public String JavaDoc getLabelResource()
53     {
54         return "assertion_visualizer_title";
55     }
56
57     public void add(SampleResult sample)
58     {
59         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(100);
60         String JavaDoc sd= sample.getSamplerData();
61         if(null != sd)
62         {
63             sb.append(sd);
64         }
65         else
66         {
67             sb.append(sample.getSampleLabel());
68         }
69         sb.append(getAssertionResult(sample));
70         sb.append("\n");
71         synchronized(textArea){
72             textArea.append(sb.toString());
73         }
74     }
75
76     public void clear()
77     {
78         textArea.setText("");
79     }
80
81     private String JavaDoc getAssertionResult(SampleResult res)
82     {
83         if (res != null)
84         {
85             StringBuffer JavaDoc display = new StringBuffer JavaDoc();
86             AssertionResult assertionResults[] = res.getAssertionResults();
87             for (int i = 0; i < assertionResults.length; i++)
88             {
89                 AssertionResult item = assertionResults[i];
90
91                 if (item.isFailure() || item.isError())
92                 {
93                     display.append("\n\t\t");
94                     display.append(item.getFailureMessage());
95                 }
96             }
97             return display.toString();
98         }
99         return "";
100     }
101
102     private void init()
103     {
104         this.setLayout(new BorderLayout JavaDoc());
105
106         // MAIN PANEL
107
Border JavaDoc margin = new EmptyBorder JavaDoc(10, 10, 5, 10);
108
109         this.setBorder(margin);
110
111
112         // NAME
113
this.add(makeTitlePanel(),BorderLayout.NORTH);
114
115         // TEXTAREA LABEL
116
JLabel JavaDoc textAreaLabel =
117             new JLabel JavaDoc(JMeterUtils.getResString("assertion_textarea_label"));
118         Box JavaDoc mainPanel = Box.createVerticalBox();
119         mainPanel.add(textAreaLabel);
120
121         // TEXTAREA
122
textArea = new JTextArea JavaDoc();
123         textArea.setEditable(false);
124         textArea.setLineWrap(false);
125         JScrollPane JavaDoc areaScrollPane = new JScrollPane JavaDoc(textArea);
126
127         areaScrollPane.setVerticalScrollBarPolicy(
128             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
129         areaScrollPane.setHorizontalScrollBarPolicy(
130             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
131
132         mainPanel.add(areaScrollPane);
133         mainPanel.add(Box.createVerticalGlue());
134         this.add(mainPanel, BorderLayout.CENTER);
135     }
136 }
137
Popular Tags