1
2
3
4
5
6
7
8
9
10
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.panels.support.assertions.Assertable;
19 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
20 import com.eviware.soapui.impl.wsdl.submit.filters.PropertyExpansionRequestFilter;
21 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
22 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
23 import com.eviware.soapui.model.iface.SubmitContext;
24 import com.eviware.soapui.support.UISupport;
25 import com.eviware.soapui.support.types.StringToStringMap;
26 import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
27 import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
28 import com.eviware.x.form.XForm;
29 import com.eviware.x.form.XFormDialog;
30 import com.eviware.x.form.XFormDialogBuilder;
31 import com.eviware.x.form.XFormFactory;
32
33 /***
34 * Assertion that checks for the non-existence of a specified text token in the associated
35 * WsdlTestRequests response message
36 *
37 * @author Ole.Matzura
38 */
39
40 public class SimpleNotContainsAssertion extends WsdlMessageAssertion implements RequestAssertion, ResponseAssertion
41 {
42 private String token;
43 private boolean ignoreCase;
44 private XFormDialog dialog;
45 public static final String ID = "Simple NotContains";
46 private static final String CONTENT = "Content";
47 private static final String IGNORE_CASE = "Ignore Case";
48
49 public SimpleNotContainsAssertion(RequestAssertionConfig assertionConfig, Assertable assertable)
50 {
51 super(assertionConfig, assertable);
52
53 XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader( getConfiguration() );
54 token = reader.readString( "token", null );
55 ignoreCase = reader.readBoolean( "ignoreCase", false );
56 }
57
58 public String internalAssertResponse(WsdlMessageExchange messageExchange, SubmitContext context) throws AssertionException
59 {
60 return assertContent( context, messageExchange.getResponseContent(), "Response" );
61 }
62
63 private String assertContent( SubmitContext context, String content, String type ) throws AssertionException
64 {
65 if( token == null ) token = "";
66
67 String replToken = PropertyExpansionRequestFilter.expandProperties( context, token );
68
69 if( replToken.length() > 0 )
70 {
71 int ix = ignoreCase ?
72 content.toUpperCase().indexOf( replToken.toUpperCase() ) : content.indexOf( replToken );
73
74 if( ix != -1 )
75 throw new AssertionException( new AssertionError( type + " contains token [" + replToken + "]") );
76 }
77
78 return type + " does not contain token [" + replToken + "]";
79 }
80
81 public boolean configure()
82 {
83 if( dialog == null )
84 buildDialog();
85
86 StringToStringMap values = new StringToStringMap();
87 values.put( CONTENT, token );
88 values.put( IGNORE_CASE, ignoreCase );
89
90 values = dialog.show( values );
91 if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
92 {
93 token = values.get( CONTENT );
94 ignoreCase = values.getBoolean( IGNORE_CASE );
95 }
96
97 setConfiguration( createConfiguration() );
98 return true;
99 }
100
101 protected XmlObject createConfiguration()
102 {
103 XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
104 builder.add( "token", token );
105 builder.add( "ignoreCase", ignoreCase );
106 return builder.finish();
107 }
108
109 public boolean isConfigurable()
110 {
111 return true;
112 }
113
114 private void buildDialog()
115 {
116 XFormDialogBuilder builder = XFormFactory.createDialogBuilder("Simple NotContains Assertion");
117 XForm mainForm = builder.createForm( "Basic" );
118
119 mainForm.addTextField( CONTENT, "Content to check for", XForm.FieldType.TEXT ).setWidth( 20 );
120 mainForm.addCheckBox( IGNORE_CASE, "Ignore case in comparison" );
121
122 dialog = builder.buildDialog( builder.buildOkCancelHelpActions( HelpUrls.SIMPLE_NOT_CONTAINS_HELP_URL ),
123 "Specify options", UISupport.OPTIONS_ICON );
124 }
125
126 protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
127 {
128 return assertContent( context, messageExchange.getRequestContent(), "Request" );
129 }
130 }