@@ -329,6 +329,106 @@ namespace ECFMPTest::Api {
329329 }
330330 );
331331
332+ class FlowMeasureDataParserMultipleMeasuresTest : public testing ::Test
333+ {
334+ public:
335+ void SetUp () override
336+ {
337+ // Create the mock parsers
338+ auto filterParser = std::make_unique<MockFlowMeasureFilterParser>();
339+ filterParserRaw = filterParser.get ();
340+ auto measureParser = std::make_unique<MockFlowMeasureMeasureParser>();
341+ measureParserRaw = measureParser.get ();
342+
343+ eventBus = ECFMP::EventBus::MakeEventBus ();
344+ mockEventHandler = std::make_shared<MockFlowMeasuresUpdatedEventHandler>(2 );
345+ mockEventHandlerInternal = std::make_shared<MockInternalFlowMeasuresUpdatedEventHandler>(2 );
346+ eventBus->SubscribeSync <ECFMP::Plugin::FlowMeasuresUpdatedEvent>(mockEventHandler);
347+ eventBus->SubscribeSync <ECFMP::Plugin::InternalFlowMeasuresUpdatedEvent>(mockEventHandlerInternal);
348+
349+ customFilters =
350+ std::make_shared<std::vector<std::shared_ptr<ECFMP::FlowMeasure::CustomFlowMeasureFilter>>>();
351+ parser = std::make_unique<ECFMP::Api::FlowMeasureDataParser>(
352+ std::move (filterParser), std::move (measureParser), std::make_shared<Log::MockLogger>(), eventBus,
353+ customFilters
354+ );
355+
356+ firs.Add (std::make_shared<ECFMP::FlightInformationRegion::ConcreteFlightInformationRegion>(
357+ 1 , " EGTT" , " London"
358+ ));
359+ firs.Add (std::make_shared<ECFMP::FlightInformationRegion::ConcreteFlightInformationRegion>(
360+ 2 , " EGPX" , " Scottish"
361+ ));
362+
363+ events.Add (std::make_shared<ECFMP::Event::ConcreteEvent>(
364+ 1 , " Test event" , now, plusOneHour, firs.Get (1 ), " abc" ,
365+ std::vector<std::shared_ptr<ECFMP::Event::EventParticipant>>{}
366+ ));
367+ }
368+
369+ std::shared_ptr<std::vector<std::shared_ptr<ECFMP::FlowMeasure::CustomFlowMeasureFilter>>> customFilters;
370+ std::shared_ptr<MockFlowMeasuresUpdatedEventHandler> mockEventHandler;
371+ std::shared_ptr<MockInternalFlowMeasuresUpdatedEventHandler> mockEventHandlerInternal;
372+ std::shared_ptr<ECFMP::EventBus::InternalEventBus> eventBus;
373+ MockFlowMeasureFilterParser* filterParserRaw;
374+ MockFlowMeasureMeasureParser* measureParserRaw;
375+ ECFMP::Api::InternalEventCollection events;
376+ ECFMP::Api::InternalFlightInformationRegionCollection firs;
377+ std::unique_ptr<ECFMP::Api::FlowMeasureDataParser> parser;
378+ };
379+
380+ TEST_F (FlowMeasureDataParserMultipleMeasuresTest, ItParsesFlowMeasures)
381+ {
382+ // Mock the measure and filter parser returns
383+ ON_CALL (*filterParserRaw, Parse (testing::_, testing::_))
384+ .WillByDefault (testing::Invoke ([&](const nlohmann::json& data,
385+ const ECFMP::Api::InternalEventCollection& events) {
386+ return std::make_unique<ECFMP::FlowMeasure::ConcreteFlowMeasureFilters>(
387+ std::list<std::shared_ptr<ECFMP::FlowMeasure::AirportFilter>>(),
388+ std::list<std::shared_ptr<ECFMP::FlowMeasure::EventFilter>>(),
389+ std::list<std::shared_ptr<ECFMP::FlowMeasure::RouteFilter>>(),
390+ std::list<std::shared_ptr<ECFMP::FlowMeasure::LevelRangeFilter>>(),
391+ std::list<std::shared_ptr<ECFMP::FlowMeasure::MultipleLevelFilter>>(),
392+ std::list<std::shared_ptr<ECFMP::FlowMeasure::RangeToDestinationFilter>>(),
393+ std::make_shared<Euroscope::MockEuroscopeAircraftFactory>()
394+ );
395+ }));
396+
397+ ON_CALL (*measureParserRaw, Parse (testing::_)).WillByDefault (testing::Invoke ([&](const nlohmann::json& data) {
398+ return std::make_unique<ECFMP::FlowMeasure::ConcreteMeasure>(ECFMP::FlowMeasure::MeasureType::GroundStop);
399+ }));
400+
401+ const auto measure1 = nlohmann::json{
402+ {" id" , 1 },
403+ {" event_id" , 1 },
404+ {" ident" , " EGTT-01A" },
405+ {" reason" , " reason 1" },
406+ {" starttime" , ECFMP::Date::DateStringFromTimePoint (plusOneHour)},
407+ {" endtime" , ECFMP::Date::DateStringFromTimePoint (plusTwoHours)},
408+ {" withdrawn_at" , nlohmann::json::value_t ::null},
409+ {" measure" , {{" foo" , " bar" }}},// Measure is mocked and handled elsewhere, so placeholder
410+ {" filters" , {{" foo" , " baz" }}},// Filter is mocked and handled elsewhere, so placeholder
411+ {" notified_flight_information_regions" , nlohmann::json::array ({1 , 2 })}};
412+
413+ const auto measure2 = nlohmann::json{
414+ {" id" , 2 },
415+ {" event_id" , 1 },
416+ {" ident" , " EGTT-01B" },
417+ {" reason" , " reason 1" },
418+ {" starttime" , ECFMP::Date::DateStringFromTimePoint (plusOneHour)},
419+ {" endtime" , ECFMP::Date::DateStringFromTimePoint (plusTwoHours)},
420+ {" withdrawn_at" , nlohmann::json::value_t ::null},
421+ {" measure" , {{" foo" , " bar" }}},// Measure is mocked and handled elsewhere, so placeholder
422+ {" filters" , {{" foo" , " baz" }}},// Filter is mocked and handled elsewhere, so placeholder
423+ {" notified_flight_information_regions" , nlohmann::json::array ({1 , 2 })}};
424+
425+ auto data = nlohmann::json{{" flow_measures" , nlohmann::json::array ({measure1, measure2})}};
426+ auto flowMeasures = parser->ParseFlowMeasures (data, events, firs);
427+ EXPECT_EQ (2 , flowMeasures->Count ());
428+ EXPECT_EQ (" EGTT-01A" , flowMeasures->begin ()->Identifier ());
429+ EXPECT_EQ (" EGTT-01B" , (++flowMeasures->begin ())->Identifier ());
430+ }
431+
332432 struct FlowMeasureDataParserBadDataTestCase {
333433 std::string description;
334434 nlohmann::json data;
0 commit comments