Improvements from anna fork
[anna.git] / include / anna / testing / TestDiameterCondition.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #ifndef anna_testing_TestDiameterCondition_hpp
10 #define anna_testing_TestDiameterCondition_hpp
11
12 // Standard
13 #include <string>
14
15 // Project
16 #include <anna/core/DataBlock.hpp>
17
18
19 namespace anna {
20   namespace xml {
21     class Node;
22   }
23
24 namespace testing {
25
26 // TODO: fix types (code to int, etc.)
27 class TestDiameterCondition {
28
29   public:
30
31     // RegexpXml = Regexp against XML representation for incoming messages
32     // RegexpHex = Regexp against HEX representation for incoming messages
33     // Fields = Compare specific message fields
34     struct Type { enum _v { RegexpXml, RegexpHex, Fields }; };
35     static const char* asText(const Type::_v type) throw();
36
37     TestDiameterCondition() : a_rcvFromEntity(true),
38
39                       a_regexp(""),
40
41                       a_code(""), a_bitR(""), a_hopByHop(""), a_applicationId(""),
42                       a_sessionId(""), a_resultCode(""),
43                       a_msisdn(""), a_imsi(""), a_serviceContextId("") { a_type = Type::Fields; }
44
45
46     // Source of the received message
47     void setReceivedFromEntity(bool rfe) throw() { a_rcvFromEntity = rfe; }
48     bool receivedFromEntity() const throw() { return a_rcvFromEntity; }
49
50     // Regexp
51     void setRegexpXml(const std::string &regexp) throw() { a_regexp = regexp; a_type = Type::RegexpXml; }
52     void setRegexpHex(const std::string &regexp) throw() { a_regexp = regexp; a_type = Type::RegexpHex; }
53
54     // Fields
55     void setCode(const std::string &value) throw() { a_code = value; a_type = Type::Fields; }
56     void setBitR(const std::string &value) throw() { a_bitR = value; a_type = Type::Fields; }
57     void setHopByHop(const std::string &value) throw() { a_hopByHop = value; a_type = Type::Fields; }
58     void setApplicationId(const std::string &value) throw() { a_applicationId = value; a_type = Type::Fields; }
59     void setSessionId(const std::string &value) throw() { a_sessionId = value; a_type = Type::Fields; }
60     void setResultCode(const std::string &value) throw() { a_resultCode = value; a_type = Type::Fields; }
61     void setMsisdn(const std::string &value) throw() { a_msisdn = value; a_type = Type::Fields; }
62     void setImsi(const std::string &value) throw() { a_imsi = value; a_type = Type::Fields; }
63     void setServiceContextId(const std::string &value) throw() { a_serviceContextId = value; a_type = Type::Fields; }
64
65     bool exists() const throw();
66     friend bool operator==(const TestDiameterCondition &c1, const TestDiameterCondition &c2) throw() {
67
68       if (c1.getType() != c2.getType()) return false;
69
70       if (c1.getType() == TestDiameterCondition::Type::RegexpXml || c1.getType() == TestDiameterCondition::Type::RegexpHex) {
71         if (c1.getRegexp() != c2.getRegexp()) return false;
72       }
73       else {
74         if (c1.getCode() != c2.getCode()) return false;
75         if (c1.getBitR() != c2.getBitR()) return false;
76         if (c1.getHopByHop() != c2.getHopByHop()) return false;
77         if (c1.getApplicationId() != c2.getApplicationId()) return false;
78         if (c1.getSessionId() != c2.getSessionId()) return false;
79         if (c1.getResultCode() != c2.getResultCode()) return false;
80         if (c1.getMsisdn() != c2.getMsisdn()) return false;
81         if (c1.getImsi() != c2.getImsi()) return false;
82         if (c1.getServiceContextId() != c2.getServiceContextId()) return false;
83       }
84
85       return true;
86     }
87
88
89     const Type::_v &getType() const throw() { return a_type; }
90
91     // Regexp:
92     const std::string & getRegexp() const throw() { return a_regexp; }
93     // Basic
94     const std::string & getCode() const throw() { return a_code; }
95     const std::string & getBitR() const throw() { return a_bitR; }
96     const std::string & getHopByHop() const throw() { return a_hopByHop; }
97     const std::string & getApplicationId() const throw() { return a_applicationId; }
98     const std::string & getSessionId() const throw() { return a_sessionId; }
99     const std::string & getResultCode() const throw() { return a_resultCode; }
100     const std::string & getMsisdn() const throw() { return a_msisdn; }
101     const std::string & getImsi() const throw() { return a_imsi; }
102     const std::string & getServiceContextId() const throw() { return a_serviceContextId; }
103
104
105     bool comply (const anna::DataBlock &message) const throw();
106
107     anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
108
109
110   private:
111
112     // Source of the received message
113     bool a_rcvFromEntity;
114
115     // Type
116     Type::_v a_type;
117
118     // Generic:
119     std::string a_regexp;
120
121     // Basic:
122     std::string a_code;
123     std::string a_bitR;
124     std::string a_hopByHop;
125     std::string a_applicationId;
126     std::string a_sessionId;
127     std::string a_resultCode;
128     std::string a_msisdn;
129     std::string a_imsi;
130     std::string a_serviceContextId;
131 };
132
133 }
134 }
135
136 #endif
137