Title / Description
Code package br.inpe.ocoe.test.scenario /** * This class represents a simple test scenario on AIT satellite. * For this scenario, there are pre and pos conditions. * @author luizalex * */ class Scenario01 extends Scenario{ //Variables definitions for this scenario def e001, e002, e003 //telemetries def e00x def tc001 //telecommands def scoeTTC //A TTC SCOE def Scenario01(){ //General Methods and variables setup = { //telemetries used on test e001 = new Telemetry(id:"E001") e002 = new Telemetry(id:"E002") e003 = new Telemetry(id:"E003") e00x = [e001,e002,e003] //group all telemetries e00x //telecommand to be send and verified tc001 = new Telecommand(id:"TC001") scoeTTC = new ScoeTTC() } /** * preconditions to starts scenario. Returns true if preconditions has been satisfied. */ preconditions = { def timeout = 1 * 5 * 1000 //3 seconds //force telemetries to not changed status e00x*.changed = false assert waitFor(timeout){e00x*.changed.every{it}} :"Timeout $timeout ms occurred!" //wait for telemetries to be changed assert e001.eng.value < 23 assert e002.text == "NORMAL" assert e003.raw.between (200, 255) } /** * The main scenario method. Returns true if no problems has been occurred. */ test = { def timeout = 1 * 30 * 1000 //30 seconds tc001.send() scoeTTC.send('COMMAND_001') assert waitFor(timeout){!tc001.received} } /** * postconditions to validated scenario. Returns true if postconditions has been satisfied. */ postconditions = { def timeout = 1 * 45 * 1000 //45 seconds assert waitFor (timeout) {e003.changed} assert e003.eng.between(2.5, 3.1) assert scoeTTC.read('parameter001') == 'DONE' } } } /************* Support Classes for Scenarios ***************/ abstract class Scenario{ //General Methods and variables def getNow () {new Date()} def isTimeout (startTime, timeout) { now.time > (startTime.time + timeout) } def waitFor(timeout, closure){ def startTime = now while (!closure() && !isTimeout(startTime, timeout)){Thread.sleep(100)} return !isTimeout(startTime, timeout) } def start = { setup() if (preconditions()) if (test()) if (postconditions()) println "Scenario executed successfully!" else println "Postconditions not satisfied!" else println "Test executions problems" else println "Preconditions not satisfied!" } /** * Method where variable are set */ def setup /** * preconditions to starts scenario. Returns true if preconditions was satisfied. */ def preconditions /** * The main scenario method. Returns true if no problems was occurs. */ def test /** * postconditions to validated scenario. Returns true if postconditions was satisfied. */ def postconditions } class Telemetry{ def id def eng = new EngValue() def raw = new RawValue() def changed = false def text } class Telecommand{ def id def send = {} def received = false } interface Value{ def value def between (a, b); } class EngValue implements Value{ def between (a, b){ return value >= [a,b].min() && value <= [a,b].max() } } class RawValue implements Value{ def between (a, b){ return (a..b).contains(value) } } abstract class Scoe{ def send = {} def read = {} } class ScoeTTC extends Scoe{ }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code