Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef MANTID_REMOTEALGORITHMS_LOGOUT2TEST_H_
#define MANTID_REMOTEALGORITHMS_LOGOUT2TEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/AlgorithmManager.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidRemoteAlgorithms/Logout2.h"
using namespace Mantid::RemoteAlgorithms;
class Logout2Test : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static Logout2Test *createSuite() { return new Logout2Test(); }
static void destroySuite(Logout2Test *suite) { delete suite; }
void test_algorithm() {
testAlg = Mantid::API::AlgorithmManager::Instance().create("Logout", 2);
TS_ASSERT(testAlg);
TS_ASSERT_EQUALS(testAlg->name(), "Logout");
TS_ASSERT_EQUALS(testAlg->version(), 2);
}
void test_castAlgorithm() {
// can create
boost::shared_ptr<Logout2> a;
TS_ASSERT(a = boost::make_shared<Logout2>());
// can cast to inherited interfaces and base classes
TS_ASSERT(dynamic_cast<Mantid::RemoteAlgorithms::Logout2 *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::API::Algorithm *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::Kernel::PropertyManagerOwner *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::API::IAlgorithm *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::Kernel::IPropertyManager *>(a.get()));
}
void test_init() {
if (!testAlg->isInitialized())
TS_ASSERT_THROWS_NOTHING(testAlg->initialize());
TS_ASSERT(testAlg->isInitialized());
Logout2 lo;
TS_ASSERT_THROWS_NOTHING(lo.initialize());
}
void test_propertiesMissing() {
Logout2 lo;
TS_ASSERT_THROWS_NOTHING(lo.initialize());
// username missing
TS_ASSERT_THROWS(lo.setPropertyValue("ComputeResource", "anything"),
std::invalid_argument);
TS_ASSERT_THROWS(lo.execute(), std::runtime_error);
TS_ASSERT(!lo.isExecuted());
}
void test_wrongProperty() {
Logout2 lo;
TS_ASSERT_THROWS_NOTHING(lo.initialize());
TS_ASSERT_THROWS(lo.setPropertyValue("usernam", "anything"),
std::runtime_error);
}
void test_runOK() {
testFacilities.emplace_back("SNS", "Fermi");
testFacilities.emplace_back("ISIS", "SCARF@STFC");
const Mantid::Kernel::FacilityInfo &prevFac =
Mantid::Kernel::ConfigService::Instance().getFacility();
// test that job managers are created correctly for different facilities
for (size_t fi = 0; fi < testFacilities.size(); fi++) {
const std::string facName = testFacilities[fi].first;
const std::string compName = testFacilities[fi].second;
Mantid::Kernel::ConfigService::Instance().setFacility(facName);
Logout2 lo;
TS_ASSERT_THROWS_NOTHING(lo.initialize());
TS_ASSERT_THROWS_NOTHING(
lo.setPropertyValue("ComputeResource", compName));
// Note: this would run the algorithm and could do a remote
// connection. uncomment only when/if we have a mock up for this
// TS_ASSERT_THROWS(lo.execute(), std::exception);
TS_ASSERT(!lo.isExecuted());
}
Mantid::Kernel::ConfigService::Instance().setFacility(prevFac.name());
}
private:
Mantid::API::IAlgorithm_sptr testAlg;
std::vector<std::pair<std::string, std::string>> testFacilities;
};
#endif // MANTID_REMOTEALGORITHMS_LOGOUT2TEST_H_