1 #include <gtest/gtest.h>
31 std::vector<std::pair<std::string, std::string> > testEnv={{
"env1",
"val1"}, {
"env2",
"val2"}, {
"env3",
"val3"}};
36 std::stringstream sourceJson;
45 sourceJson << sourceMessage;
49 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
50 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
51 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
52 printSuccess(
"DRCETaskRequestSetExecute serialize");
55 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
60 sourceJson << inputJsonMessage;
62 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
63 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
64 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
65 printSuccess(
"DRCEInputJsonMessage serialize");
67 std::string resultJson = fObj.Process(sourceJson.str());
71 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
72 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
73 ASSERT_TRUE(fObj.getErrorMsg().empty());
74 printSuccess(
"DRCEFunctionalObject Process use Enviroments");
80 const std::string json =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"tmode\":1,\"time_max\":0,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"sort\",\"input\":\"def\\nabc\\n123\\n\",\"files\":[{\"name\":\"file1\",\"data\":\"test content of file1\\n\",\"action\":13},{\"name\":\"file2\",\"data\":\"test content of file2\\n\",\"action\":1}]}";
87 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
88 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
89 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
90 printSuccess(
"DRCETaskRequestSetExecute unserialize");
93 ASSERT_TRUE(inputJsonMessage.getSessionOptions().userName.empty());
94 ASSERT_TRUE(inputJsonMessage.getSessionOptions().userPassword.empty());
95 ASSERT_TRUE(inputJsonMessage.getSessionOptions().shellName.empty());
96 ASSERT_EQ(inputJsonMessage.getSessionOptions().port, 0);
97 ASSERT_EQ(inputJsonMessage.getSessionOptions().environments.size(), 2);
98 for (
size_t i=0;i<inputJsonMessage.getSessionOptions().environments.size();++i)
100 if (inputJsonMessage.getSessionOptions().environments[i].first==
"LINES")
101 ASSERT_EQ(inputJsonMessage.getSessionOptions().environments[i].second,
"80");
102 if (inputJsonMessage.getSessionOptions().environments[i].first==
"HOSTNAME")
103 ASSERT_EQ(inputJsonMessage.getSessionOptions().environments[i].second,
"node22");
105 printSuccess(
"DRCESessionOptions checking members");
107 ASSERT_EQ(inputJsonMessage.getFilesCount(), 2);
108 for (
size_t i=0;i<inputJsonMessage.getFilesCount();++i)
110 if (inputJsonMessage.getFileItem(i).name==
"file1")
112 ASSERT_EQ(inputJsonMessage.getFileItem(i).data,
"test content of file1\n");
113 ASSERT_EQ(inputJsonMessage.getFileItem(i).actionType, 13);
115 if (inputJsonMessage.getFileItem(i).name==
"file2")
117 ASSERT_EQ(inputJsonMessage.getFileItem(i).data,
"test content of file2\n");
118 ASSERT_EQ(inputJsonMessage.getFileItem(i).actionType, 1);
121 printSuccess(
"DRCEFilesItemArray checking members");
123 ASSERT_EQ(inputJsonMessage.getCommandLine(),
"sort");
124 ASSERT_EQ(inputJsonMessage.getInputStream(),
"def\nabc\n123\n");
125 printSuccess(
"Test Request for local Shell Input");
130 const std::string json =
"[{\"error_code\": 0,\"error_message\": \"Success\",\"exit_status\": 5,\"fields\": [],\"files\":[{\"action\":13,\"data\":\"test content of file1\\n\",\"name\":\"file1\"}],\"host\":\"\",\"id\":2345,\"node\":\"TEST_NODE\",\"pid\":2595,\"port\":\"\",\"state\":42,\"stderror\":\"\",\"stdout\":\"MTIzCmFiYwpkZWYK\",\"time\":5,\"type\":0}]";
136 ASSERT_TRUE(outputJsonMessage.
getErrorMsg().empty());
137 printSuccess(
"DRCEOutputJsonMessage unserialize");
156 printSuccess(
"Test Request for local Shell Output");
161 const std::string requestJson =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"time_max\":0,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"sort\",\"input\":\"def\\nabc\\n123\\n\",\"files\":[{\"name\":\"file1\",\"data\":\"test content of file1\\n\",\"action\":13},{\"name\":\"file2\",\"data\":\"test content of file2\\n\",\"action\":1}]}";
166 fObj.setNodePort(
"NODE_PORT");
167 fObj.setNodeName(
"NODE_NAME");
172 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
176 std::stringstream sourceJson;
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");
186 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");
199 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
200 printSuccess(
"DRCEOutputJsonMessage unserialize");
217 printSuccess(
"Test Request for local Shell (sort)");
223 const std::string json =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"password\":\"\",\"time_max\":0,\"tmode\":1,\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"ps > _ps_results.txt\",\"input\":\"\",\"files\":[{\"name\":\"_ps_results.txt\",\"data\":\"\",\"action\":12}]}";
230 ASSERT_FALSE(taskRequestExecute.isError()) <<
printError(taskRequestExecute);
231 ASSERT_EQ(taskRequestExecute.getErrorCode(),
NO_ERROR);
232 ASSERT_TRUE(taskRequestExecute.getErrorMsg().empty());
233 printSuccess(
"DRCETaskRequestSetExecute unserialize");
236 ASSERT_TRUE(taskRequestExecute.getSessionOptions().userName.empty());
237 ASSERT_TRUE(taskRequestExecute.getSessionOptions().userPassword.empty());
238 ASSERT_TRUE(taskRequestExecute.getSessionOptions().shellName.empty());
239 ASSERT_EQ(taskRequestExecute.getSessionOptions().port, 0);
240 ASSERT_EQ(taskRequestExecute.getSessionOptions().environments.size(), 2);
242 for (
size_t i=0;i<taskRequestExecute.getSessionOptions().environments.size();++i)
244 if (taskRequestExecute.getSessionOptions().environments[i].first==
"LINES")
245 ASSERT_EQ(taskRequestExecute.getSessionOptions().environments[i].second,
"80");
246 if (taskRequestExecute.getSessionOptions().environments[i].first==
"HOSTNAME")
247 ASSERT_EQ(taskRequestExecute.getSessionOptions().environments[i].second,
"node22");
249 printSuccess(
"SessionOptions checking members");
251 ASSERT_EQ(taskRequestExecute.getFilesCount(), 1);
252 ASSERT_EQ(taskRequestExecute.getFileItem(0).name,
"_ps_results.txt");
253 ASSERT_TRUE(taskRequestExecute.getFileItem(0).data.empty());
254 ASSERT_EQ(taskRequestExecute.getFileItem(0).actionType, 12);
255 printSuccess(
"DRCEFilesItemList checking members");
257 ASSERT_EQ(taskRequestExecute.getCommandLine(),
"ps > _ps_results.txt");
258 ASSERT_TRUE(taskRequestExecute.getInputStream().empty());
259 printSuccess(
"Test Request for local Shell Input");
264 const std::string json =
"[{\"error_code\":1,\"error_message\":\"none\",\"exit_status\":127,\"fields\":[],\"files\":[{\"action\":12,\"data\":\"File content\",\"name\":\"_ps_results.txt\"}],\"host\":\"NODE_HOST\",\"id\":2345,\"node\":\"NODE_NAME\",\"pid\":4208,\"port\":\"NODE_PORT\",\"state\":42,\"stderror\":\"stderr_content\",\"stdout\":\"stdout_content\",\"time\":13,\"type\":1}]";
270 ASSERT_TRUE(outputJsonMessage.
getErrorMsg().empty());
271 printSuccess(
"DRCEOutputJsonMessage unserialize");
290 printSuccess(
"Test Request for local Shell Output");
295 const std::string requestJson =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"ps > _ps_results.txt\",\"input\":\"\",\"files\":[{\"name\":\"_ps_results.txt\",\"data\":\"\",\"action\":12}]}";
300 fObj.setNodePort(
"NODE_PORT");
301 fObj.setNodeName(
"NODE_NAME");
306 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
310 std::stringstream sourceJson;
311 sourceJson << inputJsonMessage;
313 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
314 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
315 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
316 printSuccess(
"DRCEInputJsonMessage serialize");
320 std::string resultJson = fObj.Process(sourceJson.str());
322 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
323 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
324 ASSERT_TRUE(fObj.getErrorMsg().empty());
325 printSuccess(
"DRCEFunctionalObject Process");
333 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
334 printSuccess(
"DRCEOutputJsonMessage unserialize");
351 printSuccess(
"Test Request for local Shell (ps)");
357 const std::string requestJson =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"php -v > php_version.txt\",\"input\":\"\",\"files\":[{\"name\":\"php_version.txt\",\"data\":\"\",\"action\":12}]}";
362 fObj.setNodePort(
"NODE_PORT");
363 fObj.setNodeName(
"NODE_NAME");
366 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
370 std::stringstream sourceJson;
371 sourceJson << inputJsonMessage;
373 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
374 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
375 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
376 printSuccess(
"DRCEInputJsonMessage serialize");
378 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");
393 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
394 printSuccess(
"DRCEOutputJsonMessage unserialize");
408 printSuccess(
"Test Request for local Shell (php -v)");
413 const std::string requestJson =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"php test.php > result.txt\",\"input\":\"\",\"files\":[{\"name\":\"test.php\",\"data\":\"<?php\\necho 'Hello, world!';\\n?>\\n\",\"action\":9}, {\"name\":\"result.txt\",\"data\":\"\",\"action\":12}]}";
418 fObj.setNodePort(
"NODE_PORT");
419 fObj.setNodeName(
"NODE_NAME");
423 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
427 std::stringstream sourceJson;
428 sourceJson << inputJsonMessage;
430 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
431 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
432 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
433 printSuccess(
"DRCEInputJsonMessage serialize");
437 std::string resultJson = fObj.Process(sourceJson.str());
439 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
440 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
441 ASSERT_TRUE(fObj.getErrorMsg().empty());
442 printSuccess(
"DRCEFunctionalObject Process");
451 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
452 printSuccess(
"DRCEOutputJsonMessage unserialize");
466 printSuccess(
"Test Request for local Shell (php test.php > result.txt)");
471 const std::string requestJson =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[]},\"command\":\"perl -v > php_version.txt\",\"input\":\"\",\"files\":[{\"name\":\"php_version.txt\",\"data\":\"\",\"action\":12}]}";
476 fObj.setNodePort(
"NODE_PORT");
477 fObj.setNodeName(
"NODE_NAME");
480 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
484 std::stringstream sourceJson;
485 sourceJson << inputJsonMessage;
487 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
488 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
489 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
490 printSuccess(
"DRCEInputJsonMessage serialize");
492 std::string resultJson = fObj.Process(sourceJson.str());
494 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
495 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
496 ASSERT_TRUE(fObj.getErrorMsg().empty());
497 printSuccess(
"DRCEFunctionalObject Process");
507 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
508 printSuccess(
"DRCEOutputJsonMessage unserialize");
522 printSuccess(
"Test Request for local Shell (perl -v > php_version.txt)");
527 const std::string requestJson =
"{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[]},\"command\":\"perl test.pl > result.txt\",\"input\":\"\",\"files\":[{\"name\":\"test.pl\",\"data\":\"#!/usr/bin/perl\\nprint \\\"Hello, world!\\\";\",\"action\":9}, {\"name\":\"result.txt\",\"data\":\"\",\"action\":12}]}";
532 fObj.setNodePort(
"NODE_PORT");
533 fObj.setNodeName(
"NODE_NAME");
536 inputJsonMessage.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
540 std::stringstream sourceJson;
541 sourceJson << inputJsonMessage;
543 ASSERT_FALSE(inputJsonMessage.isError()) <<
printError(inputJsonMessage);
544 ASSERT_EQ(inputJsonMessage.getErrorCode(),
NO_ERROR);
545 ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
546 printSuccess(
"DRCEInputJsonMessage serialize");
548 std::string resultJson = fObj.Process(sourceJson.str());
550 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
551 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
552 ASSERT_TRUE(fObj.getErrorMsg().empty());
553 printSuccess(
"DRCEFunctionalObject Process");
562 ASSERT_TRUE(resultJsonMessage.
getErrorMsg().empty());
563 printSuccess(
"DRCEOutputJsonMessage unserialize");
577 printSuccess(
"Test Request for local Shell (perl test.pl > result.txt)");