Commit 79416605 authored by Steven Murray's avatar Steven Murray
Browse files

All unit tests now pass

parent abadf1bf
......@@ -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;
}
......@@ -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.
*/
......
......@@ -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;
......
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment