1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps.assertions;
14
15 import com.eviware.soapui.config.RequestAssertionConfig;
16 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
17 import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
18 import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator;
19 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
20 import com.eviware.soapui.model.iface.SubmitContext;
21 import com.eviware.soapui.model.testsuite.Assertable;
22 import com.eviware.soapui.model.testsuite.AssertionError;
23 import com.eviware.soapui.model.testsuite.AssertionException;
24 import com.eviware.soapui.model.testsuite.RequestAssertion;
25 import com.eviware.soapui.model.testsuite.ResponseAssertion;
26
27 /***
28 * Asserts that the specified message is a valid SOAP Message
29 *
30 * @author ole.matzura
31 */
32
33 public class SoapResponseAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
34 {
35 public static final String ID = "SOAP Response";
36
37 public SoapResponseAssertion( RequestAssertionConfig assertionConfig, Assertable assertable )
38 {
39 super( assertionConfig, assertable, false, false, false, true );
40 }
41
42 @Override
43 protected String internalAssertResponse( WsdlMessageExchange messageExchange, SubmitContext context )
44 throws AssertionException
45 {
46 WsdlContext wsdlContext = messageExchange.getOperation().getInterface().getWsdlContext();
47 WsdlValidator validator = new WsdlValidator( wsdlContext );
48
49 try
50 {
51 AssertionError[] errors = validator.assertResponse( messageExchange, true );
52 if (errors.length > 0)
53 throw new AssertionException(errors);
54 }
55 catch( AssertionException e )
56 {
57 throw e;
58 }
59 catch (Exception e)
60 {
61 throw new AssertionException( new AssertionError( e.getMessage() ));
62 }
63
64 return "Response Envelope OK";
65 }
66
67 @Override
68 protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
69 {
70 WsdlContext wsdlContext = messageExchange.getOperation().getInterface().getWsdlContext();
71 WsdlValidator validator = new WsdlValidator( wsdlContext );
72
73 try
74 {
75 AssertionError[] errors = validator.assertRequest( messageExchange, true );
76 if (errors.length > 0)
77 throw new AssertionException(errors);
78 }
79 catch( AssertionException e )
80 {
81 throw e;
82 }
83 catch (Exception e)
84 {
85 throw new AssertionException( new AssertionError( e.getMessage() ));
86 }
87
88 return "Request Envelope OK";
89 }
90 }