Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "endpoints_services_test.h"
00012 #include "services_registry_test.h"
00013
00014 #include <src/server/endpoints_parameters.h>
00015 #include <opc/ua/protocol/session.h>
00016 #include <opc/ua/server/endpoints_services.h>
00017 #include <gmock/gmock.h>
00018 #include <gtest/gtest.h>
00019
00020
00021 using namespace testing;
00022
00023 class EndpointsRegistry :public Test
00024 {
00025 protected:
00026 virtual void SetUp()
00027 {
00028 Addons = Common::CreateAddonsManager();
00029 OpcUa::Test::RegisterServicesRegistry(*Addons);
00030 OpcUa::Test::RegisterEndpointsServicesAddon(*Addons);
00031 Addons->Start();
00032 }
00033
00034 virtual void TearDown()
00035 {
00036 Addons->Stop();
00037 Addons.reset();
00038 }
00039
00040 protected:
00041 std::unique_ptr<Common::AddonsManager> Addons;
00042 };
00043
00044 TEST_F(EndpointsRegistry, CanBeCreated)
00045 {
00046 OpcUa::Server::EndpointsRegistry::SharedPtr endpoints;
00047
00048 ASSERT_NO_THROW(endpoints = Addons->GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId));
00049 ASSERT_TRUE(static_cast<bool>(endpoints));
00050 }
00051
00052 TEST_F(EndpointsRegistry, RegisterEndpoints)
00053 {
00054 OpcUa::EndpointDescription desc;
00055 desc.EndpointUrl = "url";
00056
00057 OpcUa::Server::EndpointsRegistry::SharedPtr endpoints = Addons->GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId);
00058 endpoints->AddEndpoints(std::vector<OpcUa::EndpointDescription>(1, desc));
00059
00060 OpcUa::Server::ServicesRegistry::SharedPtr services = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
00061 OpcUa::Services::SharedPtr computer = services->GetServer();
00062 std::vector<OpcUa::EndpointDescription> descriptions;
00063 ASSERT_NO_THROW(descriptions = computer->Endpoints()->GetEndpoints(OpcUa::GetEndpointsParameters()));
00064 ASSERT_EQ(descriptions.size(), 1);
00065 ASSERT_EQ(descriptions[0].EndpointUrl, "url");
00066 }
00067
00068 std::vector<Common::ParametersGroup> CreateTwoEndpointsParameters()
00069 {
00070 Common::ParametersGroup data;
00071 data.Name = "application";
00072 data.Parameters.push_back(Common::Parameter("discovery_profile", "DiscoveryProfileUri"));
00073 data.Parameters.push_back(Common::Parameter("uri", "ApplicationUri"));
00074 data.Parameters.push_back(Common::Parameter("product_uri", "ProductUri"));
00075 data.Parameters.push_back(Common::Parameter("gateway_server_uri", "GatewayServerUri"));
00076 data.Parameters.push_back(Common::Parameter("name", "ApplicationName"));
00077 data.Parameters.push_back(Common::Parameter("type", "ApplicationType"));
00078
00079 Common::ParametersGroup endpoint("endpoint");
00080 endpoint.Parameters.push_back(Common::Parameter("url", "EndpointUrl"));
00081 endpoint.Parameters.push_back(Common::Parameter("security_level", "1"));
00082 endpoint.Parameters.push_back(Common::Parameter("security_mode", "3"));
00083 endpoint.Parameters.push_back(Common::Parameter("security_policy_uri", "SecurityPolicyUri"));
00084 endpoint.Parameters.push_back(Common::Parameter("transport_profile_uri", "TransportProfileUri"));
00085
00086 Common::ParametersGroup tokenPolicy("user_token_policy");
00087 tokenPolicy.Parameters.push_back(Common::Parameter("issued_token_type", "IssuedTokenType"));
00088 tokenPolicy.Parameters.push_back(Common::Parameter("issuer_endpoint_url", "IssuerEndpointUrl"));
00089 tokenPolicy.Parameters.push_back(Common::Parameter("id", "PolicyId"));
00090 tokenPolicy.Parameters.push_back(Common::Parameter("uri", "SecurityPolicyUri"));
00091 tokenPolicy.Parameters.push_back(Common::Parameter("type", "user_name"));
00092
00093 endpoint.Groups.push_back(tokenPolicy);
00094 data.Groups.push_back(endpoint);
00095
00096 return std::vector<Common::ParametersGroup>{data, data};
00097 }
00098
00099 std::vector<OpcUa::Server::ApplicationData> CreateTwoEndpointsConfiguration()
00100 {
00101 OpcUa::Server::ApplicationData data;
00102 data.Application.DiscoveryProfileUri = "DiscoveryProfileUri";
00103 data.Application.ApplicationUri = "ApplicationUri";
00104 data.Application.ProductUri = "ProductUri";
00105 data.Application.GatewayServerUri = "GatewayServerUri";
00106 data.Application.ApplicationName = OpcUa::LocalizedText("Name");
00107 data.Application.ApplicationType = OpcUa::ApplicationType::Client;
00108
00109 OpcUa::EndpointDescription ed;
00110 ed.EndpointUrl = "EndpointUrl";
00111 ed.SecurityLevel = 1;
00112 ed.SecurityMode = OpcUa::MessageSecurityMode::SignAndEncrypt;
00113 ed.SecurityPolicyUri = "SecurityPolicyUri";
00114 ed.TransportProfileUri = "TransportProfileUri";
00115
00116 OpcUa::UserTokenPolicy tokenPolicy;
00117 tokenPolicy.IssuedTokenType = "IssuedTokenType";
00118 tokenPolicy.IssuerEndpointUrl = "IssuerEndpointUrl";
00119 tokenPolicy.PolicyId = "PolicyId";
00120 tokenPolicy.SecurityPolicyUri = "SecurityPolicyUri";
00121 tokenPolicy.TokenType = OpcUa::UserTokenType::UserName;
00122 ed.UserIdentityTokens.push_back(tokenPolicy);
00123
00124 data.Endpoints = {ed};
00125
00126 return std::vector<OpcUa::Server::ApplicationData>{data, data};
00127 }
00128
00129 Common::Parameter FindParameter(const Common::ParametersGroup& group, const char* name)
00130 {
00131 auto paramIt = std::find_if(group.Parameters.begin(), group.Parameters.end(), [name](const Common::Parameter& param){
00132 return param.Name == name;
00133 });
00134
00135 if (paramIt != group.Parameters.end())
00136 {
00137 return *paramIt;
00138 }
00139 return Common::Parameter();
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210