1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps.assertions.soap;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.config.TestAssertionConfig;
17 import com.eviware.soapui.impl.wsdl.panels.teststeps.support.WsaAssertionConfiguration;
18 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
19 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
20 import com.eviware.soapui.impl.wsdl.support.wsa.WsaValidator;
21 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
22 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMockResponseTestStep;
23 import com.eviware.soapui.impl.wsdl.teststeps.assertions.AbstractTestAssertionFactory;
24 import com.eviware.soapui.model.iface.MessageExchange;
25 import com.eviware.soapui.model.iface.SubmitContext;
26 import com.eviware.soapui.model.testsuite.*;
27 import com.eviware.soapui.model.testsuite.AssertionError;
28 import com.eviware.soapui.support.UISupport;
29 import com.eviware.soapui.support.types.StringToStringMap;
30 import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
31 import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
32 import com.eviware.x.form.XForm;
33 import com.eviware.x.form.XFormDialog;
34 import com.eviware.x.form.XFormDialogBuilder;
35 import com.eviware.x.form.XFormFactory;
36 import org.apache.xmlbeans.XmlException;
37 import org.apache.xmlbeans.XmlObject;
38
39 /***
40 * Assertion for verifying that WS-Addressing processing was ok
41 *
42 * @author dragica.soldo
43 */
44
45 public class WSARequestAssertion extends WsdlMessageAssertion implements
46 RequestAssertion, ResponseAssertion
47 {
48 public static final String ID = "WS-A Request Assertion";
49 public static final String LABEL = "WS-Addressing Request";
50 private WsaAssertionConfiguration wsaAssertionConfiguration;
51 private boolean assertWsaAction;
52 private boolean assertWsaTo;
53 private boolean assertWsaReplyTo;
54 private boolean assertWsaMessageId;
55
56
57
58 private XFormDialog dialog;
59 private static final String ASSERT_ACTION = "wsa:Action";
60 private static final String ASSERT_TO = "wsa:To";
61 private static final String ASSERT_REPLY_TO = "wsa:ReplyTo";
62 private static final String ASSERT_MESSAGE_ID = "wsa:MessageId";
63
64
65
66
67 /***
68 * Constructor for our assertion.
69 *
70 * @param assertionConfig
71 * @param modelItem
72 */
73 public WSARequestAssertion(
74 TestAssertionConfig assertionConfig,
75 Assertable modelItem
76 )
77 {
78 super( assertionConfig, modelItem, false, true, false, true );
79
80 XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader(
81 getConfiguration() );
82 assertWsaAction = reader.readBoolean( "asertWsaAction", true );
83 assertWsaTo = reader.readBoolean( "asertWsaTo", false );
84 assertWsaReplyTo = reader.readBoolean( "assertWsaReplyTo", false );
85 assertWsaMessageId = reader.readBoolean( "assertWsaMessageId", false );
86
87
88
89
90
91 wsaAssertionConfiguration = new WsaAssertionConfiguration(
92 assertWsaAction, assertWsaTo, assertWsaReplyTo, assertWsaMessageId, false,
93 false, false );
94 }
95
96 public static class Factory extends AbstractTestAssertionFactory
97 {
98 @SuppressWarnings( "unchecked" )
99 public Factory()
100 {
101 super( WSARequestAssertion.ID, WSARequestAssertion.LABEL, WSARequestAssertion.class, WsdlMockResponseTestStep.class );
102 }
103 }
104
105 @Override
106 protected String internalAssertRequest(
107 MessageExchange messageExchange,
108 SubmitContext context
109 ) throws AssertionException
110 {
111 try
112 {
113 new WsaValidator( (WsdlMessageExchange) messageExchange,
114 wsaAssertionConfiguration ).validateWsAddressingRequest();
115 }
116 catch( AssertionException e )
117 {
118 throw new AssertionException( new AssertionError( e.getMessage() ) );
119 }
120 catch( XmlException e )
121 {
122 SoapUI.logError( e );
123 throw new AssertionException(
124 new AssertionError(
125 "There has been some XmlException, ws-a couldn't be validated properly." ) );
126 }
127
128 return "Request WS-Addressing is valid";
129 }
130
131 @Override
132 protected String internalAssertResponse(
133 MessageExchange messageExchange,
134 SubmitContext context
135 ) throws AssertionException
136 {
137 try
138 {
139 new WsaValidator( (WsdlMessageExchange) messageExchange,
140 wsaAssertionConfiguration ).validateWsAddressingResponse();
141 }
142 catch( AssertionException e )
143 {
144 throw new AssertionException( new AssertionError( e.getMessage() ) );
145 }
146 catch( XmlException e )
147 {
148 SoapUI.logError( e );
149 throw new AssertionException(
150 new AssertionError(
151 "There has been some XmlException, ws-a couldn't be validated properly." ) );
152 }
153
154 return "Response WS-Addressing is valid";
155 }
156
157 public boolean configure()
158 {
159 if( dialog == null )
160 buildDialog();
161
162 StringToStringMap values = new StringToStringMap();
163 values.put( ASSERT_ACTION, assertWsaAction );
164 values.put( ASSERT_TO, assertWsaTo );
165 values.put( ASSERT_REPLY_TO, assertWsaReplyTo );
166 values.put( ASSERT_MESSAGE_ID, assertWsaMessageId );
167
168
169
170
171 values = dialog.show( values );
172 if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
173 {
174 assertWsaAction = values.getBoolean( ASSERT_ACTION );
175 assertWsaTo = values.getBoolean( ASSERT_TO );
176 assertWsaReplyTo = values.getBoolean( ASSERT_REPLY_TO );
177 assertWsaMessageId = values.getBoolean( ASSERT_MESSAGE_ID );
178
179
180
181
182
183 }
184
185 wsaAssertionConfiguration = new WsaAssertionConfiguration(
186 assertWsaAction, assertWsaTo, assertWsaReplyTo, assertWsaMessageId, false,
187 false, false );
188 setConfiguration( createConfiguration() );
189 return true;
190 }
191
192 private void buildDialog()
193 {
194 XFormDialogBuilder builder = XFormFactory
195 .createDialogBuilder( "Ws-a properties to assert" );
196 XForm mainForm = builder.createForm( "Basic" );
197 mainForm.addCheckBox( ASSERT_ACTION,
198 "Check if 'wsa:Action' exists and has the right value" );
199 mainForm.addCheckBox( ASSERT_TO, "Check if 'wsa:To' exists" );
200 mainForm.addCheckBox( ASSERT_REPLY_TO, "Check if 'wsa:ReplyTo' exists" );
201 mainForm.addCheckBox( ASSERT_MESSAGE_ID, "Check if 'wsa:MessageId' exists" );
202
203
204
205
206
207
208
209 dialog = builder.buildDialog( builder
210 .buildOkCancelHelpActions( HelpUrls.SIMPLE_CONTAINS_HELP_URL ),
211 "Specify options", UISupport.OPTIONS_ICON );
212 }
213
214 protected XmlObject createConfiguration()
215 {
216 XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
217 builder.add( "asertWsaAction", assertWsaAction );
218 builder.add( "asertWsaTo", assertWsaTo );
219 builder.add( "assertWsaReplyTo", assertWsaReplyTo );
220 builder.add( "assertWsaMessageId", assertWsaMessageId );
221
222
223
224 return builder.finish();
225 }
226
227 }