Commit 251b9751 authored by Steven Murray's avatar Steven Murray
Browse files

Added value-parameterized abstract test fixture CatalogueTest

parent d37e927c
......@@ -84,6 +84,8 @@ add_custom_command(OUTPUT InMemoryCatalogueSchema.cpp
set(CATALOGUE_UNIT_TESTS_LIB_SRC_FILES
CatalogueFactoryTest.cpp
CatalogueTest.cpp
DbLoginFactory.cpp
DbLoginTest.cpp
ParamNameToIdxTest.cpp
InMemoryCatalogueTest.cpp
......@@ -98,10 +100,13 @@ target_link_libraries (ctacatalogueunittests
install(TARGETS ctacatalogueunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
set (CATALOGUE_ORA_UNIT_TESTS_LIB_SRC_FILES
CatalogueTest.cpp
DbLoginFactory.cpp
OcciConnTest.cpp
OcciEnvTest.cpp
OcciRsetTest.cpp
OcciStmtTest.cpp)
OcciStmtTest.cpp
OracleCatalogueTest.cpp)
add_library (ctacatalogueoraunittests SHARED
${CATALOGUE_ORA_UNIT_TESTS_LIB_SRC_FILES})
......
This diff is collapsed.
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "catalogue/ArchiveFileRow.hpp"
#include "catalogue/CatalogueFactory.hpp"
#include "catalogue/DbLoginFactory.hpp"
#include "catalogue/UserError.hpp"
#include "common/exception/Exception.hpp"
#include <gtest/gtest.h>
#include <map>
#include <memory>
#include <set>
namespace unitTests {
class cta_catalogue_CatalogueTest : public ::testing::TestWithParam<cta::catalogue::DbLoginFactory*> {
public:
cta_catalogue_CatalogueTest():
m_bootstrapComment("bootstrap") {
m_cliSI.username = "cli_user_name";
m_cliSI.host = "cli_host";
m_bootstrapAdminSI.username = "bootstrap_admin_user_name";
m_bootstrapAdminSI.host = "bootstrap_host";
m_adminSI.username = "admin_user_name";
m_adminSI.host = "admin_host";
}
protected:
virtual void SetUp() {
using namespace cta;
using namespace cta::catalogue;
m_catalogue.reset(CatalogueFactory::create(GetParam()->create()));
{
const std::list<common::dataStructures::AdminUser> adminUsers = m_catalogue->getAdminUsers();
for(auto &adminUser: adminUsers) {
m_catalogue->deleteAdminUser(adminUser.name);
}
}
{
const std::list<common::dataStructures::AdminHost> adminHosts = m_catalogue->getAdminHosts();
for(auto &adminHost: adminHosts) {
m_catalogue->deleteAdminHost(adminHost.name);
}
}
{
const std::list<common::dataStructures::ArchiveRoute> archiveRoutes = m_catalogue->getArchiveRoutes();
for(auto &archiveRoute: archiveRoutes) {
m_catalogue->deleteArchiveRoute(archiveRoute.storageClassName, archiveRoute.copyNb);
}
}
{
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
for(auto &rule: rules) {
m_catalogue->deleteRequesterMountRule(rule.name);
}
}
{
const std::list<common::dataStructures::RequesterGroupMountRule> rules =
m_catalogue->getRequesterGroupMountRules();
for(auto &rule: rules) {
m_catalogue->deleteRequesterGroupMountRule(rule.name);
}
}
{
std::unique_ptr<ArchiveFileItor> itor = m_catalogue->getArchiveFileItor();
while(itor->hasMore()) {
m_catalogue->deleteArchiveFile(itor->next().archiveFileID);
}
}
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
for(auto &tape: tapes) {
m_catalogue->deleteTape(tape.vid);
}
}
{
const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();
for(auto &storageClass: storageClasses) {
m_catalogue->deleteStorageClass(storageClass.name);
}
}
{
const std::list<common::dataStructures::TapePool> tapePools = m_catalogue->getTapePools();
for(auto &tapePool: tapePools) {
m_catalogue->deleteTapePool(tapePool.name);
}
}
{
const std::list<common::dataStructures::LogicalLibrary> logicalLibraries = m_catalogue->getLogicalLibraries();
for(auto &logicalLibrary: logicalLibraries) {
m_catalogue->deleteLogicalLibrary(logicalLibrary.name);
}
}
{
const std::list<common::dataStructures::MountPolicy> mountPolicies = m_catalogue->getMountPolicies();
for(auto &mountPolicy: mountPolicies) {
m_catalogue->deleteMountPolicy(mountPolicy.name);
}
}
}
virtual void TearDown() {
m_catalogue.reset();
}
std::unique_ptr<cta::catalogue::Catalogue> m_catalogue;
const std::string m_bootstrapComment;
cta::common::dataStructures::SecurityIdentity m_cliSI;
cta::common::dataStructures::SecurityIdentity m_bootstrapAdminSI;
cta::common::dataStructures::SecurityIdentity m_adminSI;
/**
* Creates a map from VID to tape given the specified list of tapes.
*
* @param listOfTapes The list of tapes from which the map shall be created.
* @return The map from VID to tape.
*/
std::map<std::string, cta::common::dataStructures::Tape> tapeListToMap(
const std::list<cta::common::dataStructures::Tape> &listOfTapes) {
using namespace cta;
try {
std::map<std::string, cta::common::dataStructures::Tape> vidToTape;
for (auto &&tape: listOfTapes) {
if(vidToTape.end() != vidToTape.find(tape.vid)) {
throw exception::Exception(std::string("Duplicate VID: value=") + tape.vid);
}
vidToTape[tape.vid] = tape;
}
return vidToTape;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
/**
* Creates a map from archive file ID to archive file from the specified iterator.
*
* @param itor Iterator over archive files.
* @return Map from archive file ID to archive file.
*/
std::map<uint64_t, cta::common::dataStructures::ArchiveFile> archiveFileItorToMap(cta::catalogue::ArchiveFileItor &itor) {
using namespace cta;
try {
std::map<uint64_t, common::dataStructures::ArchiveFile> m;
while(itor.hasMore()) {
const common::dataStructures::ArchiveFile archiveFile = itor.next();
if(m.end() != m.find(archiveFile.archiveFileID)) {
exception::Exception ex;
ex.getMessage() << "Archive file with ID " << archiveFile.archiveFileID << " is a duplicate";
throw ex;
}
m[archiveFile.archiveFileID] = archiveFile;
}
return m;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
}; // cta_catalogue_CatalogueTest
} // namespace unitTests
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/DbLoginFactory.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
DbLoginFactory::~DbLoginFactory() {
}
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "catalogue/DbLogin.hpp"
namespace cta {
namespace catalogue {
/**
* Abstract class specifying the interface to a factory of DbLogin objects.
*/
class DbLoginFactory {
public:
/**
* Destructor.
*/
virtual ~DbLoginFactory() = 0;
/**
* Returns a newly created DbLogin object.
*
* @return A newly created DbLogin object.
*/
virtual DbLogin create() = 0;
}; // class DbLogin
} // namespace catalogue
} // namespace cta
This diff is collapsed.
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CatalogueTest.hpp"
#include "tests/OraUnitTestsCmdLineArgs.hpp"
namespace {
/**
* Creates DbLogin objects for in-memory catalogue databases.
*/
class OracleDbLoginFactory: public cta::catalogue::DbLoginFactory {
public:
/**
* Destructor.
*/
virtual ~OracleDbLoginFactory() {
}
/**
* Returns a newly created DbLogin object.
*
* @return A newly created DbLogin object.
*/
virtual cta::catalogue::DbLogin create() {
using namespace cta::catalogue;
return DbLogin::parseFile(g_cmdLineArgs.oraDbConnFile);
}
}; // class OracleDbLoginFactory
OracleDbLoginFactory g_oracleDbLoginFactory;
} // anonymous namespace
namespace unitTests {
INSTANTIATE_TEST_CASE_P(Oracle, cta_catalogue_CatalogueTest,
::testing::Values(dynamic_cast<cta::catalogue::DbLoginFactory*>(&g_oracleDbLoginFactory)));
} // namespace unitTests
......@@ -53,10 +53,10 @@ add_executable(cta-oraUnitTests
${GMOCK_SRC})
target_link_libraries(cta-oraUnitTests
ctacatalogueoraunittests
${GMOCK_LIB}
gtest
pthread)
ctacatalogueoraunittests
${GMOCK_LIB}
gtest
pthread)
add_executable(cta-unitTests-multiProcess
unit_tests.cpp
......
......@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CatalogueTest.hpp"
#include "tests/OraUnitTestsCmdLineArgs.hpp"
#include <gmock/gmock.h>
......@@ -32,8 +33,9 @@ static void printUsage(std::ostream &os) {
}
/**
* Parses the specified command-line arguments. This should be called after Google test has consumed all of its
* command-line options from the command-line.
* Parses the specified command-line arguments. This should be called after
* Google test has consumed all of its command-line options from the
* command-line.
*/
static CmdLineArgs parseCmdLine(const int argc, char ** argv) {
if(argc != 2) {
......
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