neth 01/08/15 04:09:56
Added: src/org/apache/jmeter/visualizers
ViewResultsFullVisualizer.java
Log:
View Tree Result visualizer
Revision Changes Path
1.1
jakarta-jmeter/src/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java
Index: ViewResultsFullVisualizer.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.visualizers;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import org.apache.jmeter.reporters.ResultCollectorFull;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.gui.*;
import org.apache.jmeter.gui.tree.*;
import org.apache.log4j.*;
import junit.framework.*;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFull;
/**
* Allows the tester to view the textual response from sampling an Entry. This
* also allows to "single step through" the sampling process via a nice
* "Continue" button.
*
*@author Khor Soon Hin
*@created 2001/07/25
*@version $Revision: 1.1 $ $Date: 2001/08/15 11:09:56 $
*/
public class ViewResultsFullVisualizer extends ViewResultsVisualizer implements
TreeSelectionListener, ModelSupported
{
protected DefaultMutableTreeNode root;
protected DefaultTreeModel treeModel;
protected GridBagLayout gridBag;
protected GridBagConstraints gbc;
protected JPanel resultPanel;
protected JScrollPane treePane;
protected JScrollPane resultPane;
protected JSplitPane treeSplitPane;
protected JTree jTree;
protected int childIndex;
private static Category catClass =
Category.getInstance(ViewResultsFullVisualizer.class.getName());
public static final Color SERVER_ERROR_COLOR = Color.red;
public static final Color CLIENT_ERROR_COLOR = Color.blue;
public static final Color REDIRECT_COLOR = Color.green;
ResultCollectorFull model;
public ViewResultsFullVisualizer()
{
super();
this.setLayout(new GridLayout(1,1));
catClass.debug("Start : ViewResultsFullVisualizer1");
catClass.debug("End : ViewResultsFullVisualizer1");
}
/**
* Set the reporter type this visualizer will work with
*
* @param model reporter instance
*/
public void setModel(Object model)
{
catClass.debug("Start : setModel1");
this.model = (ResultCollectorFull)model;
this.model.setListener(this);
init();
catClass.debug("End : setModel1");
}
/**
* Initialize this visualizer
*/
private void init()
{
catClass.debug("Start : init1");
SampleResult rootSampleResult = new SampleResult();
rootSampleResult.putValue(SampleResult.DISPLAY_NAME, "Root");
root = new DefaultMutableTreeNode(rootSampleResult);
treeModel = new DefaultTreeModel(root);
jTree = new JTree(treeModel);
jTree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);
treePane = new JScrollPane(jTree);
gridBag = new GridBagLayout();
gbc = new GridBagConstraints();
resultPanel = new JPanel(gridBag);
resultPane = new JScrollPane(resultPanel);
treeSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
treePane, resultPane);
add(treeSplitPane);
catClass.debug("End : init1");
}
/**
* Update the visualizer with new data
*/
public void updateGui()
{
catClass.debug("Start : updateGui1");
SampleResult res = null;
while((res = model.getSampleResult()) != null)
{
DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(res);
treeModel.insertNodeInto(currNode, root, childIndex++);
ArrayList arrayList = (ArrayList)res.getValue(HTTPSamplerFull.RESULT_LIST);
Iterator iter = arrayList.iterator();
int leafIndex = 0;
while(iter.hasNext())
{
SampleResult child = (SampleResult)iter.next();
if(catClass.isDebugEnabled())
{
catClass.debug("updateGui1 : child sample result - " + child);
}
DefaultMutableTreeNode leafNode =
new DefaultMutableTreeNode(child);
treeModel.insertNodeInto(leafNode, currNode, leafIndex++);
}
}
catClass.debug("End : updateGui1");
}
/**
* Clears the visualizer
*/
public void clear()
{
catClass.debug("Start : clear1");
int totalChild = root.getChildCount();
if(catClass.isDebugEnabled())
{
catClass.debug("clear1 : total child - " + totalChild);
}
for(int i = 0; i < totalChild; i++)
{
// the child to be removed will always be 0 'cos as the nodes are removed
// the nth node will become (n-1)th
treeModel.removeNodeFromParent(
(DefaultMutableTreeNode)root.getChildAt(0));
}
resultPanel.removeAll();
// reset the child index
childIndex = 0;
catClass.debug("End : clear1");
}
/**
* Returns the description of this visualizer
*
* @return description of this visualizer
*/
public String toString()
{
String desc = "Shows the text results of sampling in tree form";
if(catClass.isDebugEnabled())
{
catClass.debug("toString1 : Returning description - " + desc);
}
return desc;
}
/**
* Sets the bottom pane to correspond to the selected node of the top
* tree
*/
public void valueChanged(TreeSelectionEvent e)
{
catClass.debug("Start : valueChanged1");
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
if(catClass.isDebugEnabled())
{
catClass.debug("valueChanged : selected node - " + node);
}
if(node != null)
{
SampleResult res = (SampleResult)node.getUserObject();
if(catClass.isDebugEnabled())
{
catClass.debug("valueChanged1 : sample result - " + res);
}
if(res != null)
{
resultPanel.removeAll();
// load time label
JLabel loadTime = new JLabel();
loadTime.setText("Load time : " + res.getTime());
gbc.gridx = 0;
gbc.gridy = 0;
// keep all of the labels to the left
gbc.anchor = GridBagConstraints.WEST;
// with weightx != 0.0, components won't clump in the center
gbc.weightx = 1.0;
// pad a bit from the display area
gbc.insets = new Insets(0, 10, 0, 0);
gridBag.setConstraints(loadTime, gbc);
resultPanel.add(loadTime);
// response code label
JLabel httpResponseCode = new JLabel();
String responseCode = (String)res.getValue(Sampler.RESPONSE_CODE);
int responseLevel = 0;
if(responseCode != null)
{
try
{
responseLevel = Integer.parseInt(responseCode)/100;
}
catch(NumberFormatException numberFormatException)
{
// no need to change the foreground color
}
}
switch(responseLevel)
{
case 3 : httpResponseCode.setForeground(REDIRECT_COLOR);
case 4 : httpResponseCode.setForeground(CLIENT_ERROR_COLOR);
case 5 : httpResponseCode.setForeground(SERVER_ERROR_COLOR);
}
httpResponseCode.setText("HTTP response code : " +
responseCode);
gbc.gridx = 0;
gbc.gridy = 1;
gridBag.setConstraints(httpResponseCode, gbc);
resultPanel.add(httpResponseCode);
// response message label
JLabel httpResponseMsg = new JLabel();
httpResponseMsg.setText("HTTP response message : " +
(String)res.getValue(Sampler.RESPONSE_MESSAGE));
gbc.gridx = 0;
gbc.gridy = 2;
gridBag.setConstraints(httpResponseMsg, gbc);
resultPanel.add(httpResponseMsg);
// get the text response and image icon
// to determine which is NOT null
String response = (String)res.getValue(Sampler.TEXT_RESPONSE);
ImageIcon icon = (ImageIcon)res.getValue(HTTPSamplerFull.IMAGE);
if(catClass.isDebugEnabled())
{
if(response != null)
{
// only first 5 chars are printed 'cos for binary files
// it may be quite long to print the whole content,
// moreover they contain non-printable chars
catClass.debug("valueChanged1 : http response - " +
response.substring(0,5));
}
else
{
catClass.debug("valueChanged1 : http response - " + response);
}
}
if(response != null)
{
JTextArea textArea = new JTextArea();
textArea.setText(response);
gbc.gridx = 0;
gbc.gridy = 4;
gridBag.setConstraints(textArea, gbc);
resultPanel.add(textArea);
}
else if(icon != null)
{
JLabel image = new JLabel();
image.setIcon(icon);
gbc.gridx = 0;
gbc.gridy = 4;
gridBag.setConstraints(image, gbc);
resultPanel.add(image);
}
resultPanel.repaint();
resultPanel.revalidate();
}
}
catClass.debug("End : valueChanged1");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]