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