9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
14 using namespace testing;
58 using namespace nlohmann;
63 "fileId": "TEST.FILEID",
66 "location": "dcs-host:/path/to/somefile.fits",
70 "selectionPatterns": [
78 "selectionPatterns": [
88 "type": "fitsKeywords",
93 "selectionPatterns": [
101 "type": "valueKeyword",
103 "value": "ESO-PARANAL"
106 "type": "valueKeyword",
111 "type": "valueKeyword",
113 "value": "OBJECT,SKY"
116 "type": "esoKeyword",
117 "name": "OCS TEMPL ID",
118 "value": "template-id"
121 "type": "literalKeyword",
122 "value": "COMMENT Example of a commentary keyword."
127 "type": "fitsKeywords",
133 "type": "esoKeyword",
134 "name": "TEL AIRM START",
138 "type": "esoKeyword",
139 "name": "TEL AIRM END",
147 "location": "fcs-host:/path/to/somefile.fits",
151 "selectionPatterns": [
159 "selectionPatterns": [
170 "type": "olasReceiver",
172 "path": "/absolute/path"
195 auto const& filter = std::get<KeywordFilter>(spec.
target.
source->keyword_rules.at(1));
196 EXPECT_THAT(filter.selection_patterns, ElementsAre(
"+e INS2 *",
"+v VALUEKW"));
199 auto const& ocm_kws_var = spec.
sources[0];
200 ASSERT_TRUE(std::holds_alternative<FitsKeywordsSource>(ocm_kws_var));
201 auto const& tcs_kws_var = spec.
sources[1];
202 ASSERT_TRUE(std::holds_alternative<FitsKeywordsSource>(tcs_kws_var));
203 auto const& fcs_fits_var = spec.
sources[2];
204 ASSERT_TRUE(std::holds_alternative<FitsFileSource>(fcs_fits_var));
205 auto const& ocm_kws = std::get<FitsKeywordsSource>(spec.
sources[0]);
206 auto const& tcs_kws = std::get<FitsKeywordsSource>(spec.
sources[1]);
207 auto const& fcs_fits = std::get<FitsFileSource>(spec.
sources[2]);
211 ASSERT_EQ(ocm_kws.keyword_rules.size(), 1);
212 auto const& filter = std::get<KeywordFilter>(ocm_kws.keyword_rules.at(0));
213 ASSERT_EQ(filter.selection_patterns.size(), 2);
214 EXPECT_THAT(filter.selection_patterns, ElementsAre(
"+e *",
"+v *"));
223 auto const& olas_variant = spec.
receivers[0];
224 ASSERT_TRUE(std::holds_alternative<OlasReceiver>(olas_variant));
225 auto const&
olas_receiver = std::get<OlasReceiver>(olas_variant);
232 m_spec[
"target"].erase(
"targetSource");
242 m_spec[
"sources"] = nlohmann::json::array();
247 m_spec.erase(
"receivers");
252 m_spec[
"receivers"] = nlohmann::json::array();
264 m_spec["target"].erase(
"fileId");
270 m_spec["target"][
"fileId"] = 0u;
273 MatchesRegex(R
"(.*\(/target/fileId\).*must be a string.*)"));
277 m_spec["sources"][0][
"keywords"][0][
"type"] =
"";
280 MatchesRegex(R
"(.*\(/sources/0/keywords/0/type\).*empty.*)"));
284 m_spec["sources"][0].erase(
"keywords");
289 m_spec["sources"][2].erase(
"keywordRules");
294 m_spec[
"target"].erase(
"source");
295 m_spec[
"sources"] = nlohmann::json::array();
302 m_spec["sources"][0][
"type"] =
"unknown";
#define EXPECT_THROW_WITH_MESSAGE(stmt, etype, matcher)
Expect that stmt throws exception of type etype and that the exception message matches matcher.
Location ParseSourceLocation(std::string const &location_str)
Parse location string from DpSpec into component parts.
DpSpec ParseDpSpec(Json const &json)
Parse JSON to construct the DpSpec structure.
Target target
Describes target which will become the data produtc.
std::optional< FitsFileSource > source
ReceiverList receivers
Ordered container of receivers where to deliver the target data product.
std::vector< SourceTypes > sources
List of sources to create data product from.
daq::json::TestParseStartDaqV2Spec _json
TEST_F(TestParseDpSpec, ParseFailsWithUnknownSourcesWrongType)
Close representation of the JSON structure but with stronger types.
Describes parsed location string into its components "host" and "path".
std::filesystem::path path
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
auto const & olas_receiver
ASSERT_EQ(meta.keyword_rules.size(), 1u)
ASSERT_TRUE(std::holds_alternative< OlasReceiver >(spec.receivers[0]))