Documentation for OpenFLUID 2.2.1
HubTestFixture.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2021-2026, INRAE
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  openfluid::ui::waresdev::forceRemove(TestWorkspacePath.toStdString());
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  openfluid::ui::waresdev::forceRemove(TestWorkspacePath.toStdString());
91  openfluid::base::WorkspaceManager::kill();
92  }
93 
95  {
98 
99  if (Wares.empty())
100  {
101  return "";
102  }
103 
104  for (const auto& Ware : Wares)
105  {
106  std::vector<std::string> Branches = Ware.second.GitBranches;
107 
108  if (std::find(Branches.begin(), Branches.end(), CurrentOFBranchName) != Branches.end())
109  {
110  QString Url = QString::fromStdString(Ware.second.GitUrl);
111 
112  FirstAvailSimId = QString::fromStdString(Ware.first);
113 
114  return Url;
115  }
116  }
117 
118  return "";
119  }
120 
121  static bool checkHttps(const std::string& TestName, int version=0)
122  {
123  QString UrlHttps;
124  if (version == 0)
125  {
126  UrlHttps = UrlHttpsV0;
127  }
128  else
129  {
130  UrlHttps = UrlHttpsV1;
131  }
132  if (!UrlHttps.isEmpty())
133  {
134  return true;
135  }
136 
137  std::cout << "** Test not run due to empty wareshub https url ** (\"" << TestName << "\")" << std::endl;
138 
139  return false;
140  }
141 };
142 
143 const QString HubTestFixture::UrlHttpV0 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V0_URL_HTTP);
144 const QString HubTestFixture::UrlHttpsV0 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V0_URL_HTTPS);
145 const QString HubTestFixture::UrlHttpsV0Redirect = QString::fromStdString(CONFIGTESTS_WARESHUB_URL_REDIRECT_HTTPS);
146 const QString HubTestFixture::UrlHttpV1 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V1_URL_HTTP);
147 const QString HubTestFixture::UrlHttpsV1 = QString::fromStdString(CONFIGTESTS_FLUIDHUB_V1_URL_HTTPS);
148 
149 const QString HubTestFixture::Username = QString::fromStdString(CONFIGTESTS_WARESHUB_USERNAME);
150 const QString HubTestFixture::Password = QString::fromStdString(CONFIGTESTS_WARESHUB_PASSWORD);
151 
152 #endif /* __OPENFLUID_UIWARESDEVTESTS_HUBTESTFIXTURE_HPP__ */
Definition: HubTestFixture.hpp:49
HubTestFixture()
Definition: HubTestFixture.hpp:70
static const QString UrlHttpsV0
Definition: HubTestFixture.hpp:61
~HubTestFixture()
Definition: HubTestFixture.hpp:88
QString getFirstAvailSimUrl(openfluid::ui::waresdev::HubManager &W)
Definition: HubTestFixture.hpp:94
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:121
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
bool OPENFLUID_API forceRemove(const std::string &Path)