soapUI: Code snippet notes



groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
 
inventorySummaryResponse = groovyUtils.getXmlHolder("getInventorySummary returns quantity 24#Response");
inventorySummaryResponse.declareNamespace("soapEnv", "http://schemas.xmlsoap.org/soap/envelope/" );
inventorySummaryResponse.declareNamespace("ns2", "http://service.unifiedinventory.inventory.ticketmaster.com/" )
 
inventorySummaryList = inventorySummaryResponse.getDomNodes("//inventorySummary");

int counter;
for (inventorySummary in inventorySummaryList) {
  quantities = inventorySummary.getChildNodes();
  
  for (quantity in quantities){
    if (quantity.getNodeName() == "quantity") {
      for (place in quantity.getChildNodes() ) {
        if (place.getNodeName() == "place") {
          if (place.getAttributes().getNamedItem("availabilityStatusId").getNodeValue() == "1") {
            counter++;            
          }
        }
      }
    }
  }
}

log.info counter.toString();
assert counter == 24;

//////////////////////////////////////

groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

// Read each productVariantRevision and count it and assert the numbers expected are present.
int counter = 0;
teststep = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel();
holder = groovyUtils.getXmlHolder(teststep + "#Response");
//def holder = groovyUtils.getXmlHolder("getProductVariantRevision - productId & 2 productVariantIds returns success#Response");

use (groovy.xml.dom.DOMCategory) {
    for(node in holder.getDomNodes("//productVariantRevision/productVariantRevision")) {
        node.children().each { child -> 
          if (child.getNodeValue() != null) {
              counter++;
              log.info child.getNodeValue();
          }            
        }
    }
}

log.info counter.toString();
assert counter == 1;

//////////////////////////////////////

assert messageExchange.responseHeaders["TMPS-Polling-HTTP-Response-Code"].contains("404");
assert !messageExchange.responseHeaders["TMPS-Correlation-Id"].contains(null);
assert messageExchange.hasResponse() == false
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["#status#"]).containsValue("HTTP/1.1 500");
assert messageExchange.getResponseContent().contains("Request validation failed");
assert messageExchange.getResponseContent().contains("Unmarshalling Error");
assert messageExchange.getResponseContent().contains("ACTIVE");

import com.eviware.soapui.support.XmlHolder;

assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["#status#"]).containsValue("HTTP/1.1 200");
def holder = new XmlHolder(messageExchange.responseContentAsXml);
assert holder["//maxProductVariantRevision"] == "1";

//////////////////////////////////////

groovyUtils.setPropertyValue("Properties", "callerRequestId", 'csi-smoke-000'+System.currentTimeMillis());

Leave a Reply

Your email address will not be published. Required fields are marked *