anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
try {
- testManager.getTestCase(id)->setDescription(description); // creates / reuses
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->setDescription(description);
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
try {
- testManager.getTestCase(id)->addIpLimit(amount); // creates / reuses
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->addIpLimit(amount);
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
try {
anna::Millisecond timeout = my_app.checkTimeMeasure("Test case timeout", anna::functions::asString(msecs));
- testManager.getTestCase(id)->addTimeout(timeout); // creates / reuses
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->addTimeout(timeout);
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
);
try {
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
my_app.updateOperatedOriginHostWithMessage(codecMsg);
if (_2e_or_2c)
- testManager.getTestCase(id)->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses
+ tc->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber);
else
- testManager.getTestCase(id)->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses
+ tc->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber);
- response = "Done";
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
try {
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
anna::Millisecond delay = ((msecs == 0 /* special case */) ? (anna::Millisecond)0 : my_app.checkTimeMeasure("Test case delay step", anna::functions::asString(msecs)));
- testManager.getTestCase(id)->addDelay(delay); // creates / reuses
- response = "Done";
+ tc->addDelay(delay); // creates / reuses
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
try {
- testManager.getTestCase(id)->addCommand(script); // creates / reuses
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->addCommand(script); // creates / reuses
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
}
try {
- testManager.getTestCase(id)->addWaitDiameterRegexpHex(fe_or_fc, regexp);
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->addWaitDiameterRegexpHex(fe_or_fc, regexp);
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
//regexp += "$";
}
- testManager.getTestCase(id)->addWaitDiameterRegexpXml(fe_or_fc, regexp);
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->addWaitDiameterRegexpXml(fe_or_fc, regexp);
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
try { // [code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId]
- testManager.getTestCase(id)->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId);
- response = "Done";
+ anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+ tc->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId);
+ response = std::to_string(tc->getId());
}
catch(anna::RuntimeException &ex) {
ex.trace();
Adds a new step to the test case with provided identifier. If provided identifier is not registered yet, a new test case will be created with that value and the step will be added as the first. For a specific 'id', the steps are stored in order as they are programmed. Check possible runtime exceptions when adding a new step because those which fail, will be ignored/skipped during test case programming giving an incomplete sequence invalid for the testing purpose.
-<id>: integer number, normally monotonically increased for each test case. Some external script/procedure shall clone a test case template in order to build a collection of independent and coherent test cases (normally same type) with different context values (Session-Id, Subscriber-Id, etc.).
+<id>: integer number, normally monotonically increased for each test case. Some external script/procedure shall clone a test case template in order to build a collection of independent and coherent test cases (normally same type) with different context values (Session-Id, Subscriber-Id, etc.). If 0 provided, `id` will be calculated as the current number of test cases plus 1 (normally valid when identification started on value of 1 and no holes were created).
<command>: commands to be executed for the test id provided. Each command programmed constitutes a test case 'step', numbered from 1 to N, with an exception for 'description' which is used to describe the test case:
### FSM testing
ADML implements a bulting *Finite State Machine* to plan testing flows with a great flexibility.
+Every operation will receive a response which `json` content is as follows:
+
+```json
+{
+ "result":"true",
+ "response":"<test id>"
+}
+```
+
+or
+
+```json
+{
+ "result":"false",
+ "response":"<error hint>"
+}
+```
+
+In case of success operation, the value of the affected test identifier carried in `response` field is useful when zero value was provided to automatically reserve the next test case. In case of error, a brief error description will be carried in that field.
#### POST /testid-description/{id}
response = admlc.postDict("/testid-description/{}".format(flow), { "description":"My test" })
# Verify response
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST
response = admlc.postDict("/testid-description/{}".format(flow), { "description":"testid-description.test_001.flow{}".format(flow) })
# Verify response
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Go to the second test:
response = admlc.postDict("/testid-description/{}".format(flow), { "description":"testid-description.test_001.flow{}".format(flow) })
# Verify response
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Go to the second test:
response = admlc.postDict("/testid-description/{}".format(flow), { "description":"My test" })
# Verify response
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST
response = admlc.postDict("/testid-ip-limit/{}".format(flow), { "amount":15 })
# Verify response (test & step programmed)
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST (execute the former test)
response = admlc.postDict("/testid-ip-limit/{}".format(flow), { "amount":15 })
# Verify response (test & step programmed)
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST (execute the former test)
response = admlc.postDict("/testid-description/{}".format(flow), { "description":"Look test" })
# Verify response
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST
response = admlc.postDict("/testid-ip-limit/{}".format(flow), { "amount":15 })
# Verify response (test & step programmed)
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST (execute the former test)
response = admlc.postDict("/testid-description/{}".format(flow), { "description":"Look test" })
# Verify response
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
# Send POST
flow = admlf.getId()
requestBody = { "msecs":500 }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-delay/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = { "description":"testid-description.test_001.flow{}".format(flow) }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-description/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = { "amount":5 }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-ip-limit/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = resources("aar-diameterJsonFromOwnToAF-request.json")
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.post("/testid-sendmsg2c/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = resources("aar-diameterJsonFromOwnToAF-request.json")
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.post("/testid-sendmsg2e/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = { "script":"date" }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-sh-command/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = { "msecs":3000 }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-timeout/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = { "hex":"01000150c000010901000014" }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-waitfc-hex/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = resources("aar-diameterJsonFromOwnToAF-request.json")
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.post("/testid-waitfc-msg/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = resources("condition-request.json")
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.post("/testid-waitfc/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = { "hex":"01000150c000010901000014" }
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.postDict("/testid-waitfe-hex/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = resources("aar-diameterJsonFromOwnToAF-request.json")
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.post("/testid-waitfe-msg/{}".format(flow), requestBody)
flow = admlf.getId()
requestBody = resources("condition-request.json")
- responseBodyRef = { "success":"true", "response":"Done" }
+ responseBodyRef = { "success":"true", "response":str(flow) }
# Send POST
response = admlc.post("/testid-waitfe/{}".format(flow), requestBody)
bool runTestCase(unsigned int id) ;
TestCase *findTestCase(unsigned int id) const ; // id = -1 provides current test case triggered
TestCase *getTestCase(unsigned int id, const std::string &description = "") ; // creates/reuses a test case
-
+ // provide 0 to reserve the id = tests() + 1
// Diameter-specific
TestCase *getDiameterTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) ;
TestCase *getDiameterTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) ;
TestCase *TestManager::getTestCase(unsigned int id, const std::string &description) {
+ if (id == 0) { // 0 is used to sequence automatically and get the value of 'tests() + 1'
+ id = tests() + 1;
+ }
+
test_pool_nc_it it = a_testPool.find(id);
if (it != a_testPool.end()) return it->second;