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

Added unit tests for creating, deleting and getting tapes.

The tests intentionally fail.
parent f907abcc
......@@ -8,6 +8,7 @@
#include "MigrationRoute.hpp"
#include "SecurityIdentity.hpp"
#include "StorageClass.hpp"
#include "Tape.hpp"
#include "TapePool.hpp"
#include "UserIdentity.hpp"
......@@ -212,7 +213,7 @@ public:
const SecurityIdentity &requester) const = 0;
/**
* Creates a logical library with the specified name and device group.
* Creates a logical library with the specified name.
*
* @param requester The identity of the user requesting the creation of the
* logical library.
......@@ -244,6 +245,48 @@ public:
virtual std::list<LogicalLibrary> getLogicalLibraries(
const SecurityIdentity &requester) const = 0;
/**
* Creates a tape.
*
* @param requester The identity of the user requesting the creation of the
* tape.
* @param vid The volume identifier of the tape.
* @param logicalLibrary The name of the logical library to which the tape
* belongs.
* @param tapePoolName The name of the tape pool to which the tape belongs.
* @param capacityInBytes The capacity of the tape.
* @param comment The comment describing the logical library.
*/
virtual void createTape(
const SecurityIdentity &requester,
const std::string &vid,
const std::string &logicalLibraryName,
const std::string &tapePoolName,
const uint64_t capacityInBytes,
const std::string &comment) = 0;
/**
* Deletes the tape with the specified volume identifier.
*
* @param requester The identity of the user requesting the deletion of the
* tape.
* @param vid The volume identifier of the tape.
*/
virtual void deleteTape(
const SecurityIdentity &requester,
const std::string &vid) = 0;
/**
* Returns the current list of tapes in the lexicographical order of their
* volume identifiers.
*
* @param requester The identity of the user requesting the list.
* @return The current list of tapes in the lexicographical order of their
* volume identifiers.
*/
virtual std::list<Tape> getTapes(
const SecurityIdentity &requester) const = 0;
}; // class MiddleTierAdmin
} // namespace cta
......@@ -343,3 +343,32 @@ std::list<cta::LogicalLibrary> cta::MockMiddleTierAdmin::getLogicalLibraries(
}
return libraries;
}
//------------------------------------------------------------------------------
// createTape
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::createTape(
const SecurityIdentity &requester,
const std::string &vid,
const std::string &logicalLibraryName,
const std::string &tapePoolName,
const uint64_t capacityInBytes,
const std::string &comment) {
}
//------------------------------------------------------------------------------
// deleteTape
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::deleteTape(
const SecurityIdentity &requester,
const std::string &vid) {
}
//------------------------------------------------------------------------------
// getTapes
//------------------------------------------------------------------------------
std::list<cta::Tape> cta::MockMiddleTierAdmin::getTapes(
const SecurityIdentity &requester) const {
std::list<cta::Tape> tapes;
return tapes;
}
......@@ -204,7 +204,7 @@ public:
const SecurityIdentity &requester) const;
/**
* Creates a logical library with the specified name and device group.
* Creates a logical library with the specified name.
*
* @param requester The identity of the user requesting the creation of the
* logical library.
......@@ -236,6 +236,48 @@ public:
std::list<LogicalLibrary> getLogicalLibraries(
const SecurityIdentity &requester) const;
/**
* Creates a tape.
*
* @param requester The identity of the user requesting the creation of the
* tape.
* @param vid The volume identifier of the tape.
* @param logicalLibrary The name of the logical library to which the tape
* belongs.
* @param tapePoolName The name of the tape pool to which the tape belongs.
* @param capacityInBytes The capacity of the tape.
* @param comment The comment describing the logical library.
*/
void createTape(
const SecurityIdentity &requester,
const std::string &vid,
const std::string &logicalLibraryName,
const std::string &tapePoolName,
const uint64_t capacityInBytes,
const std::string &comment);
/**
* Deletes the tape with the specified volume identifier.
*
* @param requester The identity of the user requesting the deletion of the
* tape.
* @param vid The volume identifier of the tape.
*/
void deleteTape(
const SecurityIdentity &requester,
const std::string &vid);
/**
* Returns the current list of tapes in the lexicographical order of their
* volume identifiers.
*
* @param requester The identity of the user requesting the list.
* @return The current list of tapes in the lexicographical order of their
* volume identifiers.
*/
std::list<Tape> getTapes(
const SecurityIdentity &requester) const;
protected:
/**
......@@ -300,55 +342,6 @@ protected:
*/
bool isAnExistingDirectory(const std::string &path) const throw();
/**
* Archives the specified list of source files to the specified destination
* directory within the archive namespace.
*
* The list of source files should contain at least one file.
*
* The storage class of the archived file will be inherited from its
* destination directory.
*
* @param requester The identity of the user requesting the archival.
* @param srcUrls List of one or more source files.
* @param dstDir Destination directory within the archive namespace.
* @return The string identifier of the archive job.
*/
std::string archiveToDirectory(
const SecurityIdentity &requester,
const std::list<std::string> &srcUrls,
const std::string &dstDir);
/**
* Archives the specified list of source files to the specified destination
* file within the archive namespace.
*
* The list of source files should contain one and only one file.
*
* The storage class of the archived file will be inherited from its
* destination directory.
*
* @param requester The identity of the user requesting the archival.
* @param srcUrls List of one or more source files.
* @param dstFile Destination file within the archive namespace.
* @return The string identifier of the archive job.
*/
std::string archiveToFile(
const SecurityIdentity &requester,
const std::list<std::string> &srcUrls,
const std::string &dstFile);
/**
* Throws an exception if the specified requester is not authorised to archive
* a file to the specified destination directory within the archive namespace.
*
* @param requester The identity of the user requesting the archival.
* @param dstDir Destination directory within the archive namespace.
*/
void checkUserIsAuthorisedToArchive(
const SecurityIdentity &user,
const FileSystemNode &dstDir);
/**
* Throws an exception if the specified logical library already exists.
*
......
......@@ -972,10 +972,10 @@ TEST_F(cta_client_MockMiddleTierAdminTest, createLogicalLibrary_new) {
ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester));
ASSERT_EQ(1, libraries.size());
LogicalLibrary LogicalLibrary;
ASSERT_NO_THROW(LogicalLibrary = libraries.front());
ASSERT_EQ(libraryName, LogicalLibrary.getName());
ASSERT_EQ(libraryComment, LogicalLibrary.getComment());
LogicalLibrary logicalLibrary;
ASSERT_NO_THROW(logicalLibrary = libraries.front());
ASSERT_EQ(libraryName, logicalLibrary.getName());
ASSERT_EQ(libraryComment, logicalLibrary.getComment());
}
}
......@@ -1003,10 +1003,10 @@ TEST_F(cta_client_MockMiddleTierAdminTest,
ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester));
ASSERT_EQ(1, libraries.size());
LogicalLibrary LogicalLibrary;
ASSERT_NO_THROW(LogicalLibrary = libraries.front());
ASSERT_EQ(libraryName, LogicalLibrary.getName());
ASSERT_EQ(libraryComment, LogicalLibrary.getComment());
LogicalLibrary logicalLibrary;
ASSERT_NO_THROW(logicalLibrary = libraries.front());
ASSERT_EQ(libraryName, logicalLibrary.getName());
ASSERT_EQ(libraryComment, logicalLibrary.getComment());
}
ASSERT_THROW(adminApi.createLogicalLibrary(requester, libraryName,
......@@ -1109,4 +1109,247 @@ TEST_F(cta_client_MockMiddleTierAdminTest, deleteLogicalLibrary_non_existing) {
}
}
TEST_F(cta_client_MockMiddleTierAdminTest, createTape_new) {
using namespace cta;
MockMiddleTierDatabase db;
MockMiddleTierAdmin adminApi(db);
const SecurityIdentity requester;
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
const std::string libraryName = "TestLogicalLibrary";
const std::string libraryComment = "Library comment";
ASSERT_NO_THROW(adminApi.createLogicalLibrary(requester, libraryName,
libraryComment));
const std::string poolName = "TestTapePool";
const uint16_t nbDrives = 1;
const uint32_t nbPartialTapes = 1;
const std::string poolComment = "Tape-pool comment";
ASSERT_NO_THROW(adminApi.createTapePool(requester, poolName, nbDrives,
nbPartialTapes, poolComment));
const std::string vid = "TestVid";
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
ASSERT_NO_THROW(adminApi.createTape(requester, vid, libraryName, poolName,
capacityInBytes, tapeComment));
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_EQ(1, tapes.size());
Tape tape;
ASSERT_NO_THROW(tape = tapes.front());
ASSERT_EQ(vid, tape.getVid());
ASSERT_EQ(libraryName, tape.getLogicalLibraryName());
ASSERT_EQ(poolName, tape.getTapePoolName());
ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes());
ASSERT_EQ(0, tape.getDataOnTapeInBytes());
ASSERT_EQ(tapeComment, tape.getComment());
}
}
TEST_F(cta_client_MockMiddleTierAdminTest, createTape_already_existing) {
using namespace cta;
MockMiddleTierDatabase db;
MockMiddleTierAdmin adminApi(db);
const SecurityIdentity requester;
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
const std::string libraryName = "TestLogicalLibrary";
const std::string libraryComment = "Library comment";
ASSERT_NO_THROW(adminApi.createLogicalLibrary(requester, libraryName,
libraryComment));
const std::string poolName = "TestTapePool";
const uint16_t nbDrives = 1;
const uint32_t nbPartialTapes = 1;
const std::string poolComment = "Tape-pool comment";
ASSERT_NO_THROW(adminApi.createTapePool(requester, poolName, nbDrives,
nbPartialTapes, poolComment));
const std::string vid = "TestVid";
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
ASSERT_NO_THROW(adminApi.createTape(requester, vid, libraryName, poolName,
capacityInBytes, tapeComment));
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_EQ(1, tapes.size());
Tape tape;
ASSERT_NO_THROW(tape = tapes.front());
ASSERT_EQ(vid, tape.getVid());
ASSERT_EQ(libraryName, tape.getLogicalLibraryName());
ASSERT_EQ(poolName, tape.getTapePoolName());
ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes());
ASSERT_EQ(0, tape.getDataOnTapeInBytes());
ASSERT_EQ(tapeComment, tape.getComment());
}
ASSERT_THROW(adminApi.createTape(requester, vid, libraryName, poolName,
capacityInBytes, tapeComment), std::exception);
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_EQ(1, tapes.size());
Tape tape;
ASSERT_NO_THROW(tape = tapes.front());
ASSERT_EQ(vid, tape.getVid());
ASSERT_EQ(libraryName, tape.getLogicalLibraryName());
ASSERT_EQ(poolName, tape.getTapePoolName());
ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes());
ASSERT_EQ(0, tape.getDataOnTapeInBytes());
ASSERT_EQ(tapeComment, tape.getComment());
}
}
TEST_F(cta_client_MockMiddleTierAdminTest, createTape_lexicographical_order) {
using namespace cta;
MockMiddleTierDatabase db;
MockMiddleTierAdmin adminApi(db);
const SecurityIdentity requester;
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
const std::string libraryName = "TestLogicalLibrary";
const std::string libraryComment = "Library comment";
ASSERT_NO_THROW(adminApi.createLogicalLibrary(requester, libraryName,
libraryComment));
const std::string poolName = "TestTapePool";
const uint16_t nbDrives = 1;
const uint32_t nbPartialTapes = 1;
const std::string poolComment = "Tape-pool comment";
ASSERT_NO_THROW(adminApi.createTapePool(requester, poolName, nbDrives,
nbPartialTapes, poolComment));
const uint64_t capacityInBytes = 12345678;
ASSERT_NO_THROW(adminApi.createTape(requester, "d", libraryName, poolName, capacityInBytes,
"Comment d"));
ASSERT_NO_THROW(adminApi.createTape(requester, "b", libraryName, poolName, capacityInBytes,
"Comment b"));
ASSERT_NO_THROW(adminApi.createTape(requester, "a", libraryName, poolName, capacityInBytes,
"Comment a"));
ASSERT_NO_THROW(adminApi.createTape(requester, "c", libraryName, poolName, capacityInBytes,
"Comment c"));
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_EQ(4, tapes.size());
ASSERT_EQ(std::string("a"), tapes.front().getVid());
tapes.pop_front();
ASSERT_EQ(std::string("b"), tapes.front().getVid());
tapes.pop_front();
ASSERT_EQ(std::string("c"), tapes.front().getVid());
tapes.pop_front();
ASSERT_EQ(std::string("d"), tapes.front().getVid());
}
}
TEST_F(cta_client_MockMiddleTierAdminTest, deleteTape_existing) {
using namespace cta;
MockMiddleTierDatabase db;
MockMiddleTierAdmin adminApi(db);
const SecurityIdentity requester;
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
const std::string libraryName = "TestLogicalLibrary";
const std::string libraryComment = "Library comment";
ASSERT_NO_THROW(adminApi.createLogicalLibrary(requester, libraryName,
libraryComment));
const std::string poolName = "TestTapePool";
const uint16_t nbDrives = 1;
const uint32_t nbPartialTapes = 1;
const std::string poolComment = "Tape-pool comment";
ASSERT_NO_THROW(adminApi.createTapePool(requester, poolName, nbDrives,
nbPartialTapes, poolComment));
const std::string vid = "TestVid";
const uint64_t capacityInBytes = 12345678;
const std::string tapeComment = "Tape comment";
ASSERT_NO_THROW(adminApi.createTape(requester, vid, libraryName, poolName,
capacityInBytes, tapeComment));
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_EQ(1, tapes.size());
Tape tape;
ASSERT_NO_THROW(tape = tapes.front());
ASSERT_EQ(vid, tape.getVid());
ASSERT_EQ(libraryName, tape.getLogicalLibraryName());
ASSERT_EQ(poolName, tape.getTapePoolName());
ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes());
ASSERT_EQ(0, tape.getDataOnTapeInBytes());
ASSERT_EQ(tapeComment, tape.getComment());
}
ASSERT_THROW(adminApi.createTape(requester, vid, libraryName, poolName,
capacityInBytes, tapeComment), std::exception);
ASSERT_NO_THROW(adminApi.deleteLogicalLibrary(requester, vid));
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
}
TEST_F(cta_client_MockMiddleTierAdminTest, deleteTape_non_existing) {
using namespace cta;
MockMiddleTierDatabase db;
MockMiddleTierAdmin adminApi(db);
const SecurityIdentity requester;
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
const std::string vid = "TestVid";
ASSERT_THROW(adminApi.deleteTape(requester, vid), std::exception);
{
std::list<Tape> tapes;
ASSERT_NO_THROW(tapes = adminApi.getTapes(requester));
ASSERT_TRUE(tapes.empty());
}
}
} // namespace unitTests
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