Groovy
Groovy (beta)
code posted
created at 13 Mar 15:39
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
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{ } |
3.49 KB in 21 ms with coderay