Documentation for OpenFLUID 2.2.0
HubTestFixture.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30  */
31 
32 /**
33  @file HubTestFixture.hpp
34 
35  @author Armel THONI <armel.thoni@inrae.fr>
36  */
37 
38 #ifndef __OPENFLUID_UIWARESDEVTESTS_HUBTESTFIXTURE_HPP__
39 #define __OPENFLUID_UIWARESDEVTESTS_HUBTESTFIXTURE_HPP__
40 
41 
42 #include <QCoreApplication>
43 #include <QDir>
44 
45 #include "tests-config.hpp"
46 
47 
49 {
50  private:
51 
52  QString TestWorkspacePath;
53 
54  public:
55 
57 
58  QString FirstAvailSimId;
59 
60  static const QString UrlHttpV0;
61  static const QString UrlHttpsV0;
62  static const QString UrlHttpsV0Redirect;
63  static const QString UrlHttpV1;
64  static const QString UrlHttpsV1;
65  static const QString Username;
66  static const QString Password;
67 
68  std::string CurrentOFBranchName;
69 
71  {
72  TestWorkspacePath = QString::fromStdString(CONFIGTESTS_OUTPUT_DATA_DIR);
73  TestWorkspacePath.append("/FluidHubWaresImport");
74 
75  forceRemove(TestWorkspacePath);
76 
77  auto Mgr = openfluid::base::WorkspaceManager::instance();
78 
79  Mgr->openWorkspace(TestWorkspacePath.toStdString());
80 
82  QString::fromStdString(Mgr->getWaresPath(openfluid::ware::WareType::SIMULATOR))
83  );
84 
86  }
87 
89  {
90  forceRemove(TestWorkspacePath);
91  openfluid::base::WorkspaceManager::kill();
92  }
93 
94  void forceRemove(const QString& Path)
95  {
96  QDir Dir(Path);
97 
98  for (const auto& SubFile : Dir.entryList(QDir::Files | QDir::System | QDir::Hidden))
99  {
100  QFile f(QString("%1/%2").arg(Path).arg(SubFile));
101  f.setPermissions(QFile::WriteUser);
102  f.remove();
103  }
104 
105  for (const auto& SubDir : Dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::System | QDir::Hidden))
106  {
107  forceRemove(QString("%1/%2").arg(Path).arg(SubDir));
108  }
109 
110  Dir.rmdir(Path);
111  }
112 
114  {
117 
118  if (Wares.empty())
119  {
120  return "";
121  }
122 
123  for (const auto& Ware : Wares)
124  {
125  std::vector<std::string> Branches = Ware.second.GitBranches;
126 
127  if (std::find(Branches.begin(), Branches.end(), CurrentOFBranchName) != Branches.end())
128  {
129  QString Url = QString::fromStdString(Ware.second.GitUrl);
130 
131  FirstAvailSimId = QString::fromStdString(Ware.first);
132 
133  return Url;
134  }
135  }
136 
137  return "";
138  }
139 
140  static bool checkHttps(const std::string& TestName, int version=0)
141  {
142  QString UrlHttps;
143  if (version == 0)
144  {
145  UrlHttps = UrlHttpsV0;
146  }
147  else
148  {
149  UrlHttps = UrlHttpsV1;
150  }
151  if (!UrlHttps.isEmpty())
152  {
153  return true;
154  }
155 
156  std::cout << "** Test not run due to empty wareshub https url ** (\"" << TestName << "\")" << std::endl;
157 
158  return false;
159  }
160 };
161 
162 const QString HubTestFixture::UrlHttpV0 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V0_URL_HTTP);
163 const QString HubTestFixture::UrlHttpsV0 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V0_URL_HTTPS);
164 const QString HubTestFixture::UrlHttpsV0Redirect = QString::fromStdString(CONFIGTESTS_WARESHUB_URL_REDIRECT_HTTPS);
165 const QString HubTestFixture::UrlHttpV1 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V1_URL_HTTP);
166 const QString HubTestFixture::UrlHttpsV1 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V1_URL_HTTPS);
167 
168 const QString HubTestFixture::Username = QString::fromStdString(CONFIGTESTS_WARESHUB_USERNAME);
169 const QString HubTestFixture::Password = QString::fromStdString(CONFIGTESTS_WARESHUB_PASSWORD);
170 
171 #endif /* __OPENFLUID_UIWARESDEVTESTS_HUBTESTFIXTURE_HPP__ */
Definition: HubTestFixture.hpp:49
HubTestFixture()
Definition: HubTestFixture.hpp:70
void forceRemove(const QString &Path)
Definition: HubTestFixture.hpp:94
static const QString UrlHttpsV0
Definition: HubTestFixture.hpp:61
~HubTestFixture()
Definition: HubTestFixture.hpp:88
QString getFirstAvailSimUrl(openfluid::ui::waresdev::HubManager &W)
Definition: HubTestFixture.hpp:113
static const QString Password
Definition: HubTestFixture.hpp:66
static const QString UrlHttpV0
Definition: HubTestFixture.hpp:60
static bool checkHttps(const std::string &TestName, int version=0)
Definition: HubTestFixture.hpp:140
static const QString UrlHttpsV1
Definition: HubTestFixture.hpp:64
QString FirstAvailSimId
Definition: HubTestFixture.hpp:58
static const QString Username
Definition: HubTestFixture.hpp:65
static const QString UrlHttpV1
Definition: HubTestFixture.hpp:63
QDir TestWaresDevSimulatorsDir
Definition: HubTestFixture.hpp:56
std::string CurrentOFBranchName
Definition: HubTestFixture.hpp:68
static const QString UrlHttpsV0Redirect
Definition: HubTestFixture.hpp:62
static QString getCurrentOpenFLUIDBranchName()
Definition: HubManager.hpp:53
openfluid::utils::FluidHubAPIClient::WaresDetailsByID_t getAvailableWaresWithDetails(openfluid::ware::WareType Type) const
std::map< openfluid::ware::WareID_t, WareDetailedDescription > WaresDetailsByID_t
Definition: FluidHubAPIClient.hpp:80
FilesystemPath Path
Definition: FilesystemPath.hpp:308