NAME

OPCUA::Open62541::Test::Server - run open62541 server for testing

SYNOPSIS

use OPCUA::Open62541::Test::Server;
use Test::More tests => OPCUA::Open62541::Test::Server::planning();

my $server = OPCUA::Open62541::Test::Server->new();

DESCRIPTION

In a module test start and run an open62541 OPC UA server in the background that can be connected by a client. The server is considered part of the test and will write to the TAP stream.

OPCUA::Open62541::Test::Server::planning

Return the number of tests results that running one server will create. Add this to your number of planned tests.

OPCUA::Open62541::Test::Server::planning_nofork

Similar to planning, but to used for non-foring tests that do not call run() and stop().

METHODS

$server = OPCUA::Open62541::Test::Server->new(%args);

Create a new test server instance.

$args{actions}

Array of CODE refs with predefined actions that can be executed during runtime. The CODE refs will get called with the Server object of the child process as an argument.

$args{certificate}

Certificate in DER format for signing and encryption. If certificate and privateKey are set, the server config will be configured with the relevant security policies.

$args{privateKey}

Private key in DER format that has to match the certificate.

$args{trustList}

Array reference with a list of trusted certificates in PEM or DER format.

$args{issuerList}

Array reference with a list of additional trusted certificates in PEM or DER format.

$args{revocationList}

Array reference with a list of certificate revocation lists (CRL) in PEM or DER format.

$args{logfile}

Logs to the specified file instead of "server.log" in the current directory.

$args{timeout}

Maximum time the server will run before shutting down itself. Defaults to 10 seconds. Can be turned off with 0, but this should not be used in automatic tests to avoid dangling processes.

$args{singlestep}

If set, we pause before calling run_iterate(). To iterate, the test has to call step() to signal the server to continue.

DESTROY

Will reap the server process if it is still running. Better call stop() to shutdown the server and check its exit code.

$server->port($port)

Optionally set the port number. If port is not given, returns the dynamically chosen port number of the server. Must be called after start() for that.

$server->start()

Configure the server.

%nodes = $server->setup_complex_objects($namespace)

Adds the following nodes in the given namespace to the server:

some_object_0
| HasTypeDefinition
some_object_type
| HasComponent
some_variable_0
| HasTypeDefinition
some_variable_type

The namespace defaults to 1 if it is not passed as an argument.

Returns the definitions for each node as a hash ref with the above names as hash keys. Each definition has the hashes used to add the node (nodeId, parentNodeId, referenceTypeId, browseName, attributes and the typeDefinition depending on the node class).

$server->delete_complex_objects(%nodes)

Delete the nodes that were added with setup_complex_objects().

$server->step()

Will let the server continue and call run_iterate() if started with singlestep.

$server->run()

Startup the open62541 server as a background process. The function will return immediately.

$server->next_action()

Will execute the next predefined action in the server. The child process with the server will die if no more actions are defined.

$server->stop()

Stop the background server and check its exit code.

SEE ALSO

OPCUA::Open62541, OPCUA::Open62541::Test::Client, OPCUA::Open62541::Test::Logger

AUTHORS

Alexander Bluhm <bluhm@genua.de>, Anton Borowka

COPYRIGHT AND LICENSE

Copyright (c) 2020-2023 Alexander Bluhm

Copyright (c) 2020-2023 Anton Borowka

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Thanks to genua GmbH, https://www.genua.de/ for sponsoring this work.