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 not a SOAP Fault
26: *
27: * @author Ole.Matzura
28: */
29:
30: public class NotSoapFaultAssertion extends WsdlMessageAssertion
31: implements ResponseAssertion {
32: public static final String ID = "SOAP Fault Assertion";
33: //public static final String ID = "Not SOAP Fault";
34: public static final String LABEL = "Not SOAP Fault";
35:
36: public NotSoapFaultAssertion(
37: RequestAssertionConfig assertionConfig,
38: Assertable assertable) {
39: super (assertionConfig, assertable, false, false);
40: }
41:
42: public String internalAssertResponse(
43: WsdlMessageExchange messageExchange, SubmitContext context)
44: throws AssertionException {
45: String responseContent = messageExchange.getResponseContent();
46: try {
47: // check manually before resource intensive xpath
48: if (responseContent.indexOf(":Fault") > 0
49: || responseContent.indexOf("<Fault") > 0) {
50: SoapVersion soapVersion = messageExchange
51: .getOperation().getInterface().getSoapVersion();
52: XmlObject xml = XmlObject.Factory
53: .parse(responseContent);
54: XmlObject[] paths = xml
55: .selectPath("declare namespace env='"
56: + soapVersion.getEnvelopeNamespace()
57: + "';" + "//env:Fault");
58: if (paths.length > 0)
59: throw new AssertionException(new AssertionError(
60: "Response is a SOAP Fault"));
61: }
62: } catch (Exception e) {
63: throw new AssertionException(new AssertionError(e
64: .getMessage()));
65: }
66:
67: return "Response is not a SOAP Fault";
68: }
69:
70: @Override
71: protected String internalAssertRequest(
72: WsdlMessageExchange messageExchange, SubmitContext context)
73: throws AssertionException {
74: return null;
75: }
76: }
|