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 <memory>
26 #include <map>
27 #include <stdexcept>
28 #include <cstdlib>
30 
31 
32 /**
33 * Helper class for using MongoDB in tests
34 */
36 {
37 public:
39  cmake("MemoryX")
40  {
41  // stopMongo();
42  startMongo();
43  }
44 
46  {
47  // stopMongo();
48  }
49 
50  void 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 stopMongo()
60  {
61 
62  std::string memoryXDir = armarx::test::getCmakeValue("MemoryX_BINARY_DIR");
63  memoryXDir = cmake.getBinaryDir();
64  std::string command = memoryXDir + "/mongod.sh stop";
65  exec(command);
66  }
67 
68 protected:
69  void exec(const std::string& command)
70  {
71  std::cout << "Executing command: " << command << std::endl;
72  if (system(command.c_str()))
73  {
74  std::cout << "Executing command '" << command << "' failed" << std::endl;
75  throw std::runtime_error {"Executing command '" + command + "' failed"};
76  }
77  }
79 };
80 
MongoTestHelper::stopMongo
void stopMongo()
Definition: MongoTestHelper.h:59
MongoTestHelper
Helper class for using MongoDB in tests.
Definition: MongoTestHelper.h:35
MongoTestHelper::~MongoTestHelper
~MongoTestHelper()
Definition: MongoTestHelper.h:45
MongoTestHelper::startMongo
void startMongo()
Definition: MongoTestHelper.h:50
MongoTestHelper::MongoTestHelper
MongoTestHelper()
Definition: MongoTestHelper.h:38
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
armarx::CMakePackageFinder::getBinaryDir
std::string getBinaryDir() const
Definition: CMakePackageFinder.h:159
MongoTestHelper::exec
void exec(const std::string &command)
Definition: MongoTestHelper.h:69
CMakePackageFinder.h
MongoTestHelper::cmake
armarx::CMakePackageFinder cmake
Definition: MongoTestHelper.h:78