View Javadoc

1    /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12   
13  package com.eviware.soapui.impl.wsdl.teststeps.actions;
14  
15  import java.awt.BorderLayout;
16  import java.awt.Component;
17  import java.awt.Dimension;
18  import java.awt.event.ActionEvent;
19  import java.util.Date;
20  
21  import javax.swing.AbstractAction;
22  import javax.swing.DefaultListModel;
23  import javax.swing.JComponent;
24  import javax.swing.JList;
25  import javax.swing.JPanel;
26  import javax.swing.JScrollPane;
27  import javax.swing.JSplitPane;
28  import javax.swing.JTabbedPane;
29  
30  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStepResult;
31  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult;
32  import com.eviware.soapui.model.iface.Response;
33  import com.eviware.soapui.model.testsuite.TestStep;
34  import com.eviware.soapui.support.UISupport;
35  import com.eviware.soapui.support.components.JPropertiesTable;
36  import com.eviware.soapui.support.components.JPropertiesTable.PropertyFormatter;
37  import com.eviware.soapui.support.xml.JXEditTextArea;
38  import com.eviware.soapui.support.xml.XmlUtils;
39  import com.eviware.soapui.ui.desktop.DesktopPanel;
40  import com.eviware.soapui.ui.support.DefaultDesktopPanel;
41  
42  /***
43   * Shows a desktop-panel with the TestStepResult for a WsdlTestRequestStepResult
44   * 
45   * @author Ole.Matzura
46   */
47  
48  public class ShowRequestStepResultsAction extends AbstractAction
49  {
50  	private final WsdlTestRequestStepResult result;
51  	private DefaultDesktopPanel desktopPanel;
52  
53  	public ShowRequestStepResultsAction(WsdlTestStepResult result)
54  	{
55  		super( "Show Results" );
56  		
57  		this.result = (WsdlTestRequestStepResult) result;
58  	}
59  
60  	public void actionPerformed(ActionEvent e)
61  	{
62  		try
63  		{
64  			if( result.isDiscarded() )
65  				UISupport.showInfoMessage( "Request has been discarded.." );
66  			else
67  				UISupport.showDesktopPanel(buildFrame());
68  		}
69  		catch (Exception ex)
70  		{
71  			ex.printStackTrace();
72  		}		
73  	}
74  
75  	private DesktopPanel buildFrame()
76  	{
77  		if( desktopPanel == null )
78  		{
79  			desktopPanel = new DefaultDesktopPanel( "TestStep Result", 
80  						"TestStep result for " + result.getTestStep().getName(), buildContent() );
81  		}
82  		
83  		return desktopPanel;
84  	}
85  
86  	private JComponent buildContent()
87  	{
88  		JTabbedPane messageTabs = new JTabbedPane();
89  		messageTabs.addTab( "Request Properties", buildPropertiesTab() );
90  		messageTabs.addTab( "Request Message", buildRequestTab() );
91  		messageTabs.addTab( "Response Message", buildResponseTab() );
92  		messageTabs.setPreferredSize( new Dimension( 500, 400 ));
93  		
94  		JPanel panel = new JPanel( new BorderLayout() );
95  		panel.add( UISupport.createTabPanel( messageTabs, true ), BorderLayout.CENTER );
96  
97  		return panel;
98  	}
99  
100 	private Component buildPropertiesTab()
101 	{
102 		JPropertiesTable table = new JPropertiesTable<WsdlTestRequestStepResult>( "Result Properties", result );
103 		table.addProperty( "Status", "status" );
104 		table.addProperty( "Time Taken", "timeTaken" );
105 		table.addProperty( "Size", "size" );
106 		table.addProperty( "Timestamp", "timeStamp", false, new TimestampPropertyFormatter());
107 		table.addProperty( "TestStep", "testStep", false, new TestStepPropertyFormatter());
108 		
109 		table.addProperty( "Encoding", "encoding" );
110    	table.addProperty( "Endpoint", "endpoint" );
111    	table.addProperty( "Username", "username" );
112    	table.addProperty( "Password", "password" );
113    	table.addProperty( "Domain", "domain" );
114    	
115    	DefaultListModel listModel = new DefaultListModel();
116 		JList messageList = new JList( listModel );
117 		String[] messages = result.getMessages();
118 		for( String message : messages )
119 		{
120 			listModel.addElement( message );
121 		}
122 		
123 		JSplitPane split = UISupport.createVerticalSplit( table, new JScrollPane( messageList ));
124 		split.setDividerLocation( 200 );
125 		return split;
126 	}
127 
128 	private Component buildResponseTab()
129 	{
130 		JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
131       Response response = result.getResponse();
132       if( response != null )
133       	resultArea.setText( XmlUtils.prettyPrintXml( response.getContentAsString() ) );
134       else
135       	resultArea.setText( "- null -" );
136       resultArea.setEditable( false );
137       resultArea.setToolTipText( "Response Content" );
138 		JScrollPane scrollPane = new JScrollPane( resultArea );
139 		return scrollPane;
140 	}
141 
142 	private Component buildRequestTab()
143 	{
144 		JXEditTextArea resultArea = JXEditTextArea.createXmlEditor();
145       String requestContent = result.getRequestContent();
146       if( requestContent != null )
147       	resultArea.setText( XmlUtils.prettyPrintXml( requestContent ) );
148       else 
149       	resultArea.setText( "- null -" );
150       resultArea.setEditable( false );
151       resultArea.setToolTipText( "Request Content" );
152 		JScrollPane scrollPane = new JScrollPane( resultArea );
153 		return scrollPane;
154 	}
155 	
156 	private static final class TestStepPropertyFormatter implements PropertyFormatter
157 	{
158 		public Object format(String propertyName, Object value)
159 		{
160 			return ((TestStep)value).getName() ;
161 		}
162 	}
163 
164 	private static final class TimestampPropertyFormatter implements PropertyFormatter
165 	{
166 		public Object format(String propertyName, Object value)
167 		{
168 			return new Date( Long.valueOf( value.toString() ) );
169 		}
170 	}
171 }