endpoints_services_test.cpp
Go to the documentation of this file.
1 
12 #include "services_registry_test.h"
13 
15 #include <opc/common/logger.h>
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 
21 
22 using namespace testing;
23 
24 class EndpointsRegistry : public Test
25 {
26 protected:
27  virtual void SetUp()
28  {
30  Logger = spdlog::stderr_color_mt("test");
31  Logger->set_level(spdlog::level::info);
32  Addons = Common::CreateAddonsManager(Logger);
35  Addons->Start();
36  }
37 
38  virtual void TearDown()
39  {
40  Addons->Stop();
41  Addons.reset();
42  }
43 
44 protected:
45  Common::Logger::SharedPtr Logger;
46  std::unique_ptr<Common::AddonsManager> Addons;
47 };
48 
49 TEST_F(EndpointsRegistry, CanBeCreated)
50 {
51  OpcUa::Server::EndpointsRegistry::SharedPtr endpoints;
52 
54  ASSERT_TRUE(static_cast<bool>(endpoints));
55 }
56 
57 TEST_F(EndpointsRegistry, RegisterEndpoints)
58 {
60  desc.EndpointUrl = "url";
61 
62  OpcUa::Server::EndpointsRegistry::SharedPtr endpoints = Addons->GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId);
63  endpoints->AddEndpoints(std::vector<OpcUa::EndpointDescription>(1, desc));
64 
65  OpcUa::Server::ServicesRegistry::SharedPtr services = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
66  OpcUa::Services::SharedPtr computer = services->GetServer();
67  std::vector<OpcUa::EndpointDescription> descriptions;
68  ASSERT_NO_THROW(descriptions = computer->Endpoints()->GetEndpoints(OpcUa::GetEndpointsParameters()));
69  ASSERT_EQ(descriptions.size(), 1);
70  ASSERT_EQ(descriptions[0].EndpointUrl, "url");
71 }
72 
73 std::vector<Common::ParametersGroup> CreateTwoEndpointsParameters()
74 {
76  data.Name = "application";
77  data.Parameters.push_back(Common::Parameter("discovery_profile", "DiscoveryProfileUri"));
78  data.Parameters.push_back(Common::Parameter("uri", "ApplicationUri"));
79  data.Parameters.push_back(Common::Parameter("product_uri", "ProductUri"));
80  data.Parameters.push_back(Common::Parameter("gateway_server_uri", "GatewayServerUri"));
81  data.Parameters.push_back(Common::Parameter("name", "ApplicationName"));
82  data.Parameters.push_back(Common::Parameter("type", "ApplicationType"));
83 
84  Common::ParametersGroup endpoint("endpoint");
85  endpoint.Parameters.push_back(Common::Parameter("url", "EndpointUrl"));
86  endpoint.Parameters.push_back(Common::Parameter("security_level", "1"));
87  endpoint.Parameters.push_back(Common::Parameter("security_mode", "3"));
88  endpoint.Parameters.push_back(Common::Parameter("security_policy_uri", "SecurityPolicyUri"));
89  endpoint.Parameters.push_back(Common::Parameter("transport_profile_uri", "TransportProfileUri"));
90 
91  Common::ParametersGroup tokenPolicy("user_token_policy");
92  tokenPolicy.Parameters.push_back(Common::Parameter("issued_token_type", "IssuedTokenType"));
93  tokenPolicy.Parameters.push_back(Common::Parameter("issuer_endpoint_url", "IssuerEndpointUrl"));
94  tokenPolicy.Parameters.push_back(Common::Parameter("id", "PolicyId"));
95  tokenPolicy.Parameters.push_back(Common::Parameter("uri", "SecurityPolicyUri"));
96  tokenPolicy.Parameters.push_back(Common::Parameter("type", "user_name"));
97 
98  endpoint.Groups.push_back(tokenPolicy);
99  data.Groups.push_back(endpoint);
100 
101  return std::vector<Common::ParametersGroup> {data, data};
102 }
103 
104 std::vector<OpcUa::Server::ApplicationData> CreateTwoEndpointsConfiguration()
105 {
107  data.Application.DiscoveryProfileUri = "DiscoveryProfileUri";
108  data.Application.ApplicationUri = "ApplicationUri";
109  data.Application.ProductUri = "ProductUri";
110  data.Application.GatewayServerUri = "GatewayServerUri";
113 
115  ed.EndpointUrl = "EndpointUrl";
116  ed.SecurityLevel = 1;
118  ed.SecurityPolicyUri = "SecurityPolicyUri";
119  ed.TransportProfileUri = "TransportProfileUri";
120 
121  OpcUa::UserTokenPolicy tokenPolicy; // By default ot os an anonimous token;
122  tokenPolicy.IssuedTokenType = "IssuedTokenType";
123  tokenPolicy.IssuerEndpointUrl = "IssuerEndpointUrl";
124  tokenPolicy.PolicyId = "PolicyId";
125  tokenPolicy.SecurityPolicyUri = "SecurityPolicyUri";
127  ed.UserIdentityTokens.push_back(tokenPolicy);
128 
129  data.Endpoints = {ed};
130 
131  return std::vector<OpcUa::Server::ApplicationData> {data, data};
132 }
133 
135 {
136  auto paramIt = std::find_if(group.Parameters.begin(), group.Parameters.end(), [name](const Common::Parameter & param)
137  {
138  return param.Name == name;
139  });
140 
141  if (paramIt != group.Parameters.end())
142  {
143  return *paramIt;
144  }
145 
146  return Common::Parameter();
147 }
148 
149 // TEST(EndpointParameters, ConvertingFromAddonParameters)
150 // {
151 // std::vector<Common::ParametersGroup> params = CreateTwoEndpointsParameters();
152 // bool debug = true;
153 // std::vector<OpcUa::Server::ApplicationData> apps = OpcUa::ParseEndpointsParameters(params, debug);
154 // ASSERT_EQ(apps.size(), 2);
155 // OpcUa::Server::ApplicationData app = apps[0];
156 // EXPECT_EQ(app.Application.DiscoveryProfileUri, "DiscoveryProfileUri");
157 // EXPECT_EQ(app.Application.ApplicationUri, "ApplicationUri");
158 // EXPECT_EQ(app.Application.ProductUri, "ProductUri");
159 // EXPECT_TRUE(app.Application.ApplicationName.Encoding & OpcUa::HAS_TEXT);
160 // EXPECT_EQ(app.Application.ApplicationName.Text, "ApplicationName");
161 // EXPECT_EQ(app.Application.ApplicationType, OpcUa::ApplicationType::Client);
162 // EXPECT_EQ(app.Application.GatewayServerUri, "GatewayServerUri");
163 //
164 // ASSERT_EQ(app.Endpoints.size(), 1);
165 // OpcUa::EndpointDescription ed = app.Endpoints[0];
166 // EXPECT_EQ(ed.EndpointUrl, "EndpointUrl");
167 // EXPECT_EQ(ed.SecurityLevel, 1);
168 // EXPECT_EQ(ed.SecurityMode, OpcUa::MessageSecurityMode::SignAndEncrypt);
169 // EXPECT_EQ(ed.SecurityPolicyUri, "SecurityPolicyUri");
170 // //EXPECT_EQ(ed.ServerCertificate, std::vector{1,2,3,4,5});
171 // //EXPECT_EQ(ed.ServerDescription, "SecurityPolicyUri");
172 // EXPECT_EQ(ed.TransportProfileUri, "TransportProfileUri");
173 //
174 // ASSERT_EQ(ed.UserIdentityTokens.size(), 1);
175 // OpcUa::UserTokenPolicy tokenPolicy = ed.UserIdentityTokens[0];
176 // EXPECT_EQ(tokenPolicy.IssuedTokenType, "IssuedTokenType");
177 // EXPECT_EQ(tokenPolicy.IssuerEndpointUrl, "IssuerEndpointUrl");
178 // EXPECT_EQ(tokenPolicy.PolicyId, "PolicyId");
179 // EXPECT_EQ(tokenPolicy.SecurityPolicyUri, "SecurityPolicyUri");
180 // EXPECT_EQ(tokenPolicy.TokenType, OpcUa::UserTokenType::UserName);
181 // }
182 
183 // TEST(EndpointParameters, ConvertingToAddonParameters)
184 // {
185 // const std::vector<OpcUa::Server::ApplicationData>& application = CreateTwoEndpointsConfiguration();
186 // bool debug = true;
187 // const std::vector<Common::ParametersGroup>& result = OpcUa::CreateCommonParameters(application, debug);
188 // ASSERT_EQ(result.size(), 2);
189 // const Common::ParametersGroup applicationGroup = result[0];
190 // EXPECT_EQ(applicationGroup.Name, "application");
191 // EXPECT_EQ(FindParameter(applicationGroup, "discovery_profile").Value, "DiscoveryProfileUri");
192 // EXPECT_EQ(FindParameter(applicationGroup, "product_uri").Value, "ProductUri");
193 // EXPECT_EQ(FindParameter(applicationGroup, "application_uri").Value, "ApplicationUri");
194 // EXPECT_EQ(FindParameter(applicationGroup, "application_name").Value, "ApplicationName");
195 // EXPECT_EQ(FindParameter(applicationGroup, "Application_type").Value, "client");
196 // EXPECT_EQ(FindParameter(applicationGroup, "gateway_server_uri").Value, "GatewayServerUri");
197 //
198 // ASSERT_EQ(applicationGroup.Groups.size(), 1) << "Application group has no subgroups with endpoints";
199 // Common::ParametersGroup endpoint = applicationGroup.Groups[0];
200 // EXPECT_EQ(endpoint.Name, "endpoint");
201 // EXPECT_EQ(FindParameter(endpoint, "endpoint_url").Value, "EndpointUrl");
202 // EXPECT_EQ(FindParameter(endpoint, "security_level").Value, "1");
203 // EXPECT_EQ(FindParameter(endpoint, "security_mode").Value, "3");
204 // EXPECT_EQ(FindParameter(endpoint, "security_policy_uri").Value, "SecurityPolicyUri");
205 // //EXPECT_EQ(FindParameter(endpoint, "server_certificate").Value, "SecurityPolicyUri");
206 // EXPECT_EQ(FindParameter(endpoint, "transport_profile_uri").Value, "TransportProfileUri");
207 //
208 // ASSERT_EQ(endpoint.Groups.size(), 1);
209 // Common::ParametersGroup tokenPolicy = endpoint.Groups[0];
210 // EXPECT_EQ(tokenPolicy.Name, "user_token_policy");
211 // EXPECT_EQ(FindParameter(tokenPolicy, "issued_token_type").Value, "IssuedTokenType");
212 // EXPECT_EQ(FindParameter(tokenPolicy, "issuer_endpoint_url").Value, "IssuerEndpointUrl");
213 // EXPECT_EQ(FindParameter(tokenPolicy, "id").Value, "PolicyId");
214 // EXPECT_EQ(FindParameter(tokenPolicy, "id").Value, "PolicyId");
215 // EXPECT_EQ(FindParameter(tokenPolicy, "uri").Value, "SecurityPolicyUri");
216 // EXPECT_EQ(FindParameter(tokenPolicy, "type").Value, "user_name");
217 // }
std::vector< OpcUa::Server::ApplicationData > CreateTwoEndpointsConfiguration()
Common::Logger::SharedPtr Logger
ApplicationDescription Application
bool param(const std::string &param_name, T &param_val, const T &default_val)
std::vector< OpcUa::UserTokenPolicy > UserIdentityTokens
const char EndpointsRegistryAddonId[]
std::string SecurityPolicyUri
std::vector< Parameter > Parameters
Common::Parameter FindParameter(const Common::ParametersGroup &group, const char *name)
TEST_F(TestInfoTest, Names)
std::vector< ParametersGroup > Groups
std::vector< EndpointDescription > Endpoints
std::string IssuedTokenType
const char ServicesRegistryAddonId[]
name
Definition: setup.py:38
virtual void AddEndpoints(const std::vector< EndpointDescription > &endpoints)=0
OpcUa::ApplicationType ApplicationType
std::unique_ptr< Common::AddonsManager > Addons
AddonsManager::UniquePtr CreateAddonsManager(const Common::Logger::SharedPtr &logger)
Get instance of addons core.
void RegisterServicesRegistry(Common::AddonsManager &addons)
OpcUa::MessageSecurityMode SecurityMode
#define ASSERT_NO_THROW(statement)
std::vector< Common::ParametersGroup > CreateTwoEndpointsParameters()
#define ASSERT_TRUE(condition)
#define ASSERT_EQ(val1, val2)
OpcUa::LocalizedText ApplicationName
void RegisterEndpointsServicesAddon(Common::AddonsManager &addons)
OpcUa::UserTokenType TokenType
std::string IssuerEndpointUrl
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)
Definition: spdlog_impl.h:150
computer
Definition: test.py:6
void drop_all()
Definition: spdlog_impl.h:260


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:04