1 18 19 package org.apache.jmeter.visualizers; 20 21 import java.awt.BorderLayout ; 22 23 import javax.swing.Box ; 24 import javax.swing.JLabel ; 25 import javax.swing.JScrollPane ; 26 import javax.swing.JTextArea ; 27 import javax.swing.border.Border ; 28 import javax.swing.border.EmptyBorder ; 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 41 public class AssertionVisualizer extends AbstractVisualizer implements Clearable 42 { 43 44 private JTextArea textArea; 45 46 public AssertionVisualizer() 47 { 48 init(); 49 setName(getStaticLabel()); 50 } 51 52 public String getLabelResource() 53 { 54 return "assertion_visualizer_title"; 55 } 56 57 public void add(SampleResult sample) 58 { 59 StringBuffer sb = new StringBuffer (100); 60 String 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 getAssertionResult(SampleResult res) 82 { 83 if (res != null) 84 { 85 StringBuffer display = new StringBuffer (); 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 ()); 105 106 Border margin = new EmptyBorder (10, 10, 5, 10); 108 109 this.setBorder(margin); 110 111 112 this.add(makeTitlePanel(),BorderLayout.NORTH); 114 115 JLabel textAreaLabel = 117 new JLabel (JMeterUtils.getResString("assertion_textarea_label")); 118 Box mainPanel = Box.createVerticalBox(); 119 mainPanel.add(textAreaLabel); 120 121 textArea = new JTextArea (); 123 textArea.setEditable(false); 124 textArea.setLineWrap(false); 125 JScrollPane areaScrollPane = new JScrollPane (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 |