1 #include <gtest/gtest.h>
33 fObj.setNodePort(
"NODE_PORT");
34 fObj.setNodeName(
"NODE_NAME");
36 std::stringstream sourceJson;
39 sourceJson << sourceMessage;
43 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
44 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
45 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
46 printSuccess(
"DRCETaskRequestSetExecute serialize");
49 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
54 sourceJson << inputJsonMessage;
56 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
57 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
58 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
59 printSuccess(
"DRCEInputJsonMessage serialize");
61 std::string resultJson = fObj.Process(sourceJson.str());
65 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
66 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
67 ASSERT_TRUE(fObj.getErrorMsg().empty());
68 printSuccess(
"DRCEFunctionalObject Process");
74 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
75 printSuccess(
"DRCEOutputJsonMessage unserialize");
85 printSuccess(
"Test Empty Command");
93 fObj.setNodePort(
"NODE_PORT");
94 fObj.setNodeName(
"NODE_NAME");
96 std::stringstream sourceJson;
101 sourceJson << sourceMessage;
105 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
106 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
107 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
108 printSuccess(
"DRCETaskRequestSetExecute serialize");
111 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
116 sourceJson << inputJsonMessage;
118 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
119 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
120 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
121 printSuccess(
"DRCEInputJsonMessage serialize");
123 std::string resultJson = fObj.Process(sourceJson.str());
127 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
128 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
129 ASSERT_TRUE(fObj.getErrorMsg().empty());
130 printSuccess(
"DRCEFunctionalObject Process");
136 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
137 printSuccess(
"DRCEOutputJsonMessage unserialize");
147 printSuccess(
"Test InputStream with Command");
155 fObj.setNodePort(
"NODE_PORT");
156 fObj.setNodeName(
"NODE_NAME");
158 std::stringstream sourceJson;
162 sourceJson << sourceMessage;
166 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
167 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
168 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
169 printSuccess(
"DRCETaskRequestSetExecute serialize");
172 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
177 sourceJson << inputJsonMessage;
179 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
180 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
181 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
182 printSuccess(
"DRCEInputJsonMessage serialize");
184 std::string resultJson = fObj.Process(sourceJson.str());
188 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
189 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
190 ASSERT_TRUE(fObj.getErrorMsg().empty());
191 printSuccess(
"DRCEFunctionalObject Process");
196 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
198 printSuccess(
"DRCEOutputJsonMessage unserialize");
208 printSuccess(
"Test InputStream without Command");
215 const std::string responseData =
"123\nabc\ndef\n";
220 fObj.setNodePort(
"NODE_PORT");
221 fObj.setNodeName(
"NODE_NAME");
223 std::stringstream sourceJson;
229 sourceJson << sourceMessage;
233 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
234 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
235 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
236 printSuccess(
"DRCETaskRequestSetExecute serialize");
239 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
244 sourceJson << inputJsonMessage;
246 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
247 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
248 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
249 printSuccess(
"DRCEInputJsonMessage serialize");
251 std::string resultJson = fObj.Process(sourceJson.str());
255 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
256 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
257 ASSERT_TRUE(fObj.getErrorMsg().empty());
258 printSuccess(
"DRCEFunctionalObject Process");
264 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
265 printSuccess(
"DRCEOutputJsonMessage unserialize");
275 printSuccess(
"Test Command Sort");
280 std::string sourceJson(
"{\"type\":0,\"data\":\"{\\\"session\\\":{\\\"type\\\":0,\\\"port\\\":0,\\\"user\\\":\\\"\\\",\\\"password\\\":\\\"\\\",\\\"shell\\\":\\\"\\\",\\\"environment\\\":[],\\\"home_dir\\\":\\\"\\\",\\\"timeout\\\":0,\\\"tmode\\\":1,\\\"time_max\\\":60000},\\\"command\\\":\\\"ls -la\\\",\\\"input\\\":\\\"\\\",\\\"files\\\":[],\\\"limits\\\":{\\\"proc_max\\\":0,\\\"threads_max\\\":0,\\\"cpu\\\":0,\\\"vram_free\\\":0,\\\"vram_free_min\\\":0,\\\"rram_free\\\":0,\\\"rram_free_min\\\":0,\\\"disk_free\\\":0,\\\"disk_free_min\\\":0}}\",\"id\":12345}");
287 fObj.setNodePort(
"NODE_PORT");
288 fObj.setNodeName(
"NODE_NAME");
294 ASSERT_FALSE(inputJsonMessage.
getErrorMsg().empty());
295 printSuccess(
"DRCEInputJsonMessage serialize");
297 std::string resultJson = fObj.Process(sourceJson);
301 ASSERT_TRUE(fObj.isError()) <<
printError(fObj);
303 ASSERT_FALSE(fObj.getErrorMsg().empty());
307 ASSERT_EQ(outputJsonMessage.getResultData().getItemsCount(), 1);
308 ASSERT_TRUE(outputJsonMessage.getResultData().getDataItem(0).getStderrStream().empty());
309 ASSERT_FALSE(outputJsonMessage.getResultData().getDataItem(0).getStdoutStream().empty());
313 ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodeName(),
"NODE_NAME");
314 ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodeHost(),
"NODE_HOST");
315 ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodePort(),
"NODE_PORT");
318 printSuccess(
"Test Bad Command Ls");
323 std::string sourceJson(
"{\"type\":0,\"data\":\"eyJzZXNzaW9uIjp7InR5cGUiOjAsInBvcnQiOjAsInVzZXIiOiIiLCJwYXNzd29yZCI6IiIsInNoZWxsIjoiIiwiZW52aXJvbm1lbnQiOltdLCJob21lX2RpciI6IiIsInRpbWVvdXQiOjAsInRtb2RlIjoxLCJ0aW1lX21heCI6NjAwMDB9LCJjb21tYW5kIjoibHMgLWxhIiwiaW5wdXQiOiIiLCJmaWxlcyI6W10sImxpbWl0cyI6eyJwcm9jX21heCI6MCwidGhyZWFkc19tYXgiOjAsImNwdSI6MCwidnJhbV9mcmVlIjowLCJ2cmFtX2ZyZWVfbWluIjowLCJycmFtX2ZyZWUiOjAsInJyYW1fZnJlZV9taW4iOjAsImRpc2tfZnJlZSI6MCwiZGlza19mcmVlX21pbiI6MH19\",\"id\":12345}");
330 fObj.setNodePort(
"NODE_PORT");
331 fObj.setNodeName(
"NODE_NAME");
337 ASSERT_TRUE(inputJsonMessage.
getErrorMsg().empty());
338 printSuccess(
"DRCEInputJsonMessage serialize");
340 std::string resultJson = fObj.Process(sourceJson);
344 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
345 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
346 ASSERT_TRUE(fObj.getErrorMsg().empty());
349 printSuccess(
"Test Command Ls");
357 fObj.setNodePort(
"NODE_PORT");
358 fObj.setNodeName(
"NODE_NAME");;
360 std::stringstream sourceJson;
365 sourceJson << sourceMessage;
369 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
370 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
371 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
372 printSuccess(
"DRCETaskRequestSetExecute serialize");
375 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
380 sourceJson << inputJsonMessage;
382 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
383 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
384 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
385 printSuccess(
"DRCEInputJsonMessage serialize");
387 std::string resultJson = fObj.Process(sourceJson.str());
391 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
392 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
393 ASSERT_TRUE(fObj.getErrorMsg().empty());
394 printSuccess(
"DRCEFunctionalObject Process");
400 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
401 printSuccess(
"DRCEOutputJsonMessage unserialize");
411 printSuccess(
"Test Command Ps");
419 fObj.setNodePort(
"NODE_PORT");
420 fObj.setNodeName(
"NODE_NAME");
422 std::stringstream sourceJson;
425 fObj.setLogStream(std::cout);
428 sourceMessage.
addFileItem(
"test.php",
"<?php\necho 'Hello, world!';\n?>\n", 9);
431 sourceJson << sourceMessage;
435 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
436 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
437 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
438 printSuccess(
"DRCETaskRequestSetExecute serialize");
441 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
446 sourceJson << inputJsonMessage;
448 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
449 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
450 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
451 printSuccess(
"DRCEInputJsonMessage serialize");
453 std::string resultJson = fObj.Process(sourceJson.str());
457 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
458 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
459 ASSERT_TRUE(fObj.getErrorMsg().empty());
460 printSuccess(
"DRCEFunctionalObject Process");
466 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
467 printSuccess(
"DRCEOutputJsonMessage unserialize");
485 printSuccess(
"Test Command 'php test.php > result.txt'");
493 fObj.setNodePort(
"NODE_PORT");
494 fObj.setNodeName(
"NODE_NAME");
496 std::stringstream sourceJson;
500 sourceMessage.
addFileItem(
"test.pl",
"#!/usr/bin/perl\nprint \"Hello, world!\";", 9);
503 sourceJson << sourceMessage;
507 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
508 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
509 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
510 printSuccess(
"DRCETaskRequestSetExecute serialize");
513 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
518 sourceJson << inputJsonMessage;
520 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
521 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
522 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
523 printSuccess(
"DRCEInputJsonMessage serialize");
525 std::string resultJson = fObj.Process(sourceJson.str());
529 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
530 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
531 ASSERT_TRUE(fObj.getErrorMsg().empty());
532 printSuccess(
"DRCEFunctionalObject Process");
538 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
539 printSuccess(
"DRCEOutputJsonMessage unserialize");
554 printSuccess(
"Test Command 'perl test.pl > result.txt'");
562 fObj.setNodePort(
"NODE_PORT");
563 fObj.setNodeName(
"NODE_NAME");
565 std::stringstream sourceJson;
568 const std::string javaClassName =
"test";
569 const std::string javaClassFile = javaClassName+
".class";
570 const std::string javaSourceFile = javaClassName+
".java";
573 sourceMessage.
addFileItem(javaSourceFile,
"public class test {\npublic static void main(String[] args) {\nSystem.out.println(\"Hello, world!\");\n}\n}", 9);
575 sourceJson << sourceMessage;
579 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
580 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
581 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
582 printSuccess(
"DRCETaskRequestSetExecute serialize");
585 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
590 sourceJson << inputJsonMessage;
592 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
593 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
594 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
595 printSuccess(
"DRCEInputJsonMessage serialize");
597 std::string resultJson = fObj.Process(sourceJson.str());
601 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
602 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
603 ASSERT_TRUE(fObj.getErrorMsg().empty());
604 printSuccess(
"DRCEFunctionalObject Process");
613 sourceMessage.clear();
614 sourceMessage.setCommandLine(
"java "+javaClassName+
" > result.txt");
615 sourceMessage.addFileItem(
"result.txt",
"", 12);
617 sourceJson << sourceMessage;
621 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
622 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
623 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
624 printSuccess(
"DRCETaskRequestSetExecute serialize");
626 inputJsonMessage.clear();
627 inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
628 inputJsonMessage.setRequestData(sourceJson.str());
629 inputJsonMessage.setRequestId(2345);
632 sourceJson << inputJsonMessage;
634 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
635 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
636 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
637 printSuccess(
"DRCEInputJsonMessage serialize");
639 resultJson = fObj.Process(sourceJson.str());
643 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
644 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
645 ASSERT_TRUE(fObj.getErrorMsg().empty());
646 printSuccess(
"DRCEFunctionalObject Process");
652 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
653 printSuccess(
"DRCEOutputJsonMessage unserialize");
670 Poco::File testFile(javaClassFile);
671 if (testFile.exists())
675 printSuccess(
"Test Command 'java test > result.txt'");