View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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;
14  
15  import java.io.PrintWriter;
16  
17  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
18  import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
19  import com.eviware.soapui.support.action.swing.ActionList;
20  import com.eviware.soapui.support.xml.XmlUtils;
21  
22  /***
23   * TestStep Result for a WsdlMessageExchange
24   * 
25   * @author ole.matzura
26   */
27  
28  public class WsdlSingleMessageExchangeTestStepResult extends WsdlTestStepResult
29  {
30  	private WsdlMessageExchange messageExchange;
31  	private boolean addedAction;
32  
33  	// private StringToStringMap properties;
34  
35  	public WsdlSingleMessageExchangeTestStepResult( WsdlTestStep step )
36  	{
37  		super( step );
38  	}
39  
40  	public void setMessageExchange( WsdlMessageExchange messageExchange )
41  	{
42  		this.messageExchange = messageExchange;
43  	}
44  
45  	@Override
46  	public ActionList getActions()
47  	{
48  		if( !addedAction )
49  		{
50  			addAction( new ShowMessageExchangeAction( messageExchange, "StepResult" ), true );
51  			addedAction = true;
52  		}
53  
54  		return super.getActions();
55  	}
56  
57  	// public String getRequestContent()
58  	// {
59  	// if( isDiscarded() )
60  	// return "<discarded>";
61  	//		
62  	// return messageExchange == null ? null :
63  	// messageExchange.getRequestContent();
64  	// }
65  	//
66  	// public void addProperty( String name, String value )
67  	// {
68  	// if( isDiscarded() )
69  	// return;
70  	//		
71  	// if( properties == null )
72  	// properties = new StringToStringMap();
73  	//		
74  	// properties.put( name, value );
75  	// }
76  
77  	public void discard()
78  	{
79  		super.discard();
80  
81  		messageExchange = null;
82  		// properties = null;
83  	}
84  
85  	public void writeTo( PrintWriter writer )
86  	{
87  		super.writeTo( writer );
88  
89  		if( isDiscarded() )
90  			return;
91  
92  		writer.println( "---------------- Message Exchange ------------------" );
93  		if( messageExchange == null )
94  		{
95  			writer.println( "Missing MessageExchange" );
96  		}
97  		else
98  		{
99  			writer.println( "--- Request" );
100 			if( messageExchange.getRequestHeaders() != null )
101 				writer.println( "Request Headers: " + messageExchange.getRequestHeaders().toString() );
102 
103 			writer.println( XmlUtils.prettyPrintXml( messageExchange.getRequestContent() ) );
104 
105 			writer.println( "--- Response" );
106 			if( messageExchange.getResponseHeaders() != null )
107 				writer.println( "Response Headers: " + messageExchange.getResponseHeaders().toString() );
108 
109 			writer.println( XmlUtils.prettyPrintXml( messageExchange.getResponseContent() ) );
110 		}
111 	}
112 }