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.lang.ref.SoftReference;
16  
17  import com.eviware.soapui.impl.wsdl.panels.teststeps.amf.AMFRequest;
18  import com.eviware.soapui.impl.wsdl.panels.teststeps.amf.AMFResponse;
19  import com.eviware.soapui.impl.wsdl.support.assertions.AssertedXPathsContainer;
20  import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
21  import com.eviware.soapui.model.ModelItem;
22  import com.eviware.soapui.model.iface.Attachment;
23  import com.eviware.soapui.model.iface.MessageExchange;
24  import com.eviware.soapui.model.iface.Operation;
25  import com.eviware.soapui.model.testsuite.AssertedXPath;
26  import com.eviware.soapui.support.action.swing.ActionList;
27  import com.eviware.soapui.support.types.StringToStringMap;
28  import com.eviware.soapui.support.types.StringToStringsMap;
29  
30  public class AMFTestStepResult extends WsdlTestStepResult implements AssertedXPathsContainer, MessageExchange
31  {
32  	private AMFResponse response;
33  	private AMFRequest request;
34  	private SoftReference<AMFResponse> softResponse;
35  	private String requestContent;
36  	private boolean addedAction;
37  
38  	public AMFTestStepResult( AMFRequestTestStep testStep )
39  	{
40  		super( testStep );
41  		this.request = testStep.getAMFRequest();
42  
43  	}
44  
45  	public void setResponse( AMFResponse response, boolean useSoftReference )
46  	{
47  		if( useSoftReference )
48  			this.softResponse = new SoftReference<AMFResponse>( response );
49  		else
50  			this.response = response;
51  	}
52  
53  	public void setRequestContent( String requestContent )
54  	{
55  		this.requestContent = requestContent;
56  	}
57  
58  	public void addAssertedXPath( AssertedXPath assertedXPath )
59  	{
60  	}
61  
62  	@Override
63  	public ActionList getActions()
64  	{
65  		if( !addedAction )
66  		{
67  			addAction( new ShowMessageExchangeAction( this, "TestStep" ), true );
68  			addedAction = true;
69  		}
70  
71  		return super.getActions();
72  	}
73  
74  	public ModelItem getModelItem()
75  	{
76  		return getTestStep();
77  	}
78  
79  	public Operation getOperation()
80  	{
81  		return null;
82  	}
83  
84  	public StringToStringMap getProperties()
85  	{
86  		return new StringToStringMap();
87  	}
88  
89  	public String getProperty( String name )
90  	{
91  		return null;
92  	}
93  
94  	public byte[] getRawRequestData()
95  	{
96  		return hasResponse() ? getResponse().getRawRequestData() : null;
97  	}
98  
99  	public byte[] getRawResponseData()
100 	{
101 		return getResponse().getRawResponseData();
102 	}
103 
104 	public Attachment[] getRequestAttachments()
105 	{
106 		return new Attachment[0];
107 	}
108 
109 	public Attachment[] getRequestAttachmentsForPart( String partName )
110 	{
111 		return new Attachment[0];
112 	}
113 
114 	public String getRequestContent()
115 	{
116 		return requestContent != null ? requestContent : hasResponse() ? getResponse().getRequestContent() : null;
117 	}
118 
119 	public AMFResponse getResponse()
120 	{
121 		return softResponse != null ? softResponse.get() : response;
122 	}
123 
124 	public String getRequestContentAsXml()
125 	{
126 		return getRequest().requestAsXML();
127 	}
128 
129 	public StringToStringsMap getRequestHeaders()
130 	{
131 		return new StringToStringsMap();
132 	}
133 
134 	public Attachment[] getResponseAttachments()
135 	{
136 		return new Attachment[0];
137 	}
138 
139 	public Attachment[] getResponseAttachmentsForPart( String partName )
140 	{
141 		return new Attachment[0];
142 	}
143 
144 	public String getResponseContent()
145 	{
146 		return hasResponse() ? getResponse().getContentAsString() : null;
147 	}
148 
149 	public String getResponseContentAsXml()
150 	{
151 		return softResponse != null && softResponse.get() != null ? softResponse.get().getResponseContentXML() : null;
152 	}
153 
154 	public StringToStringsMap getResponseHeaders()
155 	{
156 		return new StringToStringsMap();
157 	}
158 
159 	public long getTimestamp()
160 	{
161 		return hasResponse() ? getResponse().getTimestamp() : -1;
162 	}
163 
164 	public boolean hasRawData()
165 	{
166 		return true;
167 	}
168 
169 	public boolean hasRequest( boolean ignoreEmpty )
170 	{
171 		return hasResponse();
172 	}
173 
174 	public boolean hasResponse()
175 	{
176 		return getResponse() != null;
177 	}
178 
179 	public String getEndpoint()
180 	{
181 
182 		return request.getEndpoint();
183 	}
184 
185 	public AMFRequest getRequest()
186 	{
187 		return request;
188 	}
189 
190 	public void setRequest( AMFRequest request )
191 	{
192 		this.request = request;
193 	}
194 
195 }