ifw-daq  3.0.1
IFW Data Acquisition modules
testJson.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_common_libdpm
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief Defines tests for JSON support
9  */
10 #include <gtest/gtest.h>
11 
12 #include <daq/json.hpp>
13 #include <daq/status.hpp>
14 
15 namespace daq {
16 
17 TEST(TestJson, SerializeStatus) {
18  Status orig = {};
19  orig.id = "ID";
20  orig.state = State::Acquiring;
21  orig.result = "file.fits";
22  ReceiverStatus& receiver = orig.receivers[1];
24 
25  nlohmann::json j = orig;
26  auto deserialized = j.get<Status>();
27 
28  EXPECT_EQ(orig, deserialized);
29  EXPECT_EQ(orig.id, deserialized.id);
30  EXPECT_EQ(orig.state, deserialized.state);
31  EXPECT_EQ(orig.receivers, deserialized.receivers);
32 }
33 
35  using namespace std::chrono_literals;
36  DaqContext ctx;
37  ctx.id = "ID";
38  ctx.await_interval = 5s;
39  ctx.file_id = "FILE_ID";
40  ctx.keywords.push_back(fits::ValueKeyword("FOO", "BAR"));
41  ctx.dp_name_prefix = "FOO";
42  ctx.meta_sources.push_back({"NAME", "URI"});
43 
44  nlohmann::json j = ctx;
45  auto deserialized = j.get<DaqContext>();
46 
47  EXPECT_TRUE(ctx == deserialized);
48  EXPECT_EQ(ctx.id, deserialized.id);
49  EXPECT_EQ(ctx.await_interval, deserialized.await_interval);
50 }
51 
52 TEST(TestJson, DaqContextWithSpecification) {
53  using namespace std::chrono_literals;
54  DaqContext ctx;
55  ctx.id = "ID";
56  ctx.await_interval = 5s;
57  ctx.file_id = "FILE_ID";
58  ctx.keywords.push_back(fits::ValueKeyword("FOO", "BAR"));
59  ctx.dp_name_prefix = "FOO";
60  ctx.meta_sources.push_back({"NAME", "URI"});
61  auto& spec = ctx.specification.emplace();
62  spec.file_prefix = "FOO";
64  ds1.rr_uri = "uri";
65  ds1.source_name = "prim";
67  ds2.rr_uri = "uri";
68  ds2.source_name = "meta";
69 
70  spec.sources.push_back(ds1);
71  spec.sources.push_back(ds2);
72 
73  nlohmann::json j = ctx;
74  auto deserialized = j.get<DaqContext>();
75 
76  EXPECT_TRUE(ctx == deserialized);
77  EXPECT_EQ(ctx.id, deserialized.id);
78  EXPECT_EQ(ctx.await_interval, deserialized.await_interval);
79  EXPECT_EQ(ctx.specification->file_prefix, deserialized.specification->file_prefix);
80  ASSERT_EQ(ctx.specification->sources.size(), 2u);
81  EXPECT_EQ(ctx.specification->sources[0], deserialized.specification->sources[0]);
82  EXPECT_EQ(ctx.specification->sources[1], deserialized.specification->sources[1]);
83 }
84 
85 } // namespace daq
Declares JSON support for serialization.
@ Acquiring
All data sources have reported data acquisition is in progress.
TEST(TestDaqContext, Files)
Contains declaration for Status and ObservableStatus.
Structure carrying context needed to start a Data Acquisition and construct a Data Product Specificat...
Definition: daqContext.hpp:44
std::vector< Source > meta_sources
Definition: daqContext.hpp:77
std::vector< daq::fits::KeywordVariant > keywords
Keyword list provided by OCM to Data Product.
Definition: daqContext.hpp:87
std::chrono::milliseconds await_interval
Interval (and thus duration) of the requests sent to primary sources to await end of recording.
Definition: daqContext.hpp:94
std::optional< json::StartDaqV2Spec > specification
Optional specification, if DAQ was started using StartDaqV2.
Definition: daqContext.hpp:116
std::string file_id
Data Product FileId as specified by OLAS ICD.
Definition: daqContext.hpp:65
std::string dp_name_prefix
Data product file name prefix.
Definition: daqContext.hpp:75
std::string id
DAQ identfier, possibly provided by user.
Definition: daqContext.hpp:60
Persistent status for receiver delivery.
Definition: status.hpp:134
Non observable status object that keeps stores status of data acquisition.
Definition: status.hpp:153
State state
Definition: status.hpp:176
std::string id
Definition: status.hpp:174
std::string result
Path to resulting data product.
Definition: status.hpp:193
std::map< std::size_t, ReceiverStatus > receivers
Receiver processing (e.g.
Definition: status.hpp:188
A type safe version of LiteralKeyword that consist of the three basic components of a FITS keyword ke...
Definition: keyword.hpp:266
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
ASSERT_EQ(meta.keyword_rules.size(), 1u)