1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef example_diameter_launcher_TestStep_hpp
10 #define example_diameter_launcher_TestStep_hpp
17 #include <anna/core/DataBlock.hpp>
18 #include <anna/xml/Node.hpp>
21 #include <TestCondition.hpp>
44 int a_number; // step number used for xml (informational)
45 anna::Millisecond a_beginTimestamp; // unix time
46 anna::Millisecond a_endTimestamp; // unix time
48 void setBeginTimestamp(const anna::Millisecond &t) throw() { a_beginTimestamp = t; }
49 const anna::Millisecond &getBeginTimestamp() const throw() { return a_beginTimestamp; }
50 void setEndTimestamp(const anna::Millisecond &t) throw() { a_endTimestamp = t; }
51 const anna::Millisecond &getEndTimestamp() const throw() { return a_endTimestamp; }
53 void initialize(TestCase *testCase);
56 struct Type { enum _v { Unconfigured, Timeout, Sendxml2e, Sendxml2c, Delay, Wait }; };
57 static const char* asText(const Type::_v type) throw();
59 TestStep(TestCase *testCase) { initialize(testCase); }
60 virtual ~TestStep() {;}
63 const Type::_v &getType() const throw() { return a_type; }
64 const int &getNumber() const throw() { return a_number; }
65 bool isCompleted() const throw() { return a_completed; }
67 bool execute() throw();
68 void complete() throw();
71 virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
72 std::string asXMLString() const throw();
79 virtual bool do_execute() throw() = 0; // returns true if next step must be executed
80 virtual void do_complete() throw() = 0; // end of transaction (delay/timeout expired, wait condition fulfilled, sending done)
81 // In all cases, the next step will be executed except 'timeout' which is asynchronous
82 // and will move to the next step just after timer creation (no complete waited)
83 virtual void do_reset() throw() = 0;
87 class TestStepTimeout : public TestStep {
89 anna::Millisecond a_timeout;
90 TestTimer *a_timer; // just in case i would need to cancel
93 TestStepTimeout(TestCase *testCase) : TestStep(testCase), a_timeout(0), a_timer(NULL) { a_type = Type::Timeout; }
96 void setTimeout(const anna::Millisecond &t) throw() { a_timeout = t; }
97 const anna::Millisecond &getTimeout() const throw() { return a_timeout; }
100 bool do_execute() throw();
101 void do_complete() throw(); // timeout reached, test case failed
102 void do_reset() throw();
103 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
107 class TestStepSendxml : public TestStep {
110 // possible end points:
111 RealmNode *a_realmNode;
113 // Step number reference ('wait for request' step)
114 int a_waitForRequestStepNumber;
117 anna::DataBlock a_message;
120 bool a_expired; // a_endTimestamp will be the expiration reception timestamp
123 TestStepSendxml(TestCase *testCase) : TestStep(testCase), a_message(true), a_expired(false), a_realmNode(NULL), a_waitForRequestStepNumber(-1) {;}
126 void setRealmNode(RealmNode *realm) throw() { a_realmNode = realm; }
127 RealmNode *getRealmNode() const throw() { return a_realmNode; }
128 void setWaitForRequestStepNumber(int stepNumber) throw() { a_waitForRequestStepNumber = stepNumber; }
129 int getWaitForRequestStepNumber() const throw() { return a_waitForRequestStepNumber; }
130 void setMsgDataBlock(const anna::DataBlock &db) throw() { a_message = db; }
131 const anna::DataBlock &getMsgDataBlock() const throw() { return a_message; }
134 bool do_execute() throw();
135 void do_complete() throw();
136 void do_reset() throw();
137 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
140 class TestStepSendxml2e : public TestStepSendxml {
142 TestStepSendxml2e(TestCase *testCase) : TestStepSendxml(testCase) { a_type = Type::Sendxml2e; }
145 class TestStepSendxml2c : public TestStepSendxml {
147 TestStepSendxml2c(TestCase *testCase) : TestStepSendxml(testCase) { a_type = Type::Sendxml2c; }
151 class TestStepDelay : public TestStep {
152 anna::Millisecond a_delay;
153 TestTimer *a_timer; // just in case i would need to cancel
156 TestStepDelay(TestCase *testCase) : TestStep(testCase), a_delay(0), a_timer(NULL) { a_type = Type::Delay; }
159 void setDelay(const anna::Millisecond &d) throw() { a_delay = d; }
160 const anna::Millisecond &getDelay() const throw() { return a_delay; }
163 bool do_execute() throw();
164 void do_complete() throw(); // delay reached
165 void do_reset() throw();
166 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
170 class TestStepWait : public TestStep {
172 TestCondition a_condition;
173 anna::DataBlock a_message; // message which complies with condition
174 anna::diameter::comm::ClientSession *a_clientSession;
175 anna::diameter::comm::ServerSession *a_serverSession;
178 TestStepWait(TestCase *testCase) : TestStep(testCase) { a_type = Type::Wait; a_clientSession = NULL; a_serverSession = NULL; }
182 void setCondition(bool fromEntity,
183 const std::string &code, const std::string &bitR, const std::string &resultCode, const std::string &sessionId,
184 const std::string &hopByHop, const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw();
185 void setCondition(bool fromEntity, const std::string ®exp) throw();
187 void setClientSession(anna::diameter::comm::ClientSession *cs) throw() { a_clientSession = cs; }
188 void setServerSession(anna::diameter::comm::ServerSession *ss) throw() { a_serverSession = ss; }
190 const TestCondition &getCondition() const throw() { return a_condition; }
191 //void setMsgDataBlock(const anna::DataBlock &db) throw() { a_message = db; }
192 bool fulfilled(const anna::DataBlock &db/*, bool matchSessionId = true*/) throw();
193 const anna::DataBlock &getMsgDataBlock() const throw() { return a_message; }
197 bool do_execute() throw(); // this will be executed when test case starts (at least we could measure the time until condition is fulfilled)
198 void do_complete() throw(); // condition fulfilled
199 void do_reset() throw();
200 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();