opcua_protocol_addon_test.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "opcua_protocol_addon_test.h"
00012 
00013 #include <opc/common/addons_core/addon_manager.h>
00014 #include <opc/ua/client/remote_connection.h>
00015 #include "builtin_server_addon.h"
00016 #include "builtin_server.h"
00017 
00018 #include <opc/ua/server/addons/opcua_protocol.h>
00019 #include "address_space_registry_test.h"
00020 #include "endpoints_services_test.h"
00021 #include "services_registry_test.h"
00022 #include "standard_namespace_test.h"
00023 #include "builtin_server_test.h"
00024 
00025 #include <gmock/gmock.h>
00026 #include <gtest/gtest.h>
00027 #include <iostream>
00028 #include <thread>
00029 
00030 using namespace testing;
00031 
00032 class OpcUaProtocolAddonTest : public Test
00033 {
00034 public:
00035   void SetUp()
00036   {
00037     Addons = Common::CreateAddonsManager();
00038 
00039     OpcUa::Test::RegisterServicesRegistry(*Addons);
00040     OpcUa::Test::RegisterAddressSpace(*Addons);
00041     OpcUa::Test::RegisterStandardNamespace(*Addons);
00042     OpcUa::Test::RegisterBuiltinServerAddon(*Addons);
00043     //OpcUa::Test::RegisterOpcTcpAddon(*Addons);
00044     OpcUa::Test::RegisterEndpointsServicesAddon(*Addons);
00045     Addons->Register(OpcUa::Server::CreateSubscriptionServiceAddon());
00046     Addons->Register(OpcUa::Server::CreateAsioAddon());
00047     Addons->Start();
00048   }
00049 
00050   void TearDown()
00051   {
00052     Addons->Stop();
00053     Addons.reset();
00054   }
00055 
00056 protected:
00057   std::unique_ptr<Common::AddonsManager> Addons;
00058 };
00059 
00060 TEST_F(OpcUaProtocolAddonTest, Loads)
00061 {
00062   ASSERT_TRUE(static_cast<bool>(Addons->GetAddon(OpcUa::Server::OpcUaProtocolAddonId)));
00063 }
00064 
00065 TEST_F(OpcUaProtocolAddonTest, CanGetServerWhichOpensAndClosesSecureChannel)
00066 {
00067   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00068   ASSERT_TRUE(static_cast<bool>(computerAddon));
00069   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00070   ASSERT_TRUE(static_cast<bool>(computer));
00071   computer.reset();
00072 }
00073 
00074 TEST_F(OpcUaProtocolAddonTest, CanListEndpoints)
00075 {
00076   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00077   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00078   std::shared_ptr<OpcUa::EndpointServices> endpoints = computer->Endpoints();
00079   std::vector<OpcUa::EndpointDescription> desc;
00080   ASSERT_NO_THROW(desc = endpoints->GetEndpoints(OpcUa::GetEndpointsParameters()));
00081   ASSERT_EQ(desc.size(), 1);
00082   endpoints.reset();
00083   computer.reset();
00084 }
00085 
00086 TEST_F(OpcUaProtocolAddonTest, CanFindServers)
00087 {
00088   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00089   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00090   std::shared_ptr<OpcUa::EndpointServices> endpoints = computer->Endpoints();
00091   std::vector<OpcUa::ApplicationDescription> servers;
00092   ASSERT_NO_THROW(servers = endpoints->FindServers(OpcUa::FindServersParameters()));
00093   ASSERT_EQ(servers.size(), 1);
00094   endpoints.reset();
00095   computer.reset();
00096 }
00097 
00098 TEST_F(OpcUaProtocolAddonTest, CanBrowseRootFolder)
00099 {
00100   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00101   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00102   std::shared_ptr<OpcUa::ViewServices> views = computer->Views();
00103 
00104   OpcUa::BrowseDescription description;
00105   description.NodeToBrowse = OpcUa::ObjectId::RootFolder;
00106   description.Direction = OpcUa::BrowseDirection::Forward;
00107   description.ReferenceTypeId = OpcUa::ReferenceId::Organizes;
00108   description.IncludeSubtypes = true;
00109   description.NodeClasses = OpcUa::NodeClass::Object;
00110   description.ResultMask = OpcUa::BrowseResultMask::All;
00111   OpcUa::NodesQuery query;
00112   query.NodesToBrowse.push_back(description);
00113 
00114   std::vector<OpcUa::BrowseResult> results = views->Browse(query);
00115   ASSERT_EQ(results.size(), 1);
00116   ASSERT_EQ(results[0].Referencies.size(), 3);
00117 
00118   views.reset();
00119   computer.reset();
00120 }
00121 
00122 TEST_F(OpcUaProtocolAddonTest, CanCreateSession)
00123 {
00124   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00125   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00126 
00127   OpcUa::RemoteSessionParameters session;
00128   session.ClientDescription.ApplicationName.Text = "opcua client";
00129   session.SessionName = "opua command line";
00130   session.EndpointUrl = "opc.tcp://localhost:4841";
00131   session.Timeout = 1000;
00132 
00133   OpcUa::ActivateSessionParameters session_parameters;
00134 
00135   ASSERT_NO_THROW(computer->CreateSession(session));
00136   ASSERT_NO_THROW(computer->ActivateSession(session_parameters));
00137   ASSERT_NO_THROW(computer->CloseSession());
00138 
00139   computer.reset();
00140 }
00141 
00142 TEST_F(OpcUaProtocolAddonTest, ManipulateSubscriptions)
00143 {
00144   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00145   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00146   std::shared_ptr<OpcUa::SubscriptionServices> subscriptions = computer->Subscriptions();
00147 
00148   OpcUa::CreateSubscriptionParameters params;
00149   params.MaxNotificationsPerPublish = 3;
00150   params.Priority = 0;
00151   params.PublishingEnabled = true;
00152   params.RequestedLifetimeCount = 3;
00153   params.RequestedMaxKeepAliveCount = 3;
00154   params.RequestedPublishingInterval = 1000;
00155 
00156 
00157   OpcUa::CreateSubscriptionRequest req;
00158   req.Parameters = params;
00159   OpcUa::SubscriptionData data;
00160   ASSERT_NO_THROW(data = subscriptions->CreateSubscription(req, [](OpcUa::PublishResult){
00161 
00162   }));
00163 
00164   subscriptions.reset();
00165   computer.reset();
00166 }
00167 
00168 TEST_F(OpcUaProtocolAddonTest, CanReadAttributes)
00169 {
00170   std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
00171   std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
00172   std::shared_ptr<OpcUa::AttributeServices> attributes = computer->Attributes();
00173 
00174   OpcUa::ReadParameters params;
00175   params.AttributesToRead.push_back(OpcUa::ToReadValueId(OpcUa::ObjectId::RootFolder, OpcUa::AttributeId::BrowseName));
00176 
00177   std::vector<OpcUa::DataValue> values = attributes->Read(params);
00178   ASSERT_EQ(values.size(), 1);
00179 
00180   attributes.reset();
00181   computer.reset();
00182 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:56