mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[709-cb_cmds-add-support-for-commands-to-manage-the-servers] Added a toElement method to Server
This commit is contained in:
@@ -28,5 +28,15 @@ Server::create(const ServerTag& tag, const std::string& description) {
|
|||||||
return (boost::make_shared<Server>(tag, description));
|
return (boost::make_shared<Server>(tag, description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElementPtr
|
||||||
|
Server::toElement() const {
|
||||||
|
ElementPtr result = Element::createMap();
|
||||||
|
|
||||||
|
result->set("server-tag", Element::create(getServerTagAsText()));
|
||||||
|
result->set("description", Element::create(getDescription()));
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace isc::db
|
} // end of namespace isc::db
|
||||||
} // end of namespace isc
|
} // end of namespace isc
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#define DB_SERVER_H
|
#define DB_SERVER_H
|
||||||
|
|
||||||
#include <cc/base_stamped_element.h>
|
#include <cc/base_stamped_element.h>
|
||||||
|
#include <cc/cfg_to_element.h>
|
||||||
#include <cc/server_tag.h>
|
#include <cc/server_tag.h>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -28,7 +29,7 @@ typedef boost::shared_ptr<Server> ServerPtr;
|
|||||||
/// provided by the administrator and the metadata.
|
/// provided by the administrator and the metadata.
|
||||||
///
|
///
|
||||||
/// This class extends the base class with the server description field.
|
/// This class extends the base class with the server description field.
|
||||||
class Server : public data::BaseStampedElement {
|
class Server : public data::BaseStampedElement, public data::CfgToElement {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// @brief Constructor.
|
/// @brief Constructor.
|
||||||
@@ -69,6 +70,11 @@ public:
|
|||||||
return (description_);
|
return (description_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Unparses server object.
|
||||||
|
///
|
||||||
|
/// @return A pointer to unparsed server configuration.
|
||||||
|
virtual data::ElementPtr toElement() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// @brief Server tag.
|
/// @brief Server tag.
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <database/server_collection.h>
|
#include <database/server_collection.h>
|
||||||
|
#include <testutils/test_to_element.h>
|
||||||
#include <exceptions/exceptions.h>
|
#include <exceptions/exceptions.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -34,6 +35,23 @@ TEST(ServerTest, tooLongDescription) {
|
|||||||
BadValue);
|
BadValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that toElement method works well.
|
||||||
|
TEST(ServerTest, toEDlement) {
|
||||||
|
ServerPtr server1 = Server::create(ServerTag("foo"), "a server");
|
||||||
|
std::string expected1 = "{"
|
||||||
|
"\"server-tag\": \"foo\","
|
||||||
|
"\"description\": \"a server\""
|
||||||
|
" }";
|
||||||
|
isc::test::runToElementTest<Server>(expected1, *server1);
|
||||||
|
|
||||||
|
ServerPtr server2 =Server::create(ServerTag("bar"));
|
||||||
|
std::string expected2= "{"
|
||||||
|
"\"server-tag\": \"bar\","
|
||||||
|
"\"description\": \"\""
|
||||||
|
" }";
|
||||||
|
isc::test::runToElementTest<Server>(expected2, *server2);
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that it is possible to fetch server by tag fromn the collection.
|
// Tests that it is possible to fetch server by tag fromn the collection.
|
||||||
TEST(ServerFetcherTest, getByTag) {
|
TEST(ServerFetcherTest, getByTag) {
|
||||||
ServerCollection servers;
|
ServerCollection servers;
|
||||||
|
@@ -49,7 +49,7 @@ std::string connectionString(const char* type, const char* name = NULL,
|
|||||||
/// @brief Determines if wiping only the data between tests is enabled
|
/// @brief Determines if wiping only the data between tests is enabled
|
||||||
///
|
///
|
||||||
/// @return true if the environment variable, KEA_TEST_DB_WIPE_DATA_ONLY is
|
/// @return true if the environment variable, KEA_TEST_DB_WIPE_DATA_ONLY is
|
||||||
/// defined as "true" or if it is not present.
|
/// defined as "true" or if it is not present.
|
||||||
bool softWipeEnabled();
|
bool softWipeEnabled();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user