class TestCase {
void assertInitialized() const noexcept(false);
- std::string assertMessage(const anna::DataBlock &db, bool toEntity) noexcept(false);
+ void assertMessage(const anna::DataBlock &db, bool toEntity, std::string &key1, std::string &key2) noexcept(false);
public:
// getters
const unsigned int &getId() const { return a_id; }
- const std::string &getKey() const { return a_key; }
+ const std::string &getKey1() const { return a_key1; }
+ const std::string &getKey2() const { return a_key2; }
const std::string &getDescription() const { return a_description; }
// setters
private:
// private members:
unsigned int a_id;
- std::string a_key;
+ std::string a_key1;
+ std::string a_key2;
std::string a_description;
std::vector<TestStep*> a_steps;
std::vector<TestStep*>::const_iterator a_stepsIt;
TestCase::TestCase(unsigned int id, const std::string &description) :
a_id(id),
- a_key(""),
+ a_key1(""),
+ a_key2(""),
a_description((description != "") ? description : (anna::functions::asString("Testcase_%d", id))),
a_state(State::Initialized),
a_startTimestamp(0),
anna::xml::Node* result = parent->createChild("TestCase");
result->createAttribute("Id", a_id);
- if (a_key != "") result->createAttribute("Key", a_key);
+ if (a_key1 != "") result->createAttribute("Key1SessionId", a_key1);
+ if (a_key2 != "") result->createAttribute("Key2Subscriber", a_key2);
result->createAttribute("Description", a_description);
result->createAttribute("State", asText(a_state));
result->createAttribute("StartTimestamp", a_startTimestamp.asString());
throw anna::RuntimeException(anna::functions::asString("Cannot program anymore. The test case %llu (%s) has finished. You must reset it to append new steps (or do it during execution, which is also allowed).", a_id, a_description.c_str()), ANNA_FILE_LOCATION);
}
-std::string TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) noexcept(false) {
-
- std::string key;
+void TestCase::assertMessage(const anna::DataBlock &db, bool toEntity, std::string &key1, std::string &key2) noexcept(false) {
bool isRequest = anna::diameter::codec::functions::isRequest(db);
bool registerKeys = ((isRequest && toEntity) || (!isRequest && !toEntity) /* (*) */);
if (registerKeys) {
TestManager &testManager = TestManager::instantiate();
- key = anna::diameter::helpers::base::functions::getSessionId(db);
- testManager.registerKey1(key, this);
+ key1 = anna::diameter::helpers::base::functions::getSessionId(db);
+ testManager.registerKey1(key1, this);
- key = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164);
- if (key == "") // try with IMSI
- key = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI);
+ key2 = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164);
+ if (key2 == "") // try with IMSI
+ key2 = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI);
- if (key != "")
- testManager.registerKey2(key, this);
+ if (key2 != "")
+ testManager.registerKey2(key2, this);
}
-
- return key;
}
void TestCase::addTimeout(const anna::Millisecond &timeout) noexcept(false) {
void TestCase::addSendDiameterXml2e(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) noexcept(false) {
assertInitialized();
- a_key = assertMessage(db, true /* to entity */);
+ assertMessage(db, true /* to entity */, a_key1, a_key2);
if (stepNumber != -1) {
const TestStep *stepReferred = getStep(stepNumber);
void TestCase::addSendDiameterXml2c(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) noexcept(false) {
assertInitialized();
- a_key = assertMessage(db, false /* to client */);
+ assertMessage(db, false /* to client */, a_key1, a_key2);
if (stepNumber != -1) {
const TestStep *stepReferred = getStep(stepNumber);
a_testPool.erase(it);
- auto key1_it = a_key1TestCaseMap.find(it->second->getKey());
- if (key1_it != a_key1TestCaseMap.end()) a_key1TestCaseMap.erase(key1_it);
- auto key2_it = a_key2TestCaseMap.find(it->second->getKey());
- if (key2_it != a_key2TestCaseMap.end()) a_key2TestCaseMap.erase(key2_it);
-
result = "Provided test case has been dropped";
- return true;
+ bool something_removed = false;
+
+ auto key1_it = a_key1TestCaseMap.find(it->second->getKey1());
+ if (key1_it != a_key1TestCaseMap.end()) {
+ a_key1TestCaseMap.erase(key1_it);
+ result += " | Removed key1 = ";
+ result += it->second->getKey1();
+ something_removed = true;
+ }
+ auto key2_it = a_key2TestCaseMap.find(it->second->getKey2());
+ if (key2_it != a_key2TestCaseMap.end()) {
+ a_key2TestCaseMap.erase(key2_it);
+ result += " | Removed key2 = ";
+ result += it->second->getKey2();
+ something_removed = true;
+ }
+
+ if (something_removed) return true;
+
+ result = "Provided test case has been dropped, but key1 = '";
+ result += it->second->getKey1();
+ result += "' was not found, and also key2 = '";
+ result += it->second->getKey2();
+ result += "' was not found";
+
+ return false;
}
bool TestManager::clearPool(std::string &result) {