MongoTestHelper.h
Go to the documentation of this file.
1
/*
2
* This file is part of ArmarX.
3
*
4
* ArmarX is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
7
*
8
* ArmarX is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*
16
* @package MemoryX::Core
17
* @author Nils Adermann (naderman at naderman dot de)
18
* @date 2014
19
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20
* GNU General Public License
21
*/
22
23
#pragma once
24
25
#include <cstdlib>
26
#include <map>
27
#include <memory>
28
#include <stdexcept>
29
30
#include <
ArmarXCore/core/system/cmake/CMakePackageFinder.h
>
31
32
/**
33
* Helper class for using MongoDB in tests
34
*/
35
class
MongoTestHelper
36
{
37
public
:
38
MongoTestHelper
() :
cmake
(
"MemoryX"
)
39
{
40
// stopMongo();
41
startMongo
();
42
}
43
44
~MongoTestHelper
()
45
{
46
// stopMongo();
47
}
48
49
void
50
startMongo
()
51
{
52
std::string memoryXDir = armarx::test::getCmakeValue(
"MemoryX_BINARY_DIR"
);
53
memoryXDir =
cmake
.getBinaryDir();
54
sleep(1);
55
std::string command = memoryXDir +
"/mongod.sh assureRunning"
;
56
exec
(command);
57
}
58
59
void
60
stopMongo
()
61
{
62
63
std::string memoryXDir = armarx::test::getCmakeValue(
"MemoryX_BINARY_DIR"
);
64
memoryXDir =
cmake
.getBinaryDir();
65
std::string command = memoryXDir +
"/mongod.sh stop"
;
66
exec
(command);
67
}
68
69
protected
:
70
void
71
exec
(
const
std::string& command)
72
{
73
std::cout <<
"Executing command: "
<< command << std::endl;
74
if
(system(command.c_str()))
75
{
76
std::cout <<
"Executing command '"
<< command <<
"' failed"
<< std::endl;
77
throw
std::runtime_error{
"Executing command '"
+ command +
"' failed"
};
78
}
79
}
80
81
armarx::CMakePackageFinder
cmake
;
82
};
CMakePackageFinder.h
MongoTestHelper::startMongo
void startMongo()
Definition
MongoTestHelper.h:50
MongoTestHelper::MongoTestHelper
MongoTestHelper()
Definition
MongoTestHelper.h:38
MongoTestHelper::stopMongo
void stopMongo()
Definition
MongoTestHelper.h:60
MongoTestHelper::exec
void exec(const std::string &command)
Definition
MongoTestHelper.h:71
MongoTestHelper::cmake
armarx::CMakePackageFinder cmake
Definition
MongoTestHelper.h:81
MongoTestHelper::~MongoTestHelper
~MongoTestHelper()
Definition
MongoTestHelper.h:44
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition
CMakePackageFinder.h:53
MemoryX
core
MongoTestHelper.h
Generated by
1.13.2