OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_xml.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_test_xml_test_xml_h
6 #define vnsw_agent_test_xml_test_xml_h
7 
8 #include <iostream>
9 #include <vector>
10 #include <pugixml/pugixml.hpp>
11 #include <boost/uuid/uuid.hpp>
12 
13 #include <base/util.h>
14 
15 class AgentUtXmlTestCase;
16 class AgentUtXmlNode;
18 
19 namespace AgentUtXmlUtils {
20 bool GetStringAttribute(const pugi::xml_node &node, const std::string &name,
21  std::string *value);
22 bool GetUintAttribute(const pugi::xml_node &node, const std::string &name,
23  uint16_t *value);
24 bool GetIntAttribute(const pugi::xml_node &node, const std::string &name,
25  int *value);
26 bool GetBoolAttribute(const pugi::xml_node &node, const std::string &name,
27  bool *value);
28 void NovaIntfAdd(bool op_delete, const boost::uuids::uuid &id,
29  const Ip4Address &ip, const boost::uuids::uuid &vm_uuid,
30  const boost::uuids::uuid vn_uuid, const std::string &name,
31  const std::string &mac, const std::string vm_name);
32 void LinkXmlNode(pugi::xml_node *parent, const std::string &ltype,
33  const std::string lname, const std::string &rtype,
34  const std::string rname);
35 pugi::xml_node AddXmlNodeWithAttr(pugi::xml_node *parent, const char *attr);
36 pugi::xml_node AddXmlNodeWithValue(pugi::xml_node *parent, const char *name,
37  const std::string &value);
38 pugi::xml_node AddXmlNodeWithIntValue(pugi::xml_node *parent, const char *name,
39  int val);
40 }
41 
43 private:
44  typedef std::vector<AgentUtXmlTestCase *> AgentUtXmlTestList;
45 public:
46  typedef boost::function<AgentUtXmlNode *(const std::string type,
47  const std::string &name,
48  const boost::uuids::uuid &id,
49  const pugi::xml_node &node,
50  AgentUtXmlTestCase *test_case)>
52 
53  typedef boost::function<AgentUtXmlValidationNode *
54  (const std::string &type, const std::string &name,
55  const boost::uuids::uuid &id, const pugi::xml_node &node)>
57 
58  typedef std::map<std::string, AgentUtXmlTestConfigCreateFn>
60  typedef std::map<std::string, AgentUtXmlTestValidateCreateFn>
62 
63  AgentUtXmlTest(const std::string &file_name);
64  virtual ~AgentUtXmlTest();
65 
66  bool Load();
67  bool ReadXml();
68  void ToString(std::string *str);
69  bool Run();
70  bool Run(std::string test_case);
71  void AddConfigEntry(const std::string &name,
73  void AddValidateEntry(const std::string &name,
75  AgentUtXmlTestConfigCreateFn GetConfigCreateFn(const std::string &name);
76  AgentUtXmlTestValidateCreateFn GetValidateCreateFn(const std::string &name);
77 private:
78  std::string file_name_;
79  std::string name_;
80  pugi::xml_document doc_;
85 };
86 
88 private:
89  typedef std::vector<AgentUtXmlNode *> AgentUtXmlNodeList;
90 public:
91  AgentUtXmlTestCase(const std::string &name, const pugi::xml_node &node,
93  virtual ~AgentUtXmlTestCase();
94  AgentUtXmlTest *test() { return test_; }
95 
96  virtual bool ReadXml();
97  virtual bool Run();
98  virtual void ToString(std::string *str);
99  void set_verbose(bool val) { verbose_ = val; }
100  bool verbose() const { return verbose_; }
101  const std::string &name() const { return name_; }
102 private:
103  std::string name_;
104  pugi::xml_node xml_node_;
106  pugi::xml_document gen_doc_;
108  bool verbose_;
110 };
111 
113 public:
114  AgentUtXmlNode(const std::string &name, const pugi::xml_node &node,
116  AgentUtXmlNode(const std::string &name, const pugi::xml_node &node,
117  bool gen_xml, AgentUtXmlTestCase *test_case);
118  virtual ~AgentUtXmlNode();
119 
120  virtual bool ReadXml() = 0;
121  virtual bool ToXml(pugi::xml_node *parent) = 0;
122  virtual std::string NodeType() = 0;
123  virtual void ToString(std::string *str);
124  virtual bool Run() { assert(0); return false; }
125 
126  void set_gen_xml(bool val) { gen_xml_ = val; }
127  bool gen_xml() const { return gen_xml_; }
128  bool op_delete() const { return op_delete_; }
129  void set_op_delete(bool val) { op_delete_ = val; }
130  const std::string &name() const { return name_; }
131  const pugi::xml_node &node() const { return node_; }
133 protected:
134  pugi::xml_node gen_node_;
135 private:
136  pugi::xml_node node_;
137  std::string name_;
139  bool gen_xml_;
142 };
143 
145 // Task control nodes
148 public:
149  AgentUtXmlTask(const pugi::xml_node &node, AgentUtXmlTestCase *test_case);
150  virtual ~AgentUtXmlTask();
151 
152  virtual bool ReadXml();
153  virtual bool ToXml(pugi::xml_node *parent);
154  virtual std::string NodeType();
155  virtual void ToString(std::string *str);
156  virtual bool Run();
157 
158 private:
159  pugi::xml_node xml_;
160  std::string stop_;
162 };
163 
165 // Link nodes
168 public:
169  AgentUtXmlLink(const pugi::xml_node &node, AgentUtXmlTestCase *test_case);
170  virtual ~AgentUtXmlLink();
171 
172  virtual bool ReadXml();
173  virtual bool ToXml(pugi::xml_node *parent);
174  virtual std::string NodeType();
175  virtual void ToString(std::string *str);
176 
177 private:
178  pugi::xml_node xml_;
179  std::string l_node_;
180  std::string l_name_;
181  std::string r_node_;
182  std::string r_name_;
184 };
185 
187 // Config nodes
190 public:
191  AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid,
192  const pugi::xml_node &node, AgentUtXmlTestCase *test_case);
193  AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid,
194  const pugi::xml_node &node, bool gen_xml,
195  AgentUtXmlTestCase *test_case);
196  virtual ~AgentUtXmlConfig();
197 
198  virtual bool ReadXml();
199  virtual void ToString(std::string *str);
200  const boost::uuids::uuid &id() const { return id_; }
201 protected:
202  void AddIdPerms(pugi::xml_node *parent);
203 private:
206 };
207 
208 #endif //vnsw_agent_test_xml_test_xml_h
std::string name_
Definition: test_xml.h:79
boost::function< AgentUtXmlValidationNode *(const std::string &type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)> AgentUtXmlTestValidateCreateFn
Definition: test_xml.h:56
virtual void ToString(std::string *str)
Definition: test_xml.cc:436
virtual ~AgentUtXmlTest()
Definition: test_xml.cc:141
virtual std::string NodeType()
Definition: test_xml.cc:521
void set_gen_xml(bool val)
Definition: test_xml.h:126
std::vector< AgentUtXmlNode * > AgentUtXmlNodeList
Definition: test_xml.h:89
virtual bool Run()
Definition: test_xml.h:124
virtual void ToString(std::string *str)
Definition: test_xml.cc:613
xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name, int val)
Definition: test_xml.cc:125
void set_verbose(bool val)
Definition: test_xml.h:99
AgentUtXmlNode(const std::string &name, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
pugi::xml_node gen_node_
Definition: test_xml.h:134
bool GetIntAttribute(const xml_node &node, const string &name, int *value)
Definition: test_xml.cc:49
std::string file_name_
Definition: test_xml.h:78
virtual void ToString(std::string *str)
Definition: test_xml.cc:512
pugi::xml_document doc_
Definition: test_xml.h:80
AgentUtXmlTestValidateFactory validate_factory_
Definition: test_xml.h:83
AgentUtXmlTestValidateCreateFn GetValidateCreateFn(const std::string &name)
Definition: test_xml.cc:170
const std::string & name() const
Definition: test_xml.h:101
AgentUtXmlTask(const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
Definition: test_xml.cc:495
void ToString(std::string *str)
Definition: test_xml.cc:242
boost::uuids::uuid id_
Definition: test_xml.h:204
bool op_delete_
Definition: test_xml.h:138
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlNode)
std::map< std::string, AgentUtXmlTestConfigCreateFn > AgentUtXmlTestConfigFactory
Definition: test_xml.h:59
virtual bool ReadXml()=0
Definition: test_xml.cc:466
virtual ~AgentUtXmlConfig()
Definition: test_xml.cc:606
pugi::xml_node xml_
Definition: test_xml.h:159
AgentUtXmlTestList test_list_
Definition: test_xml.h:81
boost::uuids::uuid uuid
std::map< std::string, AgentUtXmlTestValidateCreateFn > AgentUtXmlTestValidateFactory
Definition: test_xml.h:61
void NovaIntfAdd(bool op_delete, const uuid &id, const Ip4Address &ip, const uuid &vm_uuid, const uuid vn_uuid, const string &name, const string &mac, const string vm_name)
Definition: test_xml.cc:75
std::string name_
Definition: test_xml.h:103
bool GetBoolAttribute(const xml_node &node, const string &name, bool *value)
Definition: test_xml.cc:60
bool ReadXml()
Definition: test_xml.cc:178
xml_node AddXmlNodeWithValue(xml_node *parent, const char *name, const string &value)
Definition: test_xml.cc:118
std::string name_
Definition: test_xml.h:137
virtual ~AgentUtXmlNode()
Definition: test_xml.cc:463
AgentUtXmlTestCase(const std::string &name, const pugi::xml_node &node, AgentUtXmlTest *test)
Definition: test_xml.cc:318
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlTask)
virtual std::string NodeType()=0
virtual bool ReadXml()
Definition: test_xml.cc:503
xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr)
Definition: test_xml.cc:112
uint8_t type
Definition: load_balance.h:109
void AddIdPerms(pugi::xml_node *parent)
Definition: test_xml.cc:650
boost::function< AgentUtXmlNode *(const std::string type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)> AgentUtXmlTestConfigCreateFn
Definition: test_xml.h:51
virtual ~AgentUtXmlTask()
Definition: test_xml.cc:500
AgentUtXmlTest(const std::string &file_name)
Definition: test_xml.cc:138
pugi::xml_document gen_doc_
Definition: test_xml.h:106
void AddConfigEntry(const std::string &name, AgentUtXmlTestConfigCreateFn fn)
Definition: test_xml.cc:149
std::vector< AgentUtXmlTestCase * > AgentUtXmlTestList
Definition: test_xml.h:44
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
Definition: test_xml.cc:25
std::string stop_
Definition: test_xml.h:160
virtual ~AgentUtXmlTestCase()
Definition: test_xml.cc:325
pugi::xml_node node_
Definition: test_xml.h:136
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
AgentUtXmlTest * test()
Definition: test_xml.h:94
bool verbose() const
Definition: test_xml.h:100
virtual bool ToXml(pugi::xml_node *parent)
Definition: test_xml.cc:508
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
Definition: test_xml.cc:37
const boost::uuids::uuid & id() const
Definition: test_xml.h:200
virtual bool Run()
Definition: test_xml.cc:525
void AddValidateEntry(const std::string &name, AgentUtXmlTestValidateCreateFn fn)
Definition: test_xml.cc:154
void set_op_delete(bool val)
Definition: test_xml.h:129
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlTest)
AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ToXml(pugi::xml_node *parent)=0
bool op_delete() const
Definition: test_xml.h:128
pugi::xml_node xml_node_
Definition: test_xml.h:104
AgentUtXmlTest * test_
Definition: test_xml.h:107
virtual bool ReadXml()
Definition: test_xml.cc:332
AgentUtXmlTestCase * test_case()
Definition: test_xml.h:132
AgentUtXmlTestConfigFactory config_factory_
Definition: test_xml.h:82
AgentUtXmlTestCase * test_case_
Definition: test_xml.h:140
virtual bool ReadXml()
Definition: test_xml.cc:609
bool gen_xml() const
Definition: test_xml.h:127
const pugi::xml_node & node() const
Definition: test_xml.h:131
virtual void ToString(std::string *str)
Definition: test_xml.cc:478
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlConfig)
const std::string & name() const
Definition: test_xml.h:130
AgentUtXmlTestConfigCreateFn GetConfigCreateFn(const std::string &name)
Definition: test_xml.cc:160
void LinkXmlNode(xml_node *parent, const string &ltype, const string lname, const string &rtype, const string rname)
Definition: test_xml.cc:90
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlTestCase)
virtual bool Run()
Definition: test_xml.cc:403
AgentUtXmlNodeList node_list_
Definition: test_xml.h:105