Skip to content

Commit

Permalink
Refactor compositeCatalogTest. Refs #9026.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Feb 20, 2014
1 parent d5b8673 commit 8982762
Showing 1 changed file with 31 additions and 133 deletions.
164 changes: 31 additions & 133 deletions Code/Mantid/Framework/ICat/test/CompositeCatalogTest.h
Expand Up @@ -7,6 +7,7 @@
#include "MantidICat/CompositeCatalog.h"

#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>

using namespace Mantid::API;
using namespace Mantid::ICat;
Expand Down Expand Up @@ -106,231 +107,128 @@ class CompositeCatalogTest : public CxxTest::TestSuite
/// Verifies that multiple catalogs are being logged in to.
void testLogin()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
// Set the inital state to zero as it's static & used in other methods.
DummyCatalog::m_counter = 0;
// Add catalogs to the composite catalog.
compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());
// This will attempt to login to each catalog that has been added.
std::string temp = "";
compositeCatalog->login(temp,temp,temp);
// This will attempt to login to each dummy catalog
// that has been added to the composite created.
createCompositeCatalog()->login(temp,temp,temp);
// Verify that the composite catalog login method works as expected.
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);
// Delete the objects that were manually created.
delete compositeCatalog;
}

void testLogout()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

compositeCatalog->logout();

createCompositeCatalog()->logout();
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testSearch()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

CatalogSearchParam params;
ITableWorkspace_sptr ws;
int limit = 0;
int offset = 0;
compositeCatalog->search(params,ws,offset,limit);

createCompositeCatalog()->search(params,ws,offset,limit);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testGetNumberOfSearchResults()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

CatalogSearchParam params;
compositeCatalog->getNumberOfSearchResults(params);

createCompositeCatalog()->getNumberOfSearchResults(params);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testMyData()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

ITableWorkspace_sptr ws;
compositeCatalog->myData(ws);
createCompositeCatalog()->myData(ws);

TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testGetDataSets()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

ITableWorkspace_sptr ws;
std::string id = "";
compositeCatalog->getDataSets(id,ws);

createCompositeCatalog()->getDataSets(id,ws);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testGetDataFiles()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

ITableWorkspace_sptr ws;
std::string id = "";
compositeCatalog->getDataFiles(id,ws);

createCompositeCatalog()->getDataFiles(id,ws);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testListInstruments()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

std::vector<std::string> vector;
compositeCatalog->listInstruments(vector);
createCompositeCatalog()->listInstruments(vector);

TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testListInvestigationTypes()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

std::vector<std::string> vector;
compositeCatalog->listInvestigationTypes(vector);

createCompositeCatalog()->listInvestigationTypes(vector);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testGetFileLocation()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

const long long temp = 0;
std::string fileLocation = "";
compositeCatalog->getFileLocation(temp,fileLocation);

createCompositeCatalog()->getFileLocation(temp,fileLocation);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testGetDownloadURL()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

const long long temp = 0;
std::string url = "";
compositeCatalog->getDownloadURL(temp, url);

createCompositeCatalog()->getDownloadURL(temp, url);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testGetUploadURL()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

std::string temp = "";
compositeCatalog->getUploadURL(temp,temp,temp);

createCompositeCatalog()->getUploadURL(temp,temp,temp);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testKeepAlive()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

compositeCatalog->keepAlive();

createCompositeCatalog()->keepAlive();
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);

delete compositeCatalog;
}

void testKeepAliveinminutes()
{
CompositeCatalog* compositeCatalog = new CompositeCatalog();
createCompositeCatalog()->keepAliveinminutes();
TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);
}

private:

/**
* Create a compositeCatalog and add two DummyCatalogs to it.
* @return A shared pointer to a CompositeCatalog.
*/
boost::shared_ptr<CompositeCatalog> createCompositeCatalog()
{
boost::shared_ptr<CompositeCatalog>compositeCatalog(new CompositeCatalog());
DummyCatalog::m_counter = 0;

compositeCatalog->add(boost::make_shared<DummyCatalog>());
compositeCatalog->add(boost::make_shared<DummyCatalog>());

compositeCatalog->keepAliveinminutes();

TS_ASSERT_EQUALS(DummyCatalog::m_counter,2);
TS_ASSERT_EQUALS(DummyCatalog::m_counter,0);

delete compositeCatalog;
return compositeCatalog;
}

};
Expand Down

0 comments on commit 8982762

Please sign in to comment.