001: package com.eviware.soapui.impl.wsdl.teststeps.assertions;
002:
003: import org.apache.xmlbeans.XmlObject;
004:
005: import com.eviware.soapui.config.RequestAssertionConfig;
006: import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
007: import com.eviware.soapui.impl.wsdl.support.assertions.Assertable;
008: import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
009: import com.eviware.soapui.model.iface.SubmitContext;
010: import com.eviware.soapui.support.UISupport;
011: import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
012: import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
013:
014: /**
015: * Assertion for verifiying that responses occurred in the desired amount of
016: * time.
017: *
018: * @author Cory Lewis cory.lewis@genworth.com
019: *
020: * with help from
021: * @author Ole.Matzura
022: */
023:
024: public class ResponseSLAAssertion extends WsdlMessageAssertion
025: implements ResponseAssertion {
026: public static final String ID = "Response SLA Assertion";
027: private String SLA;
028:
029: /**
030: * Constructor for our assertion.
031: *
032: * @param assertionConfig
033: * @param modelItem
034: */
035: public ResponseSLAAssertion(RequestAssertionConfig assertionConfig,
036: Assertable modelItem) {
037: super (assertionConfig, modelItem, false, true);
038: XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader(
039: getConfiguration());
040: SLA = reader.readString("SLA", "200");
041: }
042:
043: /**
044: * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#internalAssertRequest(com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange,
045: * com.eviware.soapui.model.iface.SubmitContext)
046: */
047: protected String internalAssertRequest(
048: WsdlMessageExchange messageExchange, SubmitContext context)
049: throws AssertionException {
050:
051: return null;
052:
053: }
054:
055: /**
056: * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#internalAssertResponse(com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange,
057: * com.eviware.soapui.model.iface.SubmitContext)
058: */
059: protected String internalAssertResponse(
060: WsdlMessageExchange messageExchange, SubmitContext context)
061: throws AssertionException {
062:
063: // assert!
064: if (messageExchange.getTimeTaken() > Long.parseLong(SLA)) {
065: throw new AssertionException(new AssertionError(
066: "Response did not meet SLA "
067: + messageExchange.getTimeTaken() + "/"
068: + SLA));
069: }
070:
071: return "Response meets SLA";
072: }
073:
074: /**
075: * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#configure()
076: */
077: public boolean configure() {
078: String value = SLA;
079:
080: if (value == null || value.trim().length() == 0) {
081: value = "200";
082: }
083:
084: value = UISupport.prompt("Specify desired response time",
085: "Configure Response SLA Assertion", value);
086:
087: try {
088: Long.parseLong(value);
089: SLA = value;
090:
091: } catch (Exception e) {
092: return false;
093: }
094:
095: setConfiguration(createConfiguration());
096: return true;
097: }
098:
099: public String getSLA() {
100: return SLA;
101: }
102:
103: public void setSLA(String sla) {
104: SLA = sla;
105: setConfiguration(createConfiguration());
106: }
107:
108: /**
109: * @return XmlObject, our config chunk
110: */
111: protected XmlObject createConfiguration() {
112: XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
113: return builder.add("SLA", SLA).finish();
114: }
115: }
|