#include <cc/server_tag.h>
#include <exceptions/exceptions.h>
#include <util/strutil.h>
+#include <boost/algorithm/string.hpp>
namespace isc {
namespace data {
} else if (tag_.length() > 256) {
isc_throw(BadValue, "server-tag must not be longer than 256 characters");
}
+
+ boost::algorithm::to_lower(tag_);
}
bool
/// @brief Constructor.
///
- /// @param tag server tag provided as string.
+ /// @param tag server tag provided as string. The tag is converted to
+ /// lower case.
explicit ServerTag(const std::string& tag);
/// @brief Checks if the server tag is set to "all servers".
/// @return true if the server tag is set to all servers, false
/// otherwise.
bool amAll() const;
+
/// @brief Returns server tag as string.
+ ///
+ /// @return lower case server tag.
std::string get() const {
return (tag_);
}
EXPECT_EQ("both left-right", tag->get());
EXPECT_FALSE(tag->amAll());
}
+
+ {
+ SCOPED_TRACE("upper to lower case");
+ ASSERT_NO_THROW(tag.reset(new ServerTag("UPPER CASE TAG")));
+ EXPECT_EQ("upper case tag", tag->get());
+ EXPECT_FALSE(tag->amAll());
+ }
}
// This test verifies that malformed server tags are rejected.
///
/// @param MethodPointer Pointer to the backend method to be called.
/// @param backend_selector Backend selector.
- /// @param server_selector Server selector.
/// @param [out] properties Reference to the collection of retrieved properties.
///
/// @throw db::NoSuchDatabase if no database matching the given selector
/// @brief Shared pointer to the @c Server class.
typedef boost::shared_ptr<Server> ServerPtr;
-/// @brief Represents information about the Kea server in the database.
+/// @brief Represents information about a Kea server in the database.
///
/// The configuration backend holds the information about the servers
/// for which the backend holds the configuration information. The
/// @brief Constructor.
///
/// @param tag server tag.
- /// @param server description.
+ /// @param description server description.
Server(const data::ServerTag& tag, const std::string& description);
/// @brief Factory function to be used to create an instance of the
/// @c Server object.
///
/// @param tag server tag.
- /// @param server description.
+ /// @param description server description.
///
/// @return Pointer to the server instance.
/// @throw BadValue if the server tag exceeds 256 characters or the
// Tests that it is possible to fetch server by tag fromn the collection.
TEST(ServerFetcherTest, getByTag) {
ServerCollection servers;
- servers.insert(Server::create(ServerTag("alpha"), "alpha description"));
- servers.insert(Server::create(ServerTag("beta"), "beta description"));
- servers.insert(Server::create(ServerTag("gamma"), "gamma description"));
+
+ EXPECT_TRUE(servers.insert(Server::create(ServerTag("alpha"), "alpha description")).second);
+ EXPECT_TRUE(servers.insert(Server::create(ServerTag("beta"), "beta description")).second);
+ EXPECT_TRUE(servers.insert(Server::create(ServerTag("gamma"), "gamma description")).second);
+
+ // Inserting an element with duplicated server tag should be unsuccessful.
+ EXPECT_FALSE(servers.insert(Server::create(ServerTag("gamma"), "gamma 2 description")).second);
auto alpha = ServerFetcher::get(servers, ServerTag("alpha"));
ASSERT_TRUE(alpha);