1 #include <gtest/gtest.h>
33 const std::string
fileName =
"file1";
34 const std::string
fileData =
"data1";
39 fObj.setNodePort(
"NODE_PORT");
40 fObj.setNodeName(
"NODE_NAME");
42 std::stringstream sourceJson;
47 sourceJson << sourceMessage;
51 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
52 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
53 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
54 printSuccess(
"DRCETaskRequestSetExecute serialize");
57 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
62 sourceJson << inputJsonMessage;
64 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
65 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
66 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
67 printSuccess(
"DRCETaskRequest serialize");
69 std::string resultJson = fObj.Process(sourceJson.str());
73 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
74 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
75 ASSERT_TRUE(fObj.getErrorMsg().empty());
76 printSuccess(
"DRCEFunctionalObject Process");
82 ASSERT_TRUE(responseJsonMessage.
getErrorMsg().empty());
83 printSuccess(
"DRCEOutputJsonMessage unserialize");
94 std::ifstream ifs(fileName.c_str());
95 ASSERT_TRUE(ifs.is_open());
98 ifs.seekg(0, std::ios::end);
99 content.resize(ifs.tellg());
100 ifs.seekg(0, std::ios::beg);
101 ifs.read(const_cast<char*>(content.c_str()), content.size());
103 ASSERT_EQ(content, fileData);
105 Poco::File testFile(fileName);
106 if (testFile.exists())
108 printSuccess(
"Test actionType CREATE_BEFORE_EXEC_AND_WRITE_DATA");
113 const std::string
fileName =
"file1";
114 const std::string
fileData =
"data1";
119 fObj.setNodePort(
"NODE_PORT");
120 fObj.setNodeName(
"NODE_NAME");
122 std::ofstream ofs(fileName.c_str(), std::fstream::trunc);
126 std::stringstream sourceJson;
131 sourceJson << sourceMessage;
135 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
136 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
137 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
138 printSuccess(
"DRCETaskRequestSetExecute serialize");
141 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
146 sourceJson << inputJsonMessage;
148 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
149 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
150 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
151 printSuccess(
"DRCETaskRequest serialize");
153 std::string resultJson = fObj.Process(sourceJson.str());
157 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
158 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
159 ASSERT_TRUE(fObj.getErrorMsg().empty());
160 printSuccess(
"DRCEFunctionalObject Process");
166 ASSERT_TRUE(responseJsonMessage.
getErrorMsg().empty());
167 printSuccess(
"DRCEOutputJsonMessage unserialize");
178 Poco::File testFile(fileName);
179 ASSERT_FALSE(testFile.exists());
180 printSuccess(
"Test actionType DELETE_BEFORE_EXEC");
185 const std::string
fileName =
"file1";
186 const std::string
fileData =
"data1";
191 fObj.setNodePort(
"NODE_PORT");
192 fObj.setNodeName(
"NODE_NAME");
194 Poco::Path testPath(fileName);
195 Poco::File testFile(testPath.absolute().toString());
197 std::ofstream ofs(testFile.path().c_str(), std::fstream::trunc);
201 Poco::Thread::sleep(2000);
203 std::stringstream sourceJson;
208 sourceJson << sourceMessage;
212 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
213 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
214 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
215 printSuccess(
"DRCETaskRequestSetExecute serialize");
218 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
223 sourceJson << inputJsonMessage;
225 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
226 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
227 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
228 printSuccess(
"DRCETaskRequest serialize");
230 std::string resultJson = fObj.Process(sourceJson.str());
232 std::cout <<
"resultJson = " << resultJson <<
std::endl;
234 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
235 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
236 ASSERT_TRUE(fObj.getErrorMsg().empty());
237 printSuccess(
"DRCEFunctionalObject Process");
243 ASSERT_TRUE(responseJsonMessage.
getErrorMsg().empty());
244 printSuccess(
"DRCEOutputJsonMessage unserialize");
259 if (testFile.exists())
261 printSuccess(
"Test actionType READ_AFTER_EXEC_AND_RETURN_RESULT");
266 const std::string
fileName =
"file1";
267 const std::string
fileData =
"data1";
272 fObj.setNodePort(
"NODE_PORT");
273 fObj.setNodeName(
"NODE_NAME");
275 std::ofstream ofs(fileName.c_str());
279 std::stringstream sourceJson;
284 sourceJson << sourceMessage;
288 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
289 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
290 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
291 printSuccess(
"DRCETaskRequestSetExecute serialize");
294 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
299 sourceJson << inputJsonMessage;
301 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
302 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
303 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
304 printSuccess(
"DRCETaskRequest serialize");
306 std::string resultJson = fObj.Process(sourceJson.str());
310 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
311 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
312 ASSERT_TRUE(fObj.getErrorMsg().empty());
313 printSuccess(
"DRCEFunctionalObject Process");
319 ASSERT_TRUE(responseJsonMessage.
getErrorMsg().empty());
320 printSuccess(
"DRCEOutputJsonMessage unserialize");
331 Poco::File testFile(fileName);
332 ASSERT_FALSE(testFile.exists());
333 printSuccess(
"Test actionType DELETE_AFTER_EXEC");
338 const std::string
fileName =
"file1";
339 const std::string
fileData =
"data1";
344 fObj.setNodePort(
"NODE_PORT");
345 fObj.setNodeName(
"NODE_NAME");
347 std::stringstream sourceJson;
354 sourceJson << sourceMessage;
358 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
359 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
360 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
361 printSuccess(
"DRCETaskRequestSetExecute serialize");
364 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
369 sourceJson << inputJsonMessage;
371 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
372 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
373 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
374 printSuccess(
"DRCETaskRequest serialize");
376 std::string resultJson = fObj.Process(sourceJson.str());
380 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
381 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
382 ASSERT_TRUE(fObj.getErrorMsg().empty());
383 printSuccess(
"DRCEFunctionalObject Process");
389 ASSERT_TRUE(responseJsonMessage.
getErrorMsg().empty());
390 printSuccess(
"DRCEOutputJsonMessage unserialize");
410 Poco::File testFile(fileName);
411 ASSERT_FALSE(testFile.exists());
412 printSuccess(
"Test actionType ENCODE_DECODE_CONTENT_BASE64");}