From e18062ead06d88034a86a954990c37d905995f50 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Tue, 24 Feb 2015 08:09:16 +0100 Subject: [PATCH] Added existence tests to MockLogicalLibraryTable and MockTapePoolTable --- libs/middletier/MockLogicalLibraryTable.cpp | 14 ++++++++++++++ libs/middletier/MockLogicalLibraryTable.hpp | 7 +++++++ libs/middletier/MockLogicalLibraryTableTest.cpp | 5 +++++ libs/middletier/MockTapePoolTable.cpp | 14 ++++++++++++++ libs/middletier/MockTapePoolTable.hpp | 9 ++++++++- libs/middletier/MockTapePoolTableTest.cpp | 5 +++++ 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/libs/middletier/MockLogicalLibraryTable.cpp b/libs/middletier/MockLogicalLibraryTable.cpp index a2f96ce286..38484bced6 100644 --- a/libs/middletier/MockLogicalLibraryTable.cpp +++ b/libs/middletier/MockLogicalLibraryTable.cpp @@ -30,6 +30,20 @@ void cta::MockLogicalLibraryTable::checkLogicalLibraryDoesNotAlreadyExist( throw(Exception(message.str())); } } + +//------------------------------------------------------------------------------ +// checkLogicalLibraryExists +//------------------------------------------------------------------------------ +void cta::MockLogicalLibraryTable::checkLogicalLibraryExists( + const std::string &name) const { + std::map<std::string, LogicalLibrary>::const_iterator itor = + m_libraries.find(name); + if(itor == m_libraries.end()) { + std::ostringstream message; + message << "Logical library " << name << " does not exist"; + throw(Exception(message.str())); + } +} //------------------------------------------------------------------------------ // deleteLogicalLibrary diff --git a/libs/middletier/MockLogicalLibraryTable.hpp b/libs/middletier/MockLogicalLibraryTable.hpp index f989ac7a58..96eba2759b 100644 --- a/libs/middletier/MockLogicalLibraryTable.hpp +++ b/libs/middletier/MockLogicalLibraryTable.hpp @@ -35,6 +35,13 @@ public: */ void checkLogicalLibraryDoesNotAlreadyExist(const std::string &name) const; + /** + * Throws an exception if the specified logical library does not exists. + * + * @param name The name of the logical library. + */ + void checkLogicalLibraryExists(const std::string &name) const; + /** * Deletes the logical library with the specified name. * diff --git a/libs/middletier/MockLogicalLibraryTableTest.cpp b/libs/middletier/MockLogicalLibraryTableTest.cpp index 555ebbdf57..10eb1bea32 100644 --- a/libs/middletier/MockLogicalLibraryTableTest.cpp +++ b/libs/middletier/MockLogicalLibraryTableTest.cpp @@ -27,6 +27,9 @@ TEST_F(cta_client_MockLogicalLibraryTableTest, createLogicalLibrary_new) { } const std::string libraryName = "TestLogicalLibrary"; + + ASSERT_THROW(db.checkLogicalLibraryExists(libraryName), std::exception); + const std::string libraryComment = "Comment"; ASSERT_NO_THROW(db.createLogicalLibrary(requester, libraryName, libraryComment)); @@ -41,6 +44,8 @@ TEST_F(cta_client_MockLogicalLibraryTableTest, createLogicalLibrary_new) { ASSERT_EQ(libraryName, logicalLibrary.getName()); ASSERT_EQ(libraryComment, logicalLibrary.getComment()); } + + ASSERT_NO_THROW(db.checkLogicalLibraryExists(libraryName)); } TEST_F(cta_client_MockLogicalLibraryTableTest, diff --git a/libs/middletier/MockTapePoolTable.cpp b/libs/middletier/MockTapePoolTable.cpp index 2cac3db32a..d17b8ce4a2 100644 --- a/libs/middletier/MockTapePoolTable.cpp +++ b/libs/middletier/MockTapePoolTable.cpp @@ -31,6 +31,20 @@ void cta::MockTapePoolTable::checkTapePoolDoesNotAlreadyExist( } } +//------------------------------------------------------------------------------ +// checkTapePoolExists +//------------------------------------------------------------------------------ +void cta::MockTapePoolTable::checkTapePoolExists( + const std::string &name) const { + std::map<std::string, TapePool>::const_iterator itor = + m_tapePools.find(name); + if(itor == m_tapePools.end()) { + std::ostringstream message; + message << "The " << name << " tape pool does not exist"; + throw Exception(message.str()); + } +} + //------------------------------------------------------------------------------ // deleteTapePool //------------------------------------------------------------------------------ diff --git a/libs/middletier/MockTapePoolTable.hpp b/libs/middletier/MockTapePoolTable.hpp index 92d432f986..e15e51ca33 100644 --- a/libs/middletier/MockTapePoolTable.hpp +++ b/libs/middletier/MockTapePoolTable.hpp @@ -36,12 +36,19 @@ public: const std::string &comment); /** - * Throws an exception if the specified tape pool already exixts. + * Throws an exception if the specified tape pool already exists. * * @param name The name of the tape pool. */ void checkTapePoolDoesNotAlreadyExist(const std::string &name) const; + /** + * Throws an exception if the specified tape pool does not exist. + * + * @param name The name of the tape pool. + */ + void checkTapePoolExists(const std::string &name) const; + /** * Delete the tape pool with the specifed name. * diff --git a/libs/middletier/MockTapePoolTableTest.cpp b/libs/middletier/MockTapePoolTableTest.cpp index e1962e8b53..db4c00ad06 100644 --- a/libs/middletier/MockTapePoolTableTest.cpp +++ b/libs/middletier/MockTapePoolTableTest.cpp @@ -27,6 +27,9 @@ TEST_F(cta_client_MockTapePoolTableTest, createTapePool_new) { } const std::string tapePoolName = "TestTapePool"; + + ASSERT_THROW(db.checkTapePoolExists(tapePoolName), std::exception); + const uint16_t nbDrives = 1; const uint16_t nbPartialTapes = 1; const std::string comment = "Comment"; @@ -43,6 +46,8 @@ TEST_F(cta_client_MockTapePoolTableTest, createTapePool_new) { ASSERT_EQ(tapePoolName, tapePool.getName()); ASSERT_EQ(comment, tapePool.getComment()); } + + ASSERT_NO_THROW(db.checkTapePoolExists(tapePoolName)); } TEST_F(cta_client_MockTapePoolTableTest, createTapePool_already_existing) { -- GitLab