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;
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.types.StringToStringMap;
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 WsdlMessageExchangeStepResult extends WsdlTestStepResult
29  {
30  	private WsdlMessageExchange messageExchange;
31  	private StringToStringMap properties;
32  	
33  	public WsdlMessageExchangeStepResult(WsdlTestStep step )
34  	{
35  		super( step );
36  	}
37  	
38  	public void setMessageExchange( WsdlMessageExchange messageExchange )
39  	{
40  		this.messageExchange = messageExchange;
41  		addAction( new ShowMessageExchangeAction( messageExchange, "StepResult" ), true );
42  	}
43  
44  	public String getRequestContent()
45  	{
46  		if( isDiscarded() )
47  			return "<discarded>";
48  		
49  		return messageExchange == null ? null : messageExchange.getRequestContent();
50  	}
51  
52  	public void addProperty( String name, String value )
53  	{
54  		if( isDiscarded() )
55  			return;
56  		
57  		if( properties == null )
58  			properties = new StringToStringMap();
59  		
60  		properties.put( name, value );
61  	}
62  	
63  	public void discard()
64  	{
65  		super.discard();
66  		
67  		messageExchange = null;
68  		properties = null;
69  	}
70  
71  	public void writeTo(PrintWriter writer)
72  	{
73  		super.writeTo( writer );
74  		
75  		if( isDiscarded() )
76  			return;
77  		
78  		writer.println( "---------------- Properties ------------------------" );
79  		if( properties == null  )
80  		{
81  			writer.println( "Missing Properties" );
82  		}
83  		else
84  		{
85  			for( String name : properties.keySet() )
86  				writer.println( name + ": " + properties.get( name ) );
87  		}
88  
89  		writer.println( "---------------- Message Exchange ------------------" );
90  		if( messageExchange == null )
91  		{
92  			writer.println( "Missing MessageExchange" );
93  		}
94  		else
95  		{
96  			writer.println( "--- Request" );
97  			if( messageExchange.getRequestHeaders() != null )
98  				writer.println( "Request Headers: " + messageExchange.getRequestHeaders().toString() );
99  			
100 			writer.println( XmlUtils.prettyPrintXml( messageExchange.getRequestContent() ) );
101 
102 			writer.println( "--- Response" );
103 			if( messageExchange.getResponseHeaders() != null )
104 				writer.println( "Response Headers: " + messageExchange.getResponseHeaders().toString() );
105 			
106 			writer.println( XmlUtils.prettyPrintXml( messageExchange.getResponseContent() ) );
107 		}
108 	}
109 
110 	public StringToStringMap getProperties()
111 	{
112 		return properties;
113 	}
114 }