1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps.assertions;
14
15 import javax.swing.JOptionPane;
16
17 import org.apache.xmlbeans.XmlCursor;
18 import org.apache.xmlbeans.XmlObject;
19
20 import com.eviware.soapui.SoapUI;
21 import com.eviware.soapui.config.RequestAssertionConfig;
22 import com.eviware.soapui.impl.wsdl.teststeps.WsdlAssertion;
23 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
24
25 /***
26 * Assertion that checks for the non-existence of a specified text token in the associated
27 * WsdlTestRequests response message
28 *
29 * @author Ole.Matzura
30 */
31
32 public class SimpleNotContainsAssertion extends WsdlAssertion
33 {
34 private String token;
35
36 public SimpleNotContainsAssertion(RequestAssertionConfig assertionConfig, WsdlTestRequest request)
37 {
38 super(assertionConfig, request);
39
40 XmlObject[] paths = getConfiguration().selectPath( "$this/token" );
41 if( paths.length != 1 ) return;
42
43 token = paths[0].newCursor().getTextValue();
44 }
45
46 public String assertRequest(WsdlTestRequest request) throws AssertionException
47 {
48 String response = request.getResponseContent();
49 if( token == null ) token = "";
50
51 if( token.length() > 0 && response.indexOf( token ) != -1 )
52 {
53 throw new AssertionException( new AssertionError("Response contains token [" + token + "]") );
54 }
55
56 return "Response does not contain token [" + token + "]";
57 }
58
59 public void configure()
60 {
61 String value = (String) JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(),
62 "Configure SimpleNotContains Assertion", "Specify token to be missing",
63 JOptionPane.QUESTION_MESSAGE, null, null, token );
64
65 if( value == null || value.equals( token )) return;
66 token = value;
67
68 setConfiguration( createConfiguration() );
69 }
70
71 protected XmlObject createConfiguration()
72 {
73 XmlObject config = XmlObject.Factory.newInstance();
74 XmlCursor cursor = config.newCursor();
75 cursor.toNextToken();
76 cursor.beginElement( "token" );
77 cursor.insertChars( token );
78 cursor.dispose();
79 return config;
80 }
81
82 public boolean isConfigurable()
83 {
84 return true;
85 }
86 }