10 #include <gmock/gmock.h>
11 #include <gtest/gtest.h>
12 #include <log4cplus/logger.h>
13 #include <nlohmann/json.hpp>
23 using namespace ::testing;
37 "type":"valueKeyword",
54 std::vector<std::string> meta_reply_files_1 = {"host@:/some/path",
"host@:/some/path2"};
55 std::vector<std::string> meta_reply_files_2;
57 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise;
58 auto reply_mock = std::make_shared<DaqStopReplyMock>();
59 EXPECT_CALL(*reply_mock, getFiles()).WillRepeatedly(Return(meta_reply_files_1));
60 EXPECT_CALL(*reply_mock, getKeywords()).WillRepeatedly(Return(m_keywords));
62 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise2;
63 auto reply_mock2 = std::make_shared<DaqStopReplyMock>();
64 EXPECT_CALL(*reply_mock2, getFiles()).WillRepeatedly(Return(meta_reply_files_2));
65 EXPECT_CALL(*reply_mock2, getKeywords()).WillRepeatedly(Return(m_empty));
66 EXPECT_CALL(*m_meta_rr_client, StopDaq(_)).WillOnce(Return(ByMove(reply_promise.get_future())));
67 EXPECT_CALL(*m_meta_rr_client2, StopDaq(_))
68 .WillOnce(Return(ByMove(reply_promise2.get_future())));
70 boost::promise<std::shared_ptr<recif::RecStatus>> prim_reply_promise_1;
71 boost::promise<std::shared_ptr<recif::RecStatus>> prim_reply_promise_2;
72 EXPECT_CALL(*m_prim_rr_client, RecStop())
73 .WillOnce(Return(ByMove(prim_reply_promise_1.get_future())));
74 EXPECT_CALL(*m_prim_rr_client2, RecStop())
75 .WillOnce(Return(ByMove(prim_reply_promise_2.get_future())));
77 std::vector<std::string> prim_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
78 std::vector<std::string> prim_reply_files_2;
79 auto prim_reply_mock1 = std::make_shared<RecStatusMock>();
80 auto prim_reply_mock2 = std::make_shared<RecStatusMock>();
81 EXPECT_CALL(*prim_reply_mock1, getDpFiles()).WillRepeatedly(Return(prim_reply_files_1));
82 EXPECT_CALL(*prim_reply_mock2, getDpFiles()).WillRepeatedly(Return(prim_reply_files_2));
85 auto fut = op::InitiateOperation<op::StopAsync>(ErrorPolicy::Strict, MakeParams());
86 ASSERT_FALSE(fut.is_ready());
89 reply_promise.set_value(reply_mock);
90 reply_promise2.set_value(reply_mock2);
91 prim_reply_promise_1.set_value(prim_reply_mock1);
92 prim_reply_promise_2.set_value(prim_reply_mock2);
97 ASSERT_TRUE(fut.is_ready());
98 ASSERT_FALSE(fut.has_exception()) <<
"Future has unexpected exception!";
99 auto result = fut.get();
100 EXPECT_EQ(result.result.size(),
101 1u + meta_reply_files_1.size() +
102 prim_reply_files_1.size());
106 std::vector<std::string> meta_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
107 std::vector<std::string> meta_reply_files_2;
109 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise;
110 auto reply_mock = std::make_shared<DaqStopReplyMock>();
111 EXPECT_CALL(*reply_mock, getFiles()).WillRepeatedly(Return(meta_reply_files_1));
112 EXPECT_CALL(*reply_mock, getKeywords()).WillRepeatedly(Return(
"this is not JSON"));
114 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise2;
115 auto reply_mock2 = std::make_shared<DaqStopReplyMock>();
116 EXPECT_CALL(*reply_mock2, getFiles()).WillRepeatedly(Return(meta_reply_files_2));
117 EXPECT_CALL(*reply_mock2, getKeywords()).WillRepeatedly(Return(m_empty));
118 EXPECT_CALL(*m_meta_rr_client, StopDaq(_)).WillOnce(Return(ByMove(reply_promise.get_future())));
119 EXPECT_CALL(*m_meta_rr_client2, StopDaq(_))
120 .WillOnce(Return(ByMove(reply_promise2.get_future())));
122 EXPECT_CALL(*m_prim_rr_client, RecStop())
123 .WillOnce(Return(ByMove(m_recstatus_promise1.get_future())));
124 EXPECT_CALL(*m_prim_rr_client2, RecStop())
125 .WillOnce(Return(ByMove(m_recstatus_promise2.get_future())));
126 std::vector<std::string> prim_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
127 std::vector<std::string> prim_reply_files_2;
128 auto prim_reply_mock1 = std::make_shared<RecStatusMock>();
129 auto prim_reply_mock2 = std::make_shared<RecStatusMock>();
130 EXPECT_CALL(*prim_reply_mock1, getDpFiles()).WillRepeatedly(Return(prim_reply_files_1));
131 EXPECT_CALL(*prim_reply_mock2, getDpFiles()).WillRepeatedly(Return(prim_reply_files_2));
135 ASSERT_FALSE(fut.is_ready());
138 reply_promise.set_value(reply_mock);
139 reply_promise2.set_value(reply_mock2);
140 m_recstatus_promise1.set_value(prim_reply_mock1);
141 m_recstatus_promise2.set_value(prim_reply_mock2);
146 ASSERT_TRUE(fut.is_ready());
147 ASSERT_FALSE(fut.has_exception()) <<
"Future should have an exception from JSON decoding error";
148 auto result = fut.get();
149 EXPECT_EQ(result.result.size(), meta_reply_files_1.size() + prim_reply_files_1.size())
150 <<
"Expected 0 keywords from failed parsing";
154 std::vector<std::string> meta_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
155 std::vector<std::string> meta_reply_files_2;
157 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise;
158 auto reply_mock = std::make_shared<DaqStopReplyMock>();
159 EXPECT_CALL(*reply_mock, getFiles()).WillRepeatedly(Return(meta_reply_files_1));
160 EXPECT_CALL(*reply_mock, getKeywords()).WillRepeatedly(Return(
"this is not JSON"));
162 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise2;
163 auto reply_mock2 = std::make_shared<DaqStopReplyMock>();
164 EXPECT_CALL(*reply_mock2, getFiles()).WillRepeatedly(Return(meta_reply_files_2));
165 EXPECT_CALL(*reply_mock2, getKeywords()).WillRepeatedly(Return(m_empty));
166 EXPECT_CALL(*m_meta_rr_client, StopDaq(_)).WillOnce(Return(ByMove(reply_promise.get_future())));
167 EXPECT_CALL(*m_meta_rr_client2, StopDaq(_))
168 .WillOnce(Return(ByMove(reply_promise2.get_future())));
170 EXPECT_CALL(*m_prim_rr_client, RecStop())
171 .WillOnce(Return(ByMove(m_recstatus_promise1.get_future())));
172 EXPECT_CALL(*m_prim_rr_client2, RecStop())
173 .WillOnce(Return(ByMove(m_recstatus_promise2.get_future())));
174 std::vector<std::string> prim_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
175 std::vector<std::string> prim_reply_files_2;
176 auto prim_reply_mock1 = std::make_shared<RecStatusMock>();
177 auto prim_reply_mock2 = std::make_shared<RecStatusMock>();
178 EXPECT_CALL(*prim_reply_mock1, getDpFiles()).WillRepeatedly(Return(prim_reply_files_1));
179 EXPECT_CALL(*prim_reply_mock2, getDpFiles()).WillRepeatedly(Return(prim_reply_files_2));
182 auto fut = op::InitiateOperation<op::StopAsync>(ErrorPolicy::Strict, MakeParams());
183 ASSERT_FALSE(fut.is_ready());
186 reply_promise.set_value(reply_mock);
187 reply_promise2.set_value(reply_mock2);
188 m_recstatus_promise1.set_value(prim_reply_mock1);
189 m_recstatus_promise2.set_value(prim_reply_mock2);
194 ASSERT_TRUE(fut.is_ready());
195 ASSERT_TRUE(fut.has_exception()) <<
"Future should have an exception from JSON decoding error";
204 std::vector<std::string> meta_reply_files_1;
206 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise;
207 auto reply_mock = std::make_shared<DaqStopReplyMock>();
208 EXPECT_CALL(*reply_mock, getFiles()).WillRepeatedly(Return(meta_reply_files_1));
209 EXPECT_CALL(*reply_mock, getKeywords()).WillRepeatedly(Return(
""));
211 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise2;
212 auto reply_mock2 = std::make_shared<DaqStopReplyMock>();
213 EXPECT_CALL(*m_meta_rr_client, StopDaq(_)).WillOnce(Return(ByMove(reply_promise.get_future())));
214 EXPECT_CALL(*m_meta_rr_client2, StopDaq(_))
215 .WillOnce(Return(ByMove(reply_promise2.get_future())));
217 EXPECT_CALL(*m_prim_rr_client, RecStop())
218 .WillOnce(Return(ByMove(m_recstatus_promise1.get_future())));
219 EXPECT_CALL(*m_prim_rr_client2, RecStop())
220 .WillOnce(Return(ByMove(m_recstatus_promise2.get_future())));
221 std::vector<std::string> prim_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
222 std::vector<std::string> prim_reply_files_2;
223 auto prim_reply_mock1 = std::make_shared<RecStatusMock>();
224 auto prim_reply_mock2 = std::make_shared<RecStatusMock>();
225 EXPECT_CALL(*prim_reply_mock1, getDpFiles()).WillRepeatedly(Return(prim_reply_files_1));
226 EXPECT_CALL(*prim_reply_mock2, getDpFiles()).WillRepeatedly(Return(prim_reply_files_2));
229 auto fut = op::InitiateOperation<op::StopAsync>(ErrorPolicy::Strict, MakeParams());
230 ASSERT_FALSE(fut.is_ready());
233 reply_promise.set_value(reply_mock);
234 reply_promise2.set_exception(metadaqif::DaqException(m_id,
"message"));
235 m_recstatus_promise1.set_value(prim_reply_mock1);
236 m_recstatus_promise2.set_value(prim_reply_mock2);
241 ASSERT_TRUE(fut.is_ready());
246 std::vector<std::string> meta_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
248 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise;
249 auto reply_mock = std::make_shared<DaqStopReplyMock>();
250 EXPECT_CALL(*reply_mock, getFiles()).WillRepeatedly(Return(meta_reply_files_1));
251 EXPECT_CALL(*reply_mock, getKeywords()).WillRepeatedly(Return(
""));
253 boost::promise<std::shared_ptr<metadaqif::DaqStopReply>> reply_promise2;
254 auto reply_mock2 = std::make_shared<DaqStopReplyMock>();
255 EXPECT_CALL(*m_meta_rr_client, StopDaq(_)).WillOnce(Return(ByMove(reply_promise.get_future())));
256 EXPECT_CALL(*m_meta_rr_client2, StopDaq(_))
257 .WillOnce(Return(ByMove(reply_promise2.get_future())));
258 EXPECT_CALL(*m_prim_rr_client, RecStop())
259 .WillOnce(Return(ByMove(m_recstatus_promise1.get_future())));
260 EXPECT_CALL(*m_prim_rr_client2, RecStop())
261 .WillOnce(Return(ByMove(m_recstatus_promise2.get_future())));
262 std::vector<std::string> prim_reply_files_1 = {
"host@:/some/path",
"host@:/some/path2"};
263 std::vector<std::string> prim_reply_files_2;
264 auto prim_reply_mock1 = std::make_shared<RecStatusMock>();
265 auto prim_reply_mock2 = std::make_shared<RecStatusMock>();
266 EXPECT_CALL(*prim_reply_mock1, getDpFiles()).WillRepeatedly(Return(prim_reply_files_1));
267 EXPECT_CALL(*prim_reply_mock2, getDpFiles()).WillRepeatedly(Return(prim_reply_files_2));
271 ASSERT_FALSE(fut.is_ready());
274 reply_promise.set_value(reply_mock);
275 reply_promise2.set_exception(metadaqif::DaqException(m_id,
"message"));
276 m_recstatus_promise1.set_value(prim_reply_mock1);
277 m_recstatus_promise2.set_value(prim_reply_mock2);
282 ASSERT_TRUE(fut.is_ready());
283 EXPECT_FALSE(fut.has_exception());
284 auto result = fut.get();
285 EXPECT_TRUE(result.error);
286 EXPECT_EQ(result.result.size(), meta_reply_files_1.size() + prim_reply_files_1.size());