Newer
Older
function test_suite=test_caosdb()
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end
%% Only test the connection
% Default connection
c1 = Caosdb();
info = c1.info();
% another working connection
c2 = Caosdb(connection = "local-caosdb-admin");
c2.info();
% This connection should fail
% c3 = Caosdb(connection = "does-not-exist");
% Error message is:
% maox_info: The ConnectionManager does not know any connection of this name.
% No connection named 'does-not-exist' present.
assertExceptionThrown(@non_existing_connection,"16");
expected_msg = ...
strjoin(
{"maox_info: The ConnectionManager does not know any connection of this name.",
"No connection named 'does-not-exist' present."}, "\n");
assertEqual(lasterror().message, expected_msg)
end
function info = non_existing_connection()
c = Caosdb(connection = "does-not-exist");
info = c.info();
%% Test retrieval of a single Entity
function test_retrieve_single()
% Default connection configuration is sufficient.
c = Caosdb();
% Retrieve a single entity
violin = c.retrieve("120"){1};
% Check content
assertEqual(violin.name, "Sherlock Holmes' violin");
assertEqual(props{1}.name, "price");
assertEqual(props{1}.value, 814873.0);
assertEqual(props{2}.name, "Manufacturer");
assertEqual(props{2}.value, "119");
assertFalse(violin.has_errors());
assertFalse(violin.has_warnings());
assertFalse(violin.has_infos());
end
%% Test retrieval of multiple Entities
function xfail_test_retrieve_multiple()
% Retrieve two entities
collection = c.retrieve({"120", "121"});
assertEqual(length(collection), 2);
assertEqual(collection(1), violin);
end