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 org.apache.xmlbeans.XmlObject;
16:
17: import com.eviware.soapui.config.RequestAssertionConfig;
18: import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
19: import com.eviware.soapui.impl.wsdl.support.assertions.Assertable;
20: import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
21: import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
22: import com.eviware.soapui.model.iface.SubmitContext;
23:
24: /**
25: * Assertion that checks that the associated WsdlTestRequests response is a SOAP Fault
26: *
27: * @author Ole.Matzura
28: */
29:
30: public class SoapFaultAssertion extends WsdlMessageAssertion implements
31: ResponseAssertion {
32: public static final String ID = "Not SOAP Fault Assertion";
33:
34: // public static final String ID = "SOAP Fault";
35:
36: public SoapFaultAssertion(RequestAssertionConfig assertionConfig,
37: Assertable assertable) {
38: super (assertionConfig, assertable, false, false);
39: }
40:
41: public String internalAssertResponse(
42: WsdlMessageExchange messageExchange, SubmitContext context)
43: throws AssertionException {
44: String responseContent = messageExchange.getResponseContent();
45: try {
46: // check manually before resource intensive xpath
47: if (responseContent.indexOf(":Fault") > 0
48: || responseContent.indexOf("<Fault") > 0) {
49: SoapVersion soapVersion = messageExchange
50: .getOperation().getInterface().getSoapVersion();
51: XmlObject xml = XmlObject.Factory
52: .parse(responseContent);
53: XmlObject[] paths = xml
54: .selectPath("declare namespace env='"
55: + soapVersion.getEnvelopeNamespace()
56: + "';" + "//env:Fault");
57: if (paths.length == 0)
58: throw new AssertionException(new AssertionError(
59: "Response is not a SOAP Fault"));
60: } else
61: throw new AssertionException(new AssertionError(
62: "Response is not a SOAP Fault"));
63: } catch (Exception e) {
64: throw new AssertionException(new AssertionError(e
65: .getMessage()));
66: }
67:
68: return "Response is a SOAP Fault";
69: }
70:
71: @Override
72: protected String internalAssertRequest(
73: WsdlMessageExchange messageExchange, SubmitContext context)
74: throws AssertionException {
75: return null;
76: }
77: }
|