1 package com.eviware.soapui.impl.wsdl.teststeps.assertions;
2
3 import org.apache.xmlbeans.XmlObject;
4
5 import com.eviware.soapui.config.RequestAssertionConfig;
6 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
7 import com.eviware.soapui.impl.wsdl.support.assertions.Assertable;
8 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
9 import com.eviware.soapui.model.iface.SubmitContext;
10 import com.eviware.soapui.support.UISupport;
11 import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
12 import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
13
14 /***
15 * Assertion for verifiying that responses occurred in the desired amount of
16 * time.
17 *
18 * @author Cory Lewis cory.lewis@genworth.com
19 *
20 * with help from
21 * @author Ole.Matzura
22 */
23
24 public class ResponseSLAAssertion extends WsdlMessageAssertion implements ResponseAssertion
25 {
26 public static final String ID = "Response SLA Assertion";
27 private String SLA;
28
29 /***
30 * Constructor for our assertion.
31 *
32 * @param assertionConfig
33 * @param modelItem
34 */
35 public ResponseSLAAssertion( RequestAssertionConfig assertionConfig, Assertable modelItem )
36 {
37 super( assertionConfig, modelItem, false, true );
38 XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader( getConfiguration() );
39 SLA = reader.readString( "SLA", "200" );
40 }
41
42 /***
43 * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#internalAssertRequest(com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange,
44 * com.eviware.soapui.model.iface.SubmitContext)
45 */
46 protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context )
47 throws AssertionException
48 {
49
50 return null;
51
52 }
53
54 /***
55 * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#internalAssertResponse(com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange,
56 * com.eviware.soapui.model.iface.SubmitContext)
57 */
58 protected String internalAssertResponse( WsdlMessageExchange messageExchange, SubmitContext context )
59 throws AssertionException
60 {
61
62
63 if( messageExchange.getTimeTaken() > Long.parseLong( SLA ) )
64 {
65 throw new AssertionException( new AssertionError( "Response did not meet SLA "
66 + messageExchange.getTimeTaken() + "/" + SLA ) );
67 }
68
69 return "Response meets SLA";
70 }
71
72 /***
73 * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#configure()
74 */
75 public boolean configure()
76 {
77 String value = SLA;
78
79 if( value == null || value.trim().length() == 0 )
80 {
81 value = "200";
82 }
83
84 value = UISupport.prompt( "Specify desired response time", "Configure Response SLA Assertion", value );
85
86 try
87 {
88 Long.parseLong( value );
89 SLA = value;
90
91 }
92 catch( Exception e )
93 {
94 return false;
95 }
96
97 setConfiguration( createConfiguration() );
98 return true;
99 }
100
101
102
103 public String getSLA()
104 {
105 return SLA;
106 }
107
108 public void setSLA( String sla )
109 {
110 SLA = sla;
111 setConfiguration( createConfiguration() );
112 }
113
114 /***
115 * @return XmlObject, our config chunk
116 */
117 protected XmlObject createConfiguration()
118 {
119 XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
120 return builder.add( "SLA", SLA ).finish();
121 }
122 }