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

Added unit-test createStorageClass

parent 2ca0f54f
......@@ -74,7 +74,7 @@ void cta::catalogue::SqliteCatalogue::createDbSchema() {
"CREATE TABLE STORAGE_CLASS("
"STORAGE_CLASS_NAME TEXT,"
"NB_FILES INTEGER,"
"NB_COPIES INTEGER,"
"COMMENT TEXT,"
......@@ -108,25 +108,18 @@ void cta::catalogue::SqliteCatalogue::createBootstrapAdminAndHostNoAuth(
const common::dataStructures::UserIdentity &user,
const std::string &hostName,
const std::string &comment) {
const uint64_t now = time(NULL);
common::dataStructures::EntryLog creationLog;
creationLog.user.name = cliIdentity.user.name;
creationLog.user.group = cliIdentity.user.group;
creationLog.host = cliIdentity.host;
creationLog.time = now;
insertAdminUser(user, comment, creationLog);
insertAdminHost(hostName, comment, creationLog);
createAdminUser(cliIdentity, user, comment);
createAdminHost(cliIdentity, hostName, comment);
}
//------------------------------------------------------------------------------
// insertAdminUser
// createAdminUser
//------------------------------------------------------------------------------
void cta::catalogue::SqliteCatalogue::insertAdminUser(
void cta::catalogue::SqliteCatalogue::createAdminUser(
const common::dataStructures::SecurityIdentity &cliIdentity,
const common::dataStructures::UserIdentity &user,
const std::string &comment,
const common::dataStructures::EntryLog &creationLog) {
const std::string &comment) {
const uint64_t now = time(NULL);
const char *const sql =
"INSERT INTO ADMIN_USER("
"USER_NAME,"
......@@ -163,81 +156,14 @@ void cta::catalogue::SqliteCatalogue::insertAdminUser(
stmt.bind(":GROUP_NAME", user.group);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATION_LOG_USER_NAME", creationLog.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", creationLog.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", creationLog.host);
stmt.bind(":CREATION_LOG_TIME", creationLog.time);
stmt.step();
}
//------------------------------------------------------------------------------
// insertAdminHost
//------------------------------------------------------------------------------
void cta::catalogue::SqliteCatalogue::insertAdminHost(
const std::string &hostName,
const std::string &comment,
const common::dataStructures::EntryLog &creationLog) {
const char *const sql =
"INSERT INTO ADMIN_HOST("
"HOST_NAME,"
"COMMENT,"
"CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME,"
"LAST_MOD_USER_NAME,"
"LAST_MOD_GROUP_NAME,"
"LAST_MOD_HOST_NAME,"
"LAST_MOD_TIME)"
"VALUES("
":HOST_NAME,"
":COMMENT,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME);";
SqliteStmt stmt(m_conn, sql);
stmt.bind(":HOST_NAME", hostName);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATION_LOG_USER_NAME", creationLog.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", creationLog.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", creationLog.host);
stmt.bind(":CREATION_LOG_TIME", creationLog.time);
stmt.bind(":CREATION_LOG_USER_NAME", cliIdentity.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", cliIdentity.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", cliIdentity.host);
stmt.bind(":CREATION_LOG_TIME", now);
stmt.step();
}
//------------------------------------------------------------------------------
// createAdminUser
//------------------------------------------------------------------------------
void cta::catalogue::SqliteCatalogue::createAdminUser(
const common::dataStructures::SecurityIdentity &cliIdentity,
const common::dataStructures::UserIdentity &user,
const std::string &comment) {
const uint64_t now = time(NULL);
common::dataStructures::EntryLog creationLog;
creationLog.user.name = cliIdentity.user.name;
creationLog.user.group = cliIdentity.user.group;
creationLog.host = cliIdentity.host;
creationLog.time = now;
insertAdminUser(user, comment, creationLog);
}
//------------------------------------------------------------------------------
// deleteAdminUser
//------------------------------------------------------------------------------
......@@ -323,14 +249,46 @@ void cta::catalogue::SqliteCatalogue::createAdminHost(
const std::string &hostName,
const std::string &comment) {
const uint64_t now = time(NULL);
const char *const sql =
"INSERT INTO ADMIN_HOST("
"HOST_NAME,"
"COMMENT,"
"CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME,"
"LAST_MOD_USER_NAME,"
"LAST_MOD_GROUP_NAME,"
"LAST_MOD_HOST_NAME,"
"LAST_MOD_TIME)"
"VALUES("
":HOST_NAME,"
common::dataStructures::EntryLog creationLog;
creationLog.user.name = cliIdentity.user.name;
creationLog.user.group = cliIdentity.user.group;
creationLog.host = cliIdentity.host;
creationLog.time = now;
":COMMENT,"
insertAdminHost(hostName, comment, creationLog);
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME);";
SqliteStmt stmt(m_conn, sql);
stmt.bind(":HOST_NAME", hostName);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATION_LOG_USER_NAME", cliIdentity.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", cliIdentity.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", cliIdentity.host);
stmt.bind(":CREATION_LOG_TIME", now);
stmt.step();
}
//------------------------------------------------------------------------------
......@@ -415,7 +373,7 @@ void cta::catalogue::SqliteCatalogue::createStorageClass(
const char *const sql =
"INSERT INTO STORAGE_CLASS("
"STORAGE_CLASS_NAME,"
"NB_FILES,"
"NB_COPIES,"
"COMMENT,"
......@@ -430,7 +388,7 @@ void cta::catalogue::SqliteCatalogue::createStorageClass(
"LAST_MOD_TIME)"
"VALUES("
":STORAGE_CLASS_NAME,"
":NB_FILES,"
":NB_COPIES,"
":COMMENT,"
......@@ -446,7 +404,7 @@ void cta::catalogue::SqliteCatalogue::createStorageClass(
SqliteStmt stmt(m_conn, sql);
stmt.bind(":STORAGE_CLASS_NAME", name);
stmt.bind(":NB_FILES", nbCopies);
stmt.bind(":NB_COPIES", nbCopies);
stmt.bind(":COMMENT", comment);
......@@ -466,7 +424,65 @@ void cta::catalogue::SqliteCatalogue::deleteStorageClass(const std::string &name
//------------------------------------------------------------------------------
// getStorageClasses
//------------------------------------------------------------------------------
std::list<cta::common::dataStructures::StorageClass> cta::catalogue::SqliteCatalogue::getStorageClasses() const { return std::list<cta::common::dataStructures::StorageClass>();}
std::list<cta::common::dataStructures::StorageClass>
cta::catalogue::SqliteCatalogue::getStorageClasses() const {
std::list<common::dataStructures::StorageClass> storageClasses;
const char *const sql =
"SELECT "
"STORAGE_CLASS_NAME AS STORAGE_CLASS_NAME,"
"NB_COPIES AS NB_COPIES,"
"COMMENT AS COMMENT,"
"CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME AS CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"LAST_MOD_USER_NAME AS LAST_MOD_USER_NAME,"
"LAST_MOD_GROUP_NAME AS LAST_MOD_GROUP_NAME,"
"LAST_MOD_HOST_NAME AS LAST_MOD_HOST_NAME,"
"LAST_MOD_TIME AS LAST_MOD_TIME "
"FROM STORAGE_CLASS";
SqliteStmt stmt(m_conn, sql);
ColumnNameToIdx nameToIdx;
while(SQLITE_ROW == stmt.step()) {
if(nameToIdx.empty()) {
nameToIdx = stmt.getColumnNameToIdx();
}
common::dataStructures::StorageClass storageClass;
storageClass.name = stmt.columnText(nameToIdx["STORAGE_CLASS_NAME"]);
storageClass.nbCopies = stmt.columnUint64(nameToIdx["NB_COPIES"]);
storageClass.comment = stmt.columnText(nameToIdx["COMMENT"]);
common::dataStructures::UserIdentity creatorUI;
creatorUI.name = stmt.columnText(nameToIdx["CREATION_LOG_USER_NAME"]);
creatorUI.group = stmt.columnText(nameToIdx["CREATION_LOG_GROUP_NAME"]);
common::dataStructures::EntryLog creationLog;
creationLog.user = creatorUI;
creationLog.host = stmt.columnText(nameToIdx["CREATION_LOG_HOST_NAME"]);
creationLog.time = stmt.columnUint64(nameToIdx["CREATION_LOG_TIME"]);
storageClass.creationLog = creationLog;
common::dataStructures::UserIdentity updaterUI;
updaterUI.name = stmt.columnText(nameToIdx["LAST_MOD_USER_NAME"]);
updaterUI.group = stmt.columnText(nameToIdx["LAST_MOD_GROUP_NAME"]);
common::dataStructures::EntryLog updateLog;
updateLog.user = updaterUI;
updateLog.host = stmt.columnText(nameToIdx["LAST_MOD_HOST_NAME"]);
updateLog.time = stmt.columnUint64(nameToIdx["LAST_MOD_TIME"]);
storageClass.lastModificationLog = updateLog;
storageClasses.push_back(storageClass);
}
return storageClasses;
}
//------------------------------------------------------------------------------
// modifyStorageClassNbCopies
......
......@@ -171,32 +171,6 @@ private:
*/
void createDbSchema();
/**
* Inserts the specified row into the ADMIN_USER table.
*
* @param user The admin user.
* @param comment The comment.
* @param creationLog The log to be used as both the creation and last
* modification logs.
*/
void insertAdminUser(
const common::dataStructures::UserIdentity &user,
const std::string &comment,
const common::dataStructures::EntryLog &creationLog);
/**
* Inserts the specified row into the ADMIN_HOST table.
*
* @param hostName The name of the admin host.
* @param comment The comment.
* @param creationLog The log to be used as both the creation and last
* modification logs.
*/
void insertAdminHost(
const std::string &hostName,
const std::string &comment,
const common::dataStructures::EntryLog &creationLog);
/**
* Returns true if the specified user name is listed in the ADMIN_USER table.
*
......
......@@ -28,7 +28,7 @@ namespace unitTests {
class cta_catalogue_SqliteCatalogueTest : public ::testing::Test {
public:
cta_catalogue_SqliteCatalogueTest():
m_bootstrapComment("bootstrap comment") {
m_bootstrapComment("bootstrap") {
m_cliUI.group = "cli_group_name";
m_cliUI.name = "cli_user_name";
......@@ -134,7 +134,7 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminUser) {
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string createAdminUserComment = "create admin user comment";
const std::string createAdminUserComment = "create admin user";
ASSERT_NO_THROW(catalogue.createAdminUser(m_bootstrapAdminSI, m_adminUI,
createAdminUserComment));
......@@ -242,7 +242,7 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminHost) {
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string createAdminHostComment = "create host user comment";
const std::string createAdminHostComment = "create host user";
const std::string anotherAdminHost = "another_admin_host";
ASSERT_NO_THROW(catalogue.createAdminHost(m_bootstrapAdminSI,
anotherAdminHost, createAdminHostComment));
......@@ -349,4 +349,36 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, isAdmin_true) {
ASSERT_TRUE(catalogue.isAdmin(m_bootstrapAdminSI));
}
TEST_F(cta_catalogue_SqliteCatalogueTest, createStorageClass) {
using namespace cta;
catalogue::SqliteCatalogue catalogue;
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 2;
const std::string comment = "create storage class";
ASSERT_NO_THROW(catalogue.createStorageClass(m_cliSI,
storageClassName, nbCopies, comment));
const std::list<common::dataStructures::StorageClass> storageClasses =
catalogue.getStorageClasses();
ASSERT_EQ(1, storageClasses.size());
const common::dataStructures::StorageClass storageClass =
storageClasses.front();
ASSERT_EQ(storageClassName, storageClass.name);
ASSERT_EQ(nbCopies, storageClass.nbCopies);
ASSERT_EQ(comment, storageClass.comment);
const common::dataStructures::EntryLog creationLog = storageClass.creationLog;
ASSERT_EQ(m_cliSI.user.name, creationLog.user.name);
ASSERT_EQ(m_cliSI.user.group, creationLog.user.group);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
storageClass.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
} // 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