01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.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.assertions.Assertable;
18: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
19: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator;
20: import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
21: import com.eviware.soapui.model.iface.SubmitContext;
22:
23: /**
24: * Asserts that the specified message is a valid SOAP Message
25: *
26: * @author ole.matzura
27: */
28:
29: public class SoapResponseAssertion extends WsdlMessageAssertion
30: implements ResponseAssertion, RequestAssertion {
31: public static final String ID = "SOAP Response";
32:
33: public SoapResponseAssertion(
34: RequestAssertionConfig assertionConfig,
35: Assertable assertable) {
36: super (assertionConfig, assertable, false, false);
37: }
38:
39: @Override
40: protected String internalAssertResponse(
41: WsdlMessageExchange messageExchange, SubmitContext context)
42: throws AssertionException {
43: WsdlContext wsdlContext = messageExchange.getOperation()
44: .getInterface().getWsdlContext();
45: WsdlValidator validator = new WsdlValidator(wsdlContext);
46:
47: try {
48: AssertionError[] errors = validator.assertResponse(
49: messageExchange, true);
50: if (errors.length > 0)
51: throw new AssertionException(errors);
52: } catch (AssertionException e) {
53: throw e;
54: } catch (Exception e) {
55: throw new AssertionException(new AssertionError(e
56: .getMessage()));
57: }
58:
59: return "Response Envelope OK";
60: }
61:
62: @Override
63: protected String internalAssertRequest(
64: WsdlMessageExchange messageExchange, SubmitContext context)
65: throws AssertionException {
66: WsdlContext wsdlContext = messageExchange.getOperation()
67: .getInterface().getWsdlContext();
68: WsdlValidator validator = new WsdlValidator(wsdlContext);
69:
70: try {
71: AssertionError[] errors = validator.assertRequest(
72: messageExchange, true);
73: if (errors.length > 0)
74: throw new AssertionException(errors);
75: } catch (AssertionException e) {
76: throw e;
77: } catch (Exception e) {
78: throw new AssertionException(new AssertionError(e
79: .getMessage()));
80: }
81:
82: return "Request Envelope OK";
83: }
84: }
|