From 794166052b3110b6cd36ae805b5f8d1c078a1a01 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Thu, 19 Feb 2015 08:13:03 +0100 Subject: [PATCH] All unit tests now pass --- libs/client/MockMiddleTierAdmin.cpp | 42 +++++++++++++++++++++++++ libs/client/MockMiddleTierAdmin.hpp | 7 +++++ libs/client/MockMiddleTierAdminTest.cpp | 2 +- libs/client/MockMiddleTierDatabase.hpp | 6 ++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/libs/client/MockMiddleTierAdmin.cpp b/libs/client/MockMiddleTierAdmin.cpp index c5db64f0b1..aefc2a7fd5 100644 --- a/libs/client/MockMiddleTierAdmin.cpp +++ b/libs/client/MockMiddleTierAdmin.cpp @@ -354,6 +354,29 @@ void cta::MockMiddleTierAdmin::createTape( const std::string &tapePoolName, const uint64_t capacityInBytes, const std::string &comment) { + checkTapeDoesNotAlreadyExist(vid); + Tape tape( + vid, + logicalLibraryName, + tapePoolName, + capacityInBytes, + requester.user, + comment); + m_db.tapes[vid] = tape; +} + +//------------------------------------------------------------------------------ +// checkTapeDoesNotAlreadyExist +//------------------------------------------------------------------------------ +void cta::MockMiddleTierAdmin::checkTapeDoesNotAlreadyExist( + const std::string &vid) const { + std::map<std::string, Tape>::const_iterator itor = + m_db.tapes.find(vid); + if(itor != m_db.tapes.end()) { + std::ostringstream message; + message << "Tape with vid " << vid << " already exists"; + throw(Exception(message.str())); + } } //------------------------------------------------------------------------------ @@ -362,6 +385,19 @@ void cta::MockMiddleTierAdmin::createTape( void cta::MockMiddleTierAdmin::deleteTape( const SecurityIdentity &requester, const std::string &vid) { + for(std::map<std::string, Tape>::iterator itor = m_db.tapes.begin(); + itor != m_db.tapes.end(); itor++) { + if(vid == itor->first) { + m_db.tapes.erase(itor); + return; + } + } + + // Reaching this point means the tape to be deleted does not + // exist + std::ostringstream message; + message << "Tape iwith volume identifier " << vid << " does not exist"; + throw Exception(message.str()); } //------------------------------------------------------------------------------ @@ -370,5 +406,11 @@ void cta::MockMiddleTierAdmin::deleteTape( std::list<cta::Tape> cta::MockMiddleTierAdmin::getTapes( const SecurityIdentity &requester) const { std::list<cta::Tape> tapes; + + for(std::map<std::string, Tape>::const_iterator itor = m_db.tapes.begin(); + itor != m_db.tapes.end(); itor++) { + tapes.push_back(itor->second); + } + return tapes; } diff --git a/libs/client/MockMiddleTierAdmin.hpp b/libs/client/MockMiddleTierAdmin.hpp index 6ef869da3f..285d834fcf 100644 --- a/libs/client/MockMiddleTierAdmin.hpp +++ b/libs/client/MockMiddleTierAdmin.hpp @@ -349,6 +349,13 @@ protected: */ void checkLogicalLibraryDoesNotAlreadyExist(const std::string &name) const; + /** + * Throws an exception if the specified tape already exists. + * + * @param vid The volume identifier of the tape. + */ + void checkTapeDoesNotAlreadyExist(const std::string &vid) const; + /** * The database of the mock middle-tier. */ diff --git a/libs/client/MockMiddleTierAdminTest.cpp b/libs/client/MockMiddleTierAdminTest.cpp index fb28241e2b..9b3d3e206f 100644 --- a/libs/client/MockMiddleTierAdminTest.cpp +++ b/libs/client/MockMiddleTierAdminTest.cpp @@ -1320,7 +1320,7 @@ TEST_F(cta_client_MockMiddleTierAdminTest, deleteTape_existing) { ASSERT_THROW(adminApi.createTape(requester, vid, libraryName, poolName, capacityInBytes, tapeComment), std::exception); - ASSERT_NO_THROW(adminApi.deleteLogicalLibrary(requester, vid)); + ASSERT_NO_THROW(adminApi.deleteTape(requester, vid)); { std::list<Tape> tapes; diff --git a/libs/client/MockMiddleTierDatabase.hpp b/libs/client/MockMiddleTierDatabase.hpp index b4b98f8a72..0643f6e797 100644 --- a/libs/client/MockMiddleTierDatabase.hpp +++ b/libs/client/MockMiddleTierDatabase.hpp @@ -8,6 +8,7 @@ #include "MiddleTierUser.hpp" #include "MigrationRoutes.hpp" #include "StorageClass.hpp" +#include "Tape.hpp" #include <stdint.h> #include <string> @@ -69,6 +70,11 @@ public: */ std::map<std::string, LogicalLibrary> libraries; + /** + * Mapping from volume identiifer to tape. + */ + std::map<std::string, Tape> tapes; + }; // class MockMiddleTierDatabase } // namespace cta -- GitLab