module SOAP_client { // written by Bernard Stepien // bernard.stepien@sympatico.ca // datatype definitions type record ttcn3DateType { integer Year, integer Month, integer Day } type record ttcn3TimeType { integer Hour, integer Minutes, integer Seconds } type record location_Type { charstring city, charstring country } type record timeframe_Type { ttcn3DateType dateWeather, ttcn3TimeType fromTime, ttcn3TimeType toTime } type record weatherRequest { location_Type location, timeframe_Type timeframe } type record weatherResponse { location_Type location, timeframe_Type timeframe, integer temperature, charstring conditions, integer barometric_pressure }; type record ErrorResponse { charstring reason } // test data definitions template ttcn3TimeType noon := { Hour := 12, Minutes := 0, Seconds := 0 } template ttcn3DateType today := { Year := 2001, Month := 11, Day := 14 } template ttcn3TimeType midnight := { Hour := 24, Minutes := 0, Seconds := 0 } template weatherRequest getWeatherBerlin_templ := { location := {city := "berlin", country := "germany"}, timeframe := { dateWeather := today, fromTime := noon, toTime := midnight } }; template weatherRequest getWeatherLondon_templ modifies getWeatherBerlin_templ := { location := {city := "london", country := "england"} }; template weatherRequest getWeatherNewYork_templ modifies getWeatherBerlin_templ := { location := {city := "new york", country := "USA"} }; template weatherRequest getWeatherTokyo_templ modifies getWeatherBerlin_templ := { location := {city := "tokyo", country := "japan"} }; template weatherResponse soap_response(charstring theCity, charstring theCountry) := { location := {city := theCity, country := theCountry}, timeframe := ?, temperature := (-50..50), conditions := ?, barometric_pressure := ? }; template ErrorResponse soap_error_response := { reason := ? } // communication configuration definitions type port SOAP message { out weatherRequest; in weatherResponse, ErrorResponse; } type component MTCType { timer soapTimer := 10.0; var ErrorResponse theErrorResponse; port SOAP soap_port; } type component SystemType { port SOAP system_soap_port; } // test cases definitions testcase GetWeatherGeneric(charstring theCity, charstring theCountry, weatherRequest theTemplate) runs on MTCType system SystemType { log("asking for the weather in " & theCity & " in " & theCountry); map(mtc:soap_port, system:system_soap_port); soap_port.send(theTemplate); soapTimer.start; alt { [] soap_port.receive(soap_response(theCity, theCountry)) { setverdict(pass) } [] AbnormalBehavior("berlin") }; stop } testcase GetWeatherBerlin() runs on MTCType system SystemType { log("asking for the weather in Berlin"); map(mtc:soap_port, system:system_soap_port); soap_port.send(getWeatherBerlin_templ); soapTimer.start; alt { [] soap_port.receive(soap_response("berlin", "germany")) { setverdict(pass) } [] AbnormalBehavior("berlin") }; stop } testcase GetWeatherLondon() runs on MTCType system SystemType { map(mtc:soap_port, system:system_soap_port); soap_port.send(getWeatherLondon_templ); soapTimer.start; alt { [] soap_port.receive(soap_response("london", "england")) { setverdict(pass) } [] AbnormalBehavior("london") }; stop } testcase GetWeatherCityMismatch() runs on MTCType system SystemType { map(mtc:soap_port, system:system_soap_port); // asking for the weather in London, England soap_port.send(getWeatherLondon_templ); soapTimer.start; alt { // the wrong city name has been entered for the soap_response parametric template // in order to end up in the catch all receive of the AbnormalBehavior altstep [] soap_port.receive(soap_response("dublin", "ireland")) { setverdict(pass) } [] AbnormalBehavior("asked london weather but gave dublin as parm for response ") }; stop } testcase GetWeatherNewYork() runs on MTCType system SystemType { map(mtc:soap_port, system:system_soap_port); soap_port.send(getWeatherNewYork_templ); soapTimer.start; alt { [] soap_port.receive(soap_response("new york", "usa")) { setverdict(pass) } [] AbnormalBehavior("new york") }; stop } testcase GetWeatherTokyo() runs on MTCType system SystemType { map(mtc:soap_port, system:system_soap_port); soap_port.send(getWeatherTokyo_templ); soapTimer.start; alt { [] soap_port.receive(soap_response("tokyo", "japan")) { soapTimer.stop; setverdict(pass) } [] AbnormalBehavior("tokyo") }; stop } altstep AbnormalBehavior(charstring theCity) runs on MTCType { [] soap_port.receive(soap_error_response) -> value theErrorResponse { var charstring theErrorMsg := "received a 404 error, reason: " & theErrorResponse.reason; soapTimer.stop; log(theErrorMsg); setverdict(fail) } [] soap_port.receive { log("received a response that doesn't match the template or is of the wrong type, expecting soap_response or soap_error_response"); setverdict(fail) } [] soapTimer.timeout { log("weather request for " & theCity & " has timed out"); setverdict(fail) } } control { var integer i; execute(GetWeatherGeneric("berlin","germany", getWeatherBerlin_templ)); for(i:=0; i < 2; i:=i+1) { execute ( GetWeatherBerlin() ) } execute( GetWeatherLondon() ) } } with { encode "SOAP"; }