]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1976] Initialization
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Wed, 20 Jun 2012 15:10:47 +0000 (17:10 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Wed, 20 Jun 2012 15:10:47 +0000 (17:10 +0200)
src/bin/auth/datasrc_configurator.h
src/bin/auth/tests/Makefile.am
src/bin/auth/tests/datasrc_configurator_unittest.cc
src/bin/auth/tests/testdata/Makefile.am
src/bin/auth/tests/testdata/spec.spec [new file with mode: 0644]

index f805c6ca5d06409231928f6653fd509e11ae30b8..d5ba5295c6492df8075676f3d470c03f08a4f8ca 100644 (file)
@@ -47,6 +47,8 @@ private:
     {
         reconfigure(config);
     }
+    static Server* server_;
+    static isc::config::ModuleCCSession* session_;
 public:
     /// \brief Initializes the class.
     ///
@@ -61,13 +63,25 @@ public:
     /// \param session The session to hook into and to access the configuration
     ///     through.
     /// \param server It is the server to configure.
-    /// \throw InvalidOperation if this is called when already initialized.
+    /// \throw isc::InvalidOperation if this is called when already initialized.
+    /// \throw isc::InvalidParameter if any of the parameters is NULL
     /// \throw isc::config::ModuleCCError if the remote configuration is not
     ///     available for some reason.
     static void init(isc::config::ModuleCCSession *session,
                      Server *server)
     {
-
+        if (session == NULL) {
+            isc_throw(isc::InvalidParameter, "The session must not be NULL");
+        }
+        if (server == NULL) {
+            isc_throw(isc::InvalidParameter, "The server must not be NULL");
+        }
+        if (server_ != NULL) {
+            isc_throw(isc::InvalidOperation,
+                      "The configurator is already initialized");
+        }
+        server_ = server;
+        session_ = session;
     }
     /// \brief Deinitializes the class.
     ///
@@ -77,13 +91,31 @@ public:
     /// This can be called even if it is not initialized currently. You
     /// can initialize it again after this.
     static void deinit() {
-
+        session_ = NULL;
+        server_ = NULL;
     }
+    /// \brief Reads new configuration and replaces the old one.
+    ///
+    /// It instructs the server to replace the lists with new ones as needed.
+    /// You don't need to call it directly (but you could, though the benefit
+    /// is unkown and it would be questionable at least). It is called
+    /// automatically on normal updates.
+    ///
+    /// \param config The configuration value to parse. It is in the form
+    ///     as an update from the config manager.
+    /// \throw InvalidOperation if it is called when not initialized.
     static void reconfigure(const isc::data::ConstElementPtr& config) {
 
     }
 };
 
+template<class Server, class List>
+isc::config::ModuleCCSession*
+DataSourceConfiguratorGeneric<Server, List>::session_(NULL);
+
+template<class Server, class List>
+Server* DataSourceConfiguratorGeneric<Server, List>::server_(NULL);
+
 /// \brief Concrete version of DataSourceConfiguratorGeneric for the
 ///     use in authoritative server.
 typedef DataSourceConfiguratorGeneric<AuthSrv,
index 74d3bed42c23885e729f9892cfb633d28d0b2ef2..bdb5eaa082466ac676da782e80c0ab604133b926 100644 (file)
@@ -5,6 +5,7 @@ AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += -DAUTH_OBJ_DIR=\"$(abs_top_builddir)/src/bin/auth\"
 AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\"
+AM_CPPFLAGS += -DTEST_OWN_DATA_DIR=\"$(abs_top_srcdir)/src/bin/auth/tests/testdata\"
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/testutils/testdata\"
 AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
 
@@ -73,6 +74,7 @@ run_unittests_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
 run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
 run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
 run_unittests_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
+run_unittests_LDADD += $(top_builddir)/src/lib/config/tests/libfake_session.la
 run_unittests_LDADD += $(GTEST_LDADD)
 run_unittests_LDADD += $(SQLITE_LIBS)
 
index 61440647230350fa9f4357f4ce8159ebbd120445..032b603fe64412988ffd0f176ce3732f2a2e8d1a 100644 (file)
 
 #include <auth/datasrc_configurator.h>
 
+#include <config/tests/fake_session.h>
+#include <config/ccsession.h>
+
+#include <gtest/gtest.h>
+#include <memory>
+
+using namespace isc;
+using namespace isc::cc;
+using namespace isc::config;
+using namespace isc::data;
+using namespace std;
+
 namespace {
 
+class DatasrcConfiguratorTest;
+
+class FakeList {
+
+};
+
+// We use the test fixture as both parameters, this makes it possible
+// to easily fake all needed methods and look that they were called.
+typedef DataSourceConfiguratorGeneric<DatasrcConfiguratorTest,
+        FakeList> Configurator;
+
+class DatasrcConfiguratorTest : public ::testing::Test {
+protected:
+    DatasrcConfiguratorTest() :
+        session(ElementPtr(new ListElement), ElementPtr(new ListElement),
+                ElementPtr(new ListElement)),
+        specfile(string(TEST_OWN_DATA_DIR) + "/spec.spec")
+    {
+        initSession();
+    }
+    void initSession() {
+        session.getMessages()->add(createAnswer());
+        mccs.reset(new ModuleCCSession(specfile, session, NULL, NULL, false,
+                                       false));
+    }
+    void TearDown() {
+        // Make sure no matter what we did, it is cleaned up.
+        Configurator::deinit();
+    }
+    void init() {
+        Configurator::init(mccs.get(), this);
+    }
+    void SetUp() {
+        init();
+    }
+    FakeSession session;
+    auto_ptr<ModuleCCSession> mccs;
+    const string specfile;
+};
+
+// Check the initialization (and deinitialization)
+TEST_F(DatasrcConfiguratorTest, initialization) {
+    // It can't be initialized again
+    EXPECT_THROW(init(), InvalidOperation);
+    // Deinitialize to make the tests reasonable
+    Configurator::deinit();
+    // Make sure there are enough messages in it, etc.
+    initSession();
+    // If one of them is NULL, it does not work
+    EXPECT_THROW(Configurator::init(NULL, this), InvalidParameter);
+    EXPECT_THROW(Configurator::init(mccs.get(), NULL), InvalidParameter);
+    // But we can initialize it again now
+    EXPECT_NO_THROW(init());
+}
+
 }
index c86722f81d41ad971636d44a0eb26da8bd225f60..7e42b704027fde0adc1996fe4f544f5e0ea8ae5e 100644 (file)
@@ -18,6 +18,7 @@ EXTRA_DIST += shortquestion_fromWire
 EXTRA_DIST += shortresponse_fromWire
 EXTRA_DIST += simplequery_fromWire.spec
 EXTRA_DIST += simpleresponse_fromWire.spec
+EXTRA_DIST += spec.spec
 
 EXTRA_DIST += example.com
 EXTRA_DIST += example.sqlite3
diff --git a/src/bin/auth/tests/testdata/spec.spec b/src/bin/auth/tests/testdata/spec.spec
new file mode 100644 (file)
index 0000000..3e0a822
--- /dev/null
@@ -0,0 +1,6 @@
+{
+    "module_spec": {
+        "module_name": "test"
+    }
+}
+