View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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 com.eviware.soapui.impl.wsdl.WsdlOperation;
16  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
17  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;
18  import com.eviware.soapui.impl.wsdl.submit.AbstractWsdlMessageExchange;
19  import com.eviware.soapui.model.ModelItem;
20  import com.eviware.soapui.model.iface.Attachment;
21  import com.eviware.soapui.support.types.StringToStringMap;
22  
23  import java.util.Vector;
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 Attachment[] getRequestAttachments()
50  	{
51  		return mockResult.getMockRequest().getRequestAttachments();
52  	}
53  
54  	public String getRequestContent()
55  	{
56  		if( mockResult == null || mockResult.getMockRequest() == null )
57  			return null;
58  
59  		return mockResult.getMockRequest().getRequestContent();
60  	}
61  
62  	public StringToStringMap getRequestHeaders()
63  	{
64  		return mockResult == null ? null : mockResult.getMockRequest().getRequestHeaders();
65  	}
66  
67  	public Attachment[] getResponseAttachments()
68  	{
69  		return mockResult == null || mockResponse == null ? new Attachment[0] : mockResult.getMockResponse().getAttachments();
70  	}
71  
72  	public String getResponseContent()
73  	{
74  		return mockResult == null ? null : mockResult.getResponseContent();
75  	}
76  
77  	public StringToStringMap getResponseHeaders()
78  	{
79  		return mockResult == null ? null : mockResult.getResponseHeaders();
80  	}
81  
82  	public WsdlOperation getOperation()
83  	{
84  		if( mockResult.getMockOperation() != null )
85  			return mockResult.getMockOperation().getOperation();
86  		
87  		return mockResponse == null ? null : mockResponse.getMockOperation().getOperation();
88  	}
89  
90  	public long getTimeTaken()
91  	{
92  		return mockResult == null ? -1 : mockResult.getTimeTaken();
93  	}
94  
95  	public long getTimestamp()
96  	{
97  		return mockResult == null ? -1 : mockResult.getTimestamp();
98  	}
99  
100 	public boolean isDiscarded()
101 	{
102 		return mockResponse == null;
103 	}
104 
105 	public void discard()
106 	{
107 		mockResponse = null;
108 	}
109 	
110 	public Vector<?> getRequestWssResult()
111 	{
112 		return mockResult == null ? null : mockResult.getRequestWssResult();
113 	}
114 
115 	public Vector<?> getResponseWssResult()
116 	{
117 		return null;
118 	}
119 
120    public int getResponseStatusCode()
121    {
122       return mockResult.getResponseStatus();
123    }
124 
125    public String getResponseContentType()
126    {
127       return mockResult.getResponseContentType();
128    }
129 }