ifw-daq  3.0.0-pre2
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 
23  nlohmann::json j = orig;
24  auto deserialized = j.get<Status>();
25 
26  EXPECT_EQ(orig, deserialized);
27  EXPECT_EQ(orig.id, deserialized.id);
28  EXPECT_EQ(orig.state, deserialized.state);
29 }
30 
32  using namespace std::chrono_literals;
33  DaqContext ctx;
34  ctx.id = "ID";
35  ctx.await_interval = 5s;
36  ctx.file_id = "FILE_ID";
37  ctx.keywords.push_back(fits::ValueKeyword("FOO", "BAR"));
38  ctx.dp_name_prefix = "FOO";
39  ctx.meta_sources.push_back({"NAME", "URI"});
40 
41  nlohmann::json j = ctx;
42  auto deserialized = j.get<DaqContext>();
43 
44  EXPECT_TRUE(ctx == deserialized);
45  EXPECT_EQ(ctx.id, deserialized.id);
46  EXPECT_EQ(ctx.await_interval, deserialized.await_interval);
47 }
48 
49 TEST(TestJson, DaqContextWithSpecification) {
50  using namespace std::chrono_literals;
51  DaqContext ctx;
52  ctx.id = "ID";
53  ctx.await_interval = 5s;
54  ctx.file_id = "FILE_ID";
55  ctx.keywords.push_back(fits::ValueKeyword("FOO", "BAR"));
56  ctx.dp_name_prefix = "FOO";
57  ctx.meta_sources.push_back({"NAME", "URI"});
58  auto& spec = ctx.specification.emplace();
59  spec.file_prefix = "FOO";
61  ds1.rr_uri = "uri";
62  ds1.source_name = "prim";
64  ds2.rr_uri = "uri";
65  ds2.source_name = "meta";
66 
67  spec.sources.push_back(ds1);
68  spec.sources.push_back(ds2);
69 
70  nlohmann::json j = ctx;
71  auto deserialized = j.get<DaqContext>();
72 
73  EXPECT_TRUE(ctx == deserialized);
74  EXPECT_EQ(ctx.id, deserialized.id);
75  EXPECT_EQ(ctx.await_interval, deserialized.await_interval);
76  EXPECT_EQ(ctx.specification->file_prefix, deserialized.specification->file_prefix);
77  ASSERT_EQ(ctx.specification->sources.size(), 2u);
78  EXPECT_EQ(ctx.specification->sources[0], deserialized.specification->sources[0]);
79  EXPECT_EQ(ctx.specification->sources[1], deserialized.specification->sources[1]);
80 }
81 
82 } // 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
Non observable status object that keeps stores status of data acquisition.
Definition: status.hpp:124
State state
Definition: status.hpp:142
std::string id
Definition: status.hpp:140
std::string result
Path to resulting data product.
Definition: status.hpp:152
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)