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.panels.mockoperation;
14  
15  import java.util.Vector;
16  
17  import com.eviware.soapui.impl.wsdl.WsdlOperation;
18  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
19  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;
20  import com.eviware.soapui.impl.wsdl.submit.AbstractWsdlMessageExchange;
21  import com.eviware.soapui.model.ModelItem;
22  import com.eviware.soapui.model.iface.Attachment;
23  import com.eviware.soapui.support.types.StringToStringMap;
24  
25  /***
26   * WsdlMessageExchange for a WsdlMockResult, required for validations
27   * 
28   * @author ole.matzura
29   */
30  
31  public class WsdlMockResultMessageExchange extends AbstractWsdlMessageExchange<ModelItem>
32  {
33  	private final WsdlMockResult mockResult;
34  	private WsdlMockResponse mockResponse;
35  
36  	public WsdlMockResultMessageExchange( WsdlMockResult mockResult, WsdlMockResponse mockResponse )
37  	{
38  		super( mockResponse );
39  
40  		this.mockResult = mockResult;
41  		this.mockResponse = mockResponse;
42  	}
43  
44  	public ModelItem getModelItem()
45  	{
46  		return mockResponse == null ? mockResult.getMockOperation() : mockResponse;
47  	}
48  
49  	public String getEndpoint()
50  	{
51  		return mockResult.getMockRequest().getHttpRequest().getRequestURI();
52  	}
53  
54  	public Attachment[] getRequestAttachments()
55  	{
56  		return mockResult.getMockRequest().getRequestAttachments();
57  	}
58  
59  	public String getRequestContent()
60  	{
61  		if( mockResult == null || mockResult.getMockRequest() == null )
62  			return null;
63  
64  		return mockResult.getMockRequest().getRequestContent();
65  	}
66  
67  	public StringToStringMap getRequestHeaders()
68  	{
69  		return mockResult == null ? null : mockResult.getMockRequest().getRequestHeaders();
70  	}
71  
72  	public Attachment[] getResponseAttachments()
73  	{
74  		return mockResult == null || mockResponse == null ? new Attachment[0] : mockResult.getMockResponse()
75  				.getAttachments();
76  	}
77  
78  	public String getResponseContent()
79  	{
80  		return mockResult == null ? null : mockResult.getResponseContent();
81  	}
82  
83  	public StringToStringMap getResponseHeaders()
84  	{
85  		return mockResult == null ? null : mockResult.getResponseHeaders();
86  	}
87  
88  	public WsdlOperation getOperation()
89  	{
90  		if( mockResult.getMockOperation() != null )
91  			return mockResult.getMockOperation().getOperation();
92  
93  		return mockResponse == null ? null : mockResponse.getMockOperation().getOperation();
94  	}
95  
96  	public long getTimeTaken()
97  	{
98  		return mockResult == null ? -1 : mockResult.getTimeTaken();
99  	}
100 
101 	public long getTimestamp()
102 	{
103 		return mockResult == null ? -1 : mockResult.getTimestamp();
104 	}
105 
106 	public boolean isDiscarded()
107 	{
108 		return mockResponse == null;
109 	}
110 
111 	public void discard()
112 	{
113 		mockResponse = null;
114 	}
115 
116 	public Vector<?> getRequestWssResult()
117 	{
118 		return mockResult == null ? null : mockResult.getRequestWssResult();
119 	}
120 
121 	public Vector<?> getResponseWssResult()
122 	{
123 		return null;
124 	}
125 
126 	public int getResponseStatusCode()
127 	{
128 		return mockResult.getResponseStatus();
129 	}
130 
131 	public String getResponseContentType()
132 	{
133 		return mockResult.getResponseContentType();
134 	}
135 }