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
#define DB_SERVER_H
#include <cc/base_stamped_element.h>
+#include <cc/cfg_to_element.h>
#include <cc/server_tag.h>
#include <boost/shared_ptr.hpp>
#include <string>
/// provided by the administrator and the metadata.
///
/// 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:
/// @brief Constructor.
return (description_);
}
+ /// @brief Unparses server object.
+ ///
+ /// @return A pointer to unparsed server configuration.
+ virtual data::ElementPtr toElement() const;
+
private:
/// @brief Server tag.
#include <config.h>
#include <database/server_collection.h>
+#include <testutils/test_to_element.h>
#include <exceptions/exceptions.h>
#include <gtest/gtest.h>
#include <string>
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.
TEST(ServerFetcherTest, getByTag) {
ServerCollection servers;
/// @brief Determines if wiping only the data between tests is enabled
///
/// @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();
};