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
31
32/**
33* Helper class for using MongoDB in tests
34*/
36{
37public:
38 MongoTestHelper() : cmake("MemoryX")
39 {
40 // stopMongo();
41 startMongo();
42 }
43
45 {
46 // stopMongo();
47 }
48
49 void
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
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
69protected:
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
82};
void exec(const std::string &command)
armarx::CMakePackageFinder cmake
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.