JsonCommanderTest.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. #include <gmock/gmock.h>
  2. #include <gtest/gtest.h>
  3. #include "../include/JsonCommander.h"
  4. #include "FileManagerMock.h"
  5. namespace {
  6. /* Version tests */
  7. TEST(testVersion, PositiveAllEqual) {
  8. FileManagerMock fileManager;
  9. JsonCommander jsonCommander(fileManager);
  10. Json::Value message;
  11. message["major"] = 0;
  12. message["minor"] = 1;
  13. JsonCommander::Response response = jsonCommander.testVersion(message);
  14. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  15. EXPECT_TRUE(response.json["accept"].asBool());
  16. EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
  17. EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
  18. }
  19. TEST(testVersion, Positive) {
  20. FileManagerMock fileManager;
  21. JsonCommander jsonCommander(fileManager);
  22. Json::Value message;
  23. message["major"] = jsonCommander.protocolMajorVersion;
  24. message["minor"] = jsonCommander.protocolMinorVersion - 1;
  25. JsonCommander::Response response = jsonCommander.testVersion(message);
  26. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  27. EXPECT_TRUE(response.json["accept"].asBool());
  28. EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
  29. EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
  30. }
  31. TEST(testVersion, InvalidRequest) {
  32. FileManagerMock fileManager;
  33. JsonCommander jsonCommander(fileManager);
  34. Json::Value message;
  35. message["major"] = "def";
  36. message["minor"] = "abc";
  37. JsonCommander::Response response = jsonCommander.testVersion(message);
  38. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  39. EXPECT_FALSE(response.json["accept"].asBool());
  40. EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
  41. EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
  42. }
  43. TEST(testVersion, NotEqualMajorNumber) {
  44. FileManagerMock fileManager;
  45. JsonCommander jsonCommander(fileManager);
  46. Json::Value message;
  47. message["major"] = jsonCommander.protocolMajorVersion + 1;
  48. message["minor"] = jsonCommander.protocolMinorVersion;
  49. JsonCommander::Response response = jsonCommander.testVersion(message);
  50. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  51. EXPECT_FALSE(response.json["accept"].asBool());
  52. EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
  53. EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
  54. }
  55. TEST(testVersion, BiggerMinorNumber) {
  56. FileManagerMock fileManager;
  57. JsonCommander jsonCommander(fileManager);
  58. Json::Value message;
  59. message["major"] = jsonCommander.protocolMajorVersion;
  60. message["minor"] = jsonCommander.protocolMinorVersion + 1;
  61. JsonCommander::Response response = jsonCommander.testVersion(message);
  62. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  63. EXPECT_FALSE(response.json["accept"].asBool());
  64. EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
  65. EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
  66. }
  67. /* Status tests */
  68. TEST(Status, Ok) {
  69. FileManagerMock fileManager;
  70. JsonCommander jsonCommander(fileManager);
  71. const std::string command = "status";
  72. Json::Value message;
  73. message["command"] = command;
  74. JsonCommander::Response response = jsonCommander.execute(message);
  75. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  76. EXPECT_EQ(response.json["command"].asString(), command);
  77. EXPECT_EQ(response.json["response"].asString(), "ok");
  78. }
  79. TEST(Status, Downloading) {
  80. FileManagerMock fileManager;
  81. JsonCommander jsonCommander(fileManager);
  82. const std::string command = "status";
  83. Json::Value message;
  84. message["command"] = command;
  85. ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
  86. JsonCommander::Response response = jsonCommander.execute(message);
  87. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  88. EXPECT_EQ(response.json["command"].asString(), command);
  89. EXPECT_EQ(response.json["response"].asString(), "download running");
  90. }
  91. TEST(Status, Uploading) {
  92. FileManagerMock fileManager;
  93. JsonCommander jsonCommander(fileManager);
  94. const std::string command = "status";
  95. Json::Value message;
  96. message["command"] = command;
  97. ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
  98. JsonCommander::Response response = jsonCommander.execute(message);
  99. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  100. EXPECT_EQ(response.json["command"].asString(), command);
  101. EXPECT_EQ(response.json["response"].asString(), "upload running");
  102. }
  103. TEST(Status, UploadingAndDownloading) {
  104. FileManagerMock fileManager;
  105. JsonCommander jsonCommander(fileManager);
  106. const std::string command = "status";
  107. Json::Value message;
  108. message["command"] = command;
  109. ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
  110. ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
  111. JsonCommander::Response response = jsonCommander.execute(message);
  112. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  113. EXPECT_EQ(response.json["command"].asString(), command);
  114. EXPECT_EQ(response.json["response"].asString(), "download and upload running");
  115. }
  116. /* Close tests */
  117. TEST(Close, Close) {
  118. FileManagerMock fileManager;
  119. JsonCommander jsonCommander(fileManager);
  120. const std::string command = "close";
  121. Json::Value message;
  122. message["command"] = command;
  123. JsonCommander::Response response = jsonCommander.execute(message);
  124. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  125. EXPECT_EQ(response.json["command"].asString(), command);
  126. EXPECT_EQ(response.json["response"].asString(), "bye");
  127. }
  128. /* Put tests */
  129. TEST(Put, Positive) {
  130. FileManagerMock fileManager;
  131. JsonCommander jsonCommander(fileManager);
  132. const std::string command = "put";
  133. const std::string filename = "cool.txt";
  134. Json::Value message;
  135. message["command"] = command;
  136. message["file"] = filename;
  137. message["size"] = 1337;
  138. message["chunks"] = 1;
  139. ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
  140. JsonCommander::Response response = jsonCommander.execute(message);
  141. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  142. EXPECT_EQ(response.json["command"].asString(), command);
  143. EXPECT_TRUE(response.json["accept"].asBool());
  144. EXPECT_EQ(response.json["file"].asString(), filename);
  145. EXPECT_EQ(response.json["error"].asString(), "");
  146. }
  147. TEST(Put, Negative) {
  148. FileManagerMock fileManager;
  149. JsonCommander jsonCommander(fileManager);
  150. const std::string command = "put";
  151. const std::string filename = "cool.txt";
  152. Json::Value message;
  153. message["command"] = command;
  154. message["file"] = filename;
  155. message["size"] = 1337;
  156. message["chunks"] = 1;
  157. ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(false));
  158. JsonCommander::Response response = jsonCommander.execute(message);
  159. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  160. EXPECT_EQ(response.json["command"].asString(), command);
  161. EXPECT_FALSE(response.json["accept"].asBool());
  162. EXPECT_EQ(response.json["file"].asString(), filename);
  163. EXPECT_TRUE(response.json["error"].asString().length() > 0);
  164. }
  165. /* Putdata tests */
  166. TEST(Putdata, Positive) {
  167. FileManagerMock fileManager;
  168. JsonCommander jsonCommander(fileManager);
  169. /* start with put */
  170. std::string command = "put";
  171. const std::string filename = "cool.txt";
  172. Json::Value message;
  173. message["command"] = command;
  174. message["file"] = filename;
  175. message["size"] = 1337;
  176. const int chunks = 3;
  177. message["chunks"] = chunks;
  178. ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
  179. JsonCommander::Response response = jsonCommander.execute(message);
  180. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  181. EXPECT_EQ(response.json["command"].asString(), command);
  182. EXPECT_TRUE(response.json["accept"].asBool());
  183. EXPECT_EQ(response.json["file"].asString(), filename);
  184. EXPECT_EQ(response.json["error"].asString(), "");
  185. /* putdata */
  186. command = "putdata";
  187. ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
  188. ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
  189. for (int remaining = chunks - 1; remaining >= 0; remaining--) {
  190. message = Json::Value();
  191. message["command"] = command;
  192. message["file"] = filename;
  193. message["data"] = "MTMzNw==";
  194. message["remaining"] = remaining;
  195. message["cancel"] = false;
  196. response = jsonCommander.execute(message);
  197. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  198. EXPECT_EQ(response.json["command"].asString(), command);
  199. EXPECT_FALSE(response.json["cancel"].asBool());
  200. EXPECT_EQ(response.json["received"].asInt(), remaining);
  201. EXPECT_EQ(response.json["file"].asString(), filename);
  202. EXPECT_EQ(response.json["error"].asString(), "");
  203. }
  204. }
  205. TEST(Putdata, Cancel) {
  206. FileManagerMock fileManager;
  207. JsonCommander jsonCommander(fileManager);
  208. /* start with put */
  209. std::string command = "put";
  210. const std::string filename = "cool.txt";
  211. Json::Value message;
  212. message["command"] = command;
  213. message["file"] = filename;
  214. message["size"] = 1337;
  215. const int chunks = 3;
  216. message["chunks"] = chunks;
  217. ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
  218. JsonCommander::Response response = jsonCommander.execute(message);
  219. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  220. EXPECT_EQ(response.json["command"].asString(), command);
  221. EXPECT_TRUE(response.json["accept"].asBool());
  222. EXPECT_EQ(response.json["file"].asString(), filename);
  223. EXPECT_EQ(response.json["error"].asString(), "");
  224. /* putdata */
  225. command = "putdata";
  226. ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
  227. ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
  228. int remaining = chunks - 1;
  229. message = Json::Value();
  230. message["command"] = command;
  231. message["file"] = filename;
  232. message["data"] = "MTMzNw==";
  233. message["remaining"] = remaining;
  234. message["cancel"] = false;
  235. response = jsonCommander.execute(message);
  236. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  237. EXPECT_EQ(response.json["command"].asString(), command);
  238. EXPECT_FALSE(response.json["cancel"].asBool());
  239. EXPECT_EQ(response.json["received"].asInt(), remaining);
  240. EXPECT_EQ(response.json["file"].asString(), filename);
  241. EXPECT_EQ(response.json["error"].asString(), "");
  242. // cancel transfer
  243. message = Json::Value();
  244. message["command"] = command;
  245. message["file"] = filename;
  246. message["data"] = "MTMzNw==";
  247. message["remaining"] = --remaining;
  248. message["cancel"] = true;
  249. response = jsonCommander.execute(message);
  250. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  251. EXPECT_EQ(response.json["command"].asString(), command);
  252. EXPECT_TRUE(response.json["cancel"].asBool());
  253. EXPECT_EQ(response.json["received"].asInt(), remaining);
  254. EXPECT_EQ(response.json["file"].asString(), filename);
  255. EXPECT_EQ(response.json["error"].asString(), "");
  256. }
  257. TEST(Putdata, WrongRemaining) {
  258. FileManagerMock fileManager;
  259. JsonCommander jsonCommander(fileManager);
  260. /* start with put */
  261. std::string command = "put";
  262. const std::string filename = "cool.txt";
  263. Json::Value message;
  264. message["command"] = command;
  265. message["file"] = filename;
  266. message["size"] = 1337;
  267. const int chunks = 3;
  268. message["chunks"] = chunks;
  269. ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
  270. JsonCommander::Response response = jsonCommander.execute(message);
  271. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  272. EXPECT_EQ(response.json["command"].asString(), command);
  273. EXPECT_TRUE(response.json["accept"].asBool());
  274. EXPECT_EQ(response.json["file"].asString(), filename);
  275. EXPECT_EQ(response.json["error"].asString(), "");
  276. /* putdata */
  277. command = "putdata";
  278. ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
  279. ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
  280. int remaining = chunks - 1;
  281. message = Json::Value();
  282. message["command"] = command;
  283. message["file"] = filename;
  284. message["data"] = "MTMzNw==";
  285. message["remaining"] = remaining;
  286. message["cancel"] = false;
  287. response = jsonCommander.execute(message);
  288. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  289. EXPECT_EQ(response.json["command"].asString(), command);
  290. EXPECT_FALSE(response.json["cancel"].asBool());
  291. EXPECT_EQ(response.json["received"].asInt(), remaining);
  292. EXPECT_EQ(response.json["file"].asString(), filename);
  293. EXPECT_EQ(response.json["error"].asString(), "");
  294. message = Json::Value();
  295. // skip remaining=1 and provoke an error
  296. remaining = 0;
  297. message = Json::Value();
  298. message["command"] = command;
  299. message["file"] = filename;
  300. message["data"] = "MTMzNw==";
  301. message["remaining"] = remaining;
  302. message["cancel"] = false;
  303. response = jsonCommander.execute(message);
  304. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  305. EXPECT_EQ(response.json["command"].asString(), command);
  306. EXPECT_TRUE(response.json["cancel"].asBool());
  307. EXPECT_EQ(response.json["received"].asInt(), remaining);
  308. EXPECT_EQ(response.json["file"].asString(), filename);
  309. EXPECT_TRUE(response.json["error"].asString().length() > 0);
  310. }
  311. /* Get tests */
  312. TEST(Get, Positive) {
  313. FileManagerMock fileManager;
  314. JsonCommander jsonCommander(fileManager);
  315. const std::string command = "get";
  316. const std::string filename = "cool.txt";
  317. Json::Value message;
  318. message["command"] = command;
  319. message["file"] = filename;
  320. const int chunks = 3;
  321. EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
  322. JsonCommander::Response response = jsonCommander.execute(message);
  323. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  324. EXPECT_EQ(response.json["command"].asString(), command);
  325. EXPECT_TRUE(response.json["accept"].asBool());
  326. EXPECT_EQ(response.json["file"].asString(), filename);
  327. EXPECT_EQ(response.json["chunks"].asInt(), chunks);
  328. EXPECT_EQ(response.json["error"].asString(), "");
  329. }
  330. TEST(Get, Negative) {
  331. FileManagerMock fileManager;
  332. JsonCommander jsonCommander(fileManager);
  333. const std::string command = "get";
  334. const std::string filename = "cool.txt";
  335. Json::Value message;
  336. message["command"] = command;
  337. message["file"] = filename;
  338. EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(false, -1)));
  339. JsonCommander::Response response = jsonCommander.execute(message);
  340. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  341. EXPECT_EQ(response.json["command"].asString(), command);
  342. EXPECT_FALSE(response.json["accept"].asBool());
  343. EXPECT_EQ(response.json["file"].asString(), filename);
  344. EXPECT_EQ(response.json["chunks"].asInt(), -1);
  345. EXPECT_TRUE(response.json["error"].asString().length() > 0);
  346. }
  347. /* Getdata tests */
  348. TEST(Getdata, Positive) {
  349. FileManagerMock fileManager;
  350. JsonCommander jsonCommander(fileManager);
  351. std::string command = "get";
  352. const std::string filename = "cool.txt";
  353. Json::Value message;
  354. message["command"] = command;
  355. message["file"] = filename;
  356. const int chunks = 3;
  357. EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
  358. JsonCommander::Response response = jsonCommander.execute(message);
  359. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  360. EXPECT_EQ(response.json["command"].asString(), command);
  361. EXPECT_TRUE(response.json["accept"].asBool());
  362. EXPECT_EQ(response.json["file"].asString(), filename);
  363. EXPECT_EQ(response.json["chunks"].asInt(), chunks);
  364. EXPECT_EQ(response.json["error"].asString(), "");
  365. /* getdata */
  366. command = "getdata";
  367. ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
  368. ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
  369. std::vector<char> data;
  370. data.push_back('1');
  371. data.push_back('3');
  372. data.push_back('3');
  373. data.push_back('7');
  374. ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
  375. for (int remaining = chunks - 1; remaining >= 0; remaining--) {
  376. message = Json::Value();
  377. message["command"] = command;
  378. message["file"] = filename;
  379. message["chunk"] = remaining;
  380. message["cancel"] = false;
  381. response = jsonCommander.execute(message);
  382. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  383. EXPECT_EQ(response.json["command"].asString(), command);
  384. EXPECT_FALSE(response.json["cancel"].asBool());
  385. EXPECT_EQ(response.json["remaining"].asInt(), remaining);
  386. EXPECT_EQ(response.json["file"].asString(), filename);
  387. EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
  388. EXPECT_EQ(response.json["error"].asString(), "");
  389. }
  390. }
  391. TEST(Getdata, Cancle) {
  392. FileManagerMock fileManager;
  393. JsonCommander jsonCommander(fileManager);
  394. std::string command = "get";
  395. const std::string filename = "cool.txt";
  396. Json::Value message;
  397. message["command"] = command;
  398. message["file"] = filename;
  399. const int chunks = 3;
  400. EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
  401. JsonCommander::Response response = jsonCommander.execute(message);
  402. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  403. EXPECT_EQ(response.json["command"].asString(), command);
  404. EXPECT_TRUE(response.json["accept"].asBool());
  405. EXPECT_EQ(response.json["file"].asString(), filename);
  406. EXPECT_EQ(response.json["chunks"].asInt(), chunks);
  407. EXPECT_EQ(response.json["error"].asString(), "");
  408. /* getdata */
  409. command = "getdata";
  410. ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
  411. ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
  412. std::vector<char> data;
  413. data.push_back('1');
  414. data.push_back('3');
  415. data.push_back('3');
  416. data.push_back('7');
  417. ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
  418. int remaining = chunks - 1;
  419. message = Json::Value();
  420. message["command"] = command;
  421. message["file"] = filename;
  422. message["chunk"] = remaining;
  423. message["cancel"] = false;
  424. response = jsonCommander.execute(message);
  425. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  426. EXPECT_EQ(response.json["command"].asString(), command);
  427. EXPECT_FALSE(response.json["cancel"].asBool());
  428. EXPECT_EQ(response.json["remaining"].asInt(), remaining);
  429. EXPECT_EQ(response.json["file"].asString(), filename);
  430. EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
  431. EXPECT_EQ(response.json["error"].asString(), "");
  432. // set cancel to true
  433. message = Json::Value();
  434. message["command"] = command;
  435. message["file"] = filename;
  436. message["chunk"] = --remaining;
  437. message["cancel"] = true;
  438. response = jsonCommander.execute(message);
  439. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  440. EXPECT_EQ(response.json["command"].asString(), command);
  441. EXPECT_TRUE(response.json["cancel"].asBool());
  442. EXPECT_EQ(response.json["remaining"].asInt(), remaining);
  443. EXPECT_EQ(response.json["file"].asString(), filename);
  444. EXPECT_EQ(response.json["data"].asString(), "");
  445. EXPECT_EQ(response.json["error"].asString(), "");
  446. }
  447. TEST(Getdata, WrongChunk) {
  448. FileManagerMock fileManager;
  449. JsonCommander jsonCommander(fileManager);
  450. std::string command = "get";
  451. const std::string filename = "cool.txt";
  452. Json::Value message;
  453. message["command"] = command;
  454. message["file"] = filename;
  455. const int chunks = 3;
  456. EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
  457. JsonCommander::Response response = jsonCommander.execute(message);
  458. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  459. EXPECT_EQ(response.json["command"].asString(), command);
  460. EXPECT_TRUE(response.json["accept"].asBool());
  461. EXPECT_EQ(response.json["file"].asString(), filename);
  462. EXPECT_EQ(response.json["chunks"].asInt(), chunks);
  463. EXPECT_EQ(response.json["error"].asString(), "");
  464. /* getdata */
  465. command = "getdata";
  466. ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
  467. ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
  468. std::vector<char> data;
  469. data.push_back('1');
  470. data.push_back('3');
  471. data.push_back('3');
  472. data.push_back('7');
  473. ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
  474. int remaining = chunks - 1;
  475. message = Json::Value();
  476. message["command"] = command;
  477. message["file"] = filename;
  478. message["chunk"] = remaining;
  479. message["cancel"] = false;
  480. response = jsonCommander.execute(message);
  481. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  482. EXPECT_EQ(response.json["command"].asString(), command);
  483. EXPECT_FALSE(response.json["cancel"].asBool());
  484. EXPECT_EQ(response.json["remaining"].asInt(), remaining);
  485. EXPECT_EQ(response.json["file"].asString(), filename);
  486. EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
  487. EXPECT_EQ(response.json["error"].asString(), "");
  488. // skip chunk=0
  489. remaining = 0;
  490. message = Json::Value();
  491. message["command"] = command;
  492. message["file"] = filename;
  493. message["chunk"] = remaining;
  494. message["cancel"] = false;
  495. response = jsonCommander.execute(message);
  496. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  497. EXPECT_EQ(response.json["command"].asString(), command);
  498. EXPECT_TRUE(response.json["cancel"].asBool());
  499. EXPECT_EQ(response.json["remaining"].asInt(), remaining);
  500. EXPECT_EQ(response.json["file"].asString(), filename);
  501. EXPECT_EQ(response.json["data"].asString(), "");
  502. EXPECT_TRUE(response.json["error"].asString().length() > 0);
  503. }
  504. /* List tests */
  505. TEST(List, Positive) {
  506. FileManagerMock fileManager;
  507. JsonCommander jsonCommander(fileManager);
  508. const std::string command = "list";
  509. Json::Value message;
  510. message["command"] = command;
  511. EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(1));
  512. EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(5));
  513. JsonCommander::Response response = jsonCommander.execute(message);
  514. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  515. EXPECT_EQ(response.json["command"].asString(), command);
  516. EXPECT_TRUE(response.json["accept"].asBool());
  517. EXPECT_EQ(response.json["chunks"].asInt(), 1);
  518. EXPECT_EQ(response.json["items"].asInt(), 5);
  519. EXPECT_EQ(response.json["error"].asString(), "");
  520. }
  521. TEST(List, Negative) {
  522. FileManagerMock fileManager;
  523. JsonCommander jsonCommander(fileManager);
  524. const std::string command = "list";
  525. Json::Value message;
  526. message["command"] = command;
  527. EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(-1));
  528. JsonCommander::Response response = jsonCommander.execute(message);
  529. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  530. EXPECT_EQ(response.json["command"].asString(), command);
  531. EXPECT_FALSE(response.json["accept"].asBool());
  532. EXPECT_EQ(response.json["chunks"].asInt(), -1);
  533. EXPECT_EQ(response.json["items"].asInt(), -1);
  534. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  535. }
  536. TEST(List, EmptyList) {
  537. FileManagerMock fileManager;
  538. JsonCommander jsonCommander(fileManager);
  539. const std::string command = "list";
  540. Json::Value message;
  541. message["command"] = command;
  542. EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(0));
  543. EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(0));
  544. JsonCommander::Response response = jsonCommander.execute(message);
  545. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  546. EXPECT_EQ(response.json["command"].asString(), command);
  547. EXPECT_TRUE(response.json["accept"].asBool());
  548. EXPECT_EQ(response.json["chunks"].asInt(), 0);
  549. EXPECT_EQ(response.json["items"].asInt(), 0);
  550. EXPECT_EQ(response.json["error"].asString(), "");
  551. }
  552. /* Listdata tests */
  553. void fillExampleFileList(std::vector<std::string> (&chunk)[3]) {
  554. chunk[0].push_back("file01.txt");
  555. chunk[0].push_back("bumdibumps");
  556. chunk[0].push_back("1");
  557. chunk[0].push_back("Ich habe Hunger.txt");
  558. chunk[0].push_back("answerIs42");
  559. chunk[0].push_back("123456789456115811");
  560. chunk[0].push_back("kek");
  561. chunk[1].push_back("1337");
  562. chunk[1].push_back("cats.png");
  563. chunk[1].push_back("more_cats.png");
  564. chunk[1].push_back("ugly dog.tiff");
  565. chunk[1].push_back("hello.txt");
  566. chunk[1].push_back("bye.exe");
  567. chunk[1].push_back("poster.pdf");
  568. chunk[2].push_back("headbang.gif");
  569. chunk[2].push_back("feelsbad.jpg");
  570. chunk[2].push_back("hack.s");
  571. chunk[2].push_back("SodiumChloride");
  572. chunk[2].push_back("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst"
  573. "uvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN"
  574. "OPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  575. }
  576. TEST(Listdata, Positive) {
  577. FileManagerMock fileManager;
  578. JsonCommander jsonCommander(fileManager);
  579. const std::string command = "listdata";
  580. const int chunks = 3;
  581. std::vector<std::string> chunk[chunks];
  582. fillExampleFileList(chunk);
  583. int remaining = chunks - 1;
  584. for (int k = 0; k < chunks; k++) {
  585. Json::Value message;
  586. message["command"] = command;
  587. message["chunk"] = remaining;
  588. message["cancel"] = false;
  589. EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
  590. EXPECT_CALL(fileManager, getNextChunkFromList()).WillOnce(testing::Return(chunk[k]));
  591. JsonCommander::Response response = jsonCommander.execute(message);
  592. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  593. EXPECT_EQ(response.json["command"].asString(), command);
  594. EXPECT_FALSE(response.json["cancel"].asBool());
  595. EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
  596. EXPECT_TRUE(response.json["names"].isArray());
  597. Json::Value array = response.json["names"];
  598. EXPECT_EQ(array.size(), chunk[k].size());
  599. for (int i = 0; i < 3; i++) {
  600. EXPECT_EQ(array[i].asString(), chunk[k][i]);
  601. }
  602. EXPECT_EQ(response.json["error"].asString(), "");
  603. }
  604. }
  605. TEST(Listdata, Cancel) {
  606. FileManagerMock fileManager;
  607. JsonCommander jsonCommander(fileManager);
  608. const std::string command = "listdata";
  609. const int chunks = 3;
  610. std::vector<std::string> chunk[chunks];
  611. fillExampleFileList(chunk);
  612. int remaining = chunks - 1;
  613. Json::Value message;
  614. message["command"] = command;
  615. message["chunk"] = remaining;
  616. message["cancel"] = false;
  617. EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
  618. EXPECT_CALL(fileManager, getNextChunkFromList()).WillOnce(testing::Return(chunk[0]));
  619. JsonCommander::Response response = jsonCommander.execute(message);
  620. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  621. EXPECT_EQ(response.json["command"].asString(), command);
  622. EXPECT_FALSE(response.json["cancel"].asBool());
  623. EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
  624. EXPECT_TRUE(response.json["names"].isArray());
  625. Json::Value array = response.json["names"];
  626. EXPECT_EQ(array.size(), chunk[0].size());
  627. for (int i = 0; i < 3; i++) {
  628. EXPECT_EQ(array[i].asString(), chunk[0][i]);
  629. }
  630. EXPECT_EQ(response.json["error"].asString(), "");
  631. message = Json::Value();
  632. message["command"] = command;
  633. message["chunk"] = remaining;
  634. message["cancel"] = true;
  635. EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
  636. response = jsonCommander.execute(message);
  637. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  638. EXPECT_EQ(response.json["command"].asString(), command);
  639. EXPECT_TRUE(response.json["cancel"].asBool());
  640. EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
  641. EXPECT_TRUE(response.json["names"].isArray());
  642. EXPECT_EQ(response.json["error"].asString(), "");
  643. }
  644. TEST(Listdata, WrongChunkNumber) {
  645. FileManagerMock fileManager;
  646. JsonCommander jsonCommander(fileManager);
  647. const std::string command = "listdata";
  648. const int chunks = 3;
  649. int remaining = chunks - 1;
  650. Json::Value message;
  651. message["command"] = command;
  652. message["chunk"] = remaining;
  653. message["cancel"] = false;
  654. // return smaller remaining
  655. EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining));
  656. JsonCommander::Response response = jsonCommander.execute(message);
  657. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  658. EXPECT_EQ(response.json["command"].asString(), command);
  659. EXPECT_TRUE(response.json["cancel"].asBool());
  660. EXPECT_EQ(response.json["remaining"].asInt(), -1);
  661. EXPECT_TRUE(response.json["names"].isArray());
  662. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  663. }
  664. TEST(Listdata, NoChunksToBeSend) {
  665. FileManagerMock fileManager;
  666. JsonCommander jsonCommander(fileManager);
  667. const std::string command = "listdata";
  668. const int chunks = 0;
  669. Json::Value message;
  670. message["command"] = command;
  671. message["chunk"] = 1;
  672. message["cancel"] = false;
  673. // return smaller remaining
  674. EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(chunks));
  675. JsonCommander::Response response = jsonCommander.execute(message);
  676. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  677. EXPECT_EQ(response.json["command"].asString(), command);
  678. EXPECT_TRUE(response.json["cancel"].asBool());
  679. EXPECT_EQ(response.json["remaining"].asInt(), -1);
  680. EXPECT_TRUE(response.json["names"].isArray());
  681. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  682. }
  683. TEST(Listdata, InvalidRequest) {
  684. FileManagerMock fileManager;
  685. JsonCommander jsonCommander(fileManager);
  686. const std::string command = "listdata";
  687. const int chunks = 3;
  688. Json::Value message;
  689. message["command"] = command;
  690. message["chunk"] = 1;
  691. // return smaller remaining
  692. EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(chunks));
  693. JsonCommander::Response response = jsonCommander.execute(message);
  694. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  695. EXPECT_EQ(response.json["command"].asString(), command);
  696. EXPECT_TRUE(response.json["cancel"].asBool());
  697. EXPECT_EQ(response.json["remaining"].asInt(), -1);
  698. EXPECT_TRUE(response.json["names"].isArray());
  699. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  700. }
  701. TEST(Head, Positive) {
  702. FileManagerMock fileManager;
  703. JsonCommander jsonCommander(fileManager);
  704. const std::string command = "head";
  705. const std::string file = "asdf.txt";
  706. Json::Value message;
  707. message["command"] = command;
  708. message["file"] = file;
  709. std::vector<char> bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
  710. const std::string bytesAsString = "YWJjZGVmZ2g=";
  711. EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_error)));
  712. JsonCommander::Response response = jsonCommander.execute(message);
  713. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  714. EXPECT_EQ(response.json["command"].asString(), command);
  715. EXPECT_TRUE(response.json["accept"].asBool());
  716. EXPECT_EQ(response.json["file"].asString(), file);
  717. EXPECT_EQ(response.json["data"].asString(), bytesAsString);
  718. EXPECT_EQ(response.json["error"].asString(), "");
  719. }
  720. TEST(Head, InvalidRequest) {
  721. FileManagerMock fileManager;
  722. JsonCommander jsonCommander(fileManager);
  723. const std::string command = "head";
  724. const int file = 3641;
  725. Json::Value message;
  726. message["command"] = command;
  727. message["file"] = file;
  728. JsonCommander::Response response = jsonCommander.execute(message);
  729. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  730. EXPECT_EQ(response.json["command"].asString(), command);
  731. EXPECT_FALSE(response.json["accept"].asBool());
  732. EXPECT_EQ(response.json["file"].asString(), "");
  733. EXPECT_EQ(response.json["data"].asString(), "");
  734. EXPECT_NE(response.json["error"].asString(), "");
  735. }
  736. TEST(Head, NoSuchFile) {
  737. FileManagerMock fileManager;
  738. JsonCommander jsonCommander(fileManager);
  739. const std::string command = "head";
  740. const std::string file = "asdf.txt";
  741. Json::Value message;
  742. message["command"] = command;
  743. message["file"] = file;
  744. std::vector<char> bytes;
  745. EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_such_file)));
  746. JsonCommander::Response response = jsonCommander.execute(message);
  747. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  748. EXPECT_EQ(response.json["command"].asString(), command);
  749. EXPECT_FALSE(response.json["accept"].asBool());
  750. EXPECT_EQ(response.json["file"].asString(), file);
  751. EXPECT_EQ(response.json["data"].asString(), "");
  752. EXPECT_NE(response.json["error"].asString(), "");
  753. }
  754. TEST(Head, FileTooSmall) {
  755. FileManagerMock fileManager;
  756. JsonCommander jsonCommander(fileManager);
  757. const std::string command = "head";
  758. const std::string file = "asdf.txt";
  759. Json::Value message;
  760. message["command"] = command;
  761. message["file"] = file;
  762. std::vector<char> bytes;
  763. EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
  764. JsonCommander::Response response = jsonCommander.execute(message);
  765. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  766. EXPECT_EQ(response.json["command"].asString(), command);
  767. EXPECT_FALSE(response.json["accept"].asBool());
  768. EXPECT_EQ(response.json["file"].asString(), file);
  769. EXPECT_EQ(response.json["data"].asString(), "");
  770. EXPECT_NE(response.json["error"].asString(), "");
  771. }
  772. TEST(Deleteme, Positive) {
  773. FileManagerMock fileManager;
  774. JsonCommander jsonCommander(fileManager);
  775. // need to set currentUser in jsonCommander via calling checkLogin
  776. Json::Value login;
  777. login["login"] = true;
  778. login["user"] = "positive";
  779. login["pass"] = "positive";
  780. login["cancel"] = false;
  781. JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
  782. EXPECT_TRUE(loginRes.json["accept"].asBool());
  783. EXPECT_EQ(loginRes.json["error"].asString(), "");
  784. // now the actual test
  785. const std::string command = "deleteme";
  786. Json::Value message;
  787. message["command"] = command;
  788. message["pass"] = "positive";
  789. JsonCommander::Response response = jsonCommander.execute(message);
  790. EXPECT_EQ(response.action, JsonCommander::Action::closeAndSend);
  791. EXPECT_EQ(response.json["command"].asString(), command);
  792. EXPECT_TRUE(response.json["accept"].asBool());
  793. EXPECT_EQ(response.json["error"].asString(), "");
  794. }
  795. TEST(Deleteme, Negative) {
  796. FileManagerMock fileManager;
  797. JsonCommander jsonCommander(fileManager);
  798. // need to set currentUser in jsonCommander via calling checkLogin
  799. Json::Value login;
  800. login["login"] = true;
  801. login["user"] = "positive";
  802. login["pass"] = "positive";
  803. login["cancel"] = false;
  804. JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
  805. EXPECT_TRUE(loginRes.json["accept"].asBool());
  806. EXPECT_EQ(loginRes.json["error"].asString(), "");
  807. // now the actual test
  808. const std::string command = "deleteme";
  809. Json::Value message;
  810. message["command"] = command;
  811. message["pass"] = "negative";
  812. JsonCommander::Response response = jsonCommander.execute(message);
  813. EXPECT_EQ(response.action, JsonCommander::Action::send);
  814. EXPECT_EQ(response.json["command"].asString(), command);
  815. EXPECT_FALSE(response.json["accept"].asBool());
  816. EXPECT_NE(response.json["error"].asString(), "");
  817. }
  818. TEST(Deleteme, InvalidRequest) {
  819. FileManagerMock fileManager;
  820. JsonCommander jsonCommander(fileManager);
  821. // need to set currentUser in jsonCommander via calling checkLogin
  822. Json::Value login;
  823. login["login"] = true;
  824. login["user"] = "positive";
  825. login["pass"] = "positive";
  826. login["cancel"] = false;
  827. JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
  828. EXPECT_TRUE(loginRes.json["accept"].asBool());
  829. EXPECT_EQ(loginRes.json["error"].asString(), "");
  830. // now the actual test
  831. const std::string command = "deleteme";
  832. Json::Value message;
  833. message["command"] = command;
  834. message["pass"] = 123;
  835. JsonCommander::Response response = jsonCommander.execute(message);
  836. EXPECT_EQ(response.action, JsonCommander::Action::closeAndSend);
  837. EXPECT_EQ(response.json["command"].asString(), command);
  838. EXPECT_FALSE(response.json["accept"].asBool());
  839. EXPECT_NE(response.json["error"].asString(), "");
  840. }
  841. TEST(DeleteFile, Positive) {
  842. FileManagerMock fileManager;
  843. JsonCommander jsonCommander(fileManager);
  844. const std::string command = "deletefile";
  845. const std::string file = "asdf.txt";
  846. Json::Value message;
  847. message["command"] = command;
  848. message["file"] = file;
  849. EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_error));
  850. JsonCommander::Response response = jsonCommander.execute(message);
  851. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  852. EXPECT_EQ(response.json["command"].asString(), command);
  853. EXPECT_EQ(response.json["file"].asString(), file);
  854. EXPECT_TRUE(response.json["accept"].asBool());
  855. EXPECT_EQ(response.json["error"].asString(), "");
  856. }
  857. TEST(DeleteFile, InvalidRequest) {
  858. FileManagerMock fileManager;
  859. JsonCommander jsonCommander(fileManager);
  860. const std::string command = "deletefile";
  861. const int file = 3641;
  862. Json::Value message;
  863. message["command"] = command;
  864. message["file"] = file;
  865. JsonCommander::Response response = jsonCommander.execute(message);
  866. EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
  867. EXPECT_EQ(response.json["command"].asString(), command);
  868. EXPECT_EQ(response.json["file"].asString(), "");
  869. EXPECT_FALSE(response.json["accept"].asBool());
  870. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  871. }
  872. TEST(DeleteFile, FileDoesNotExist) {
  873. FileManagerMock fileManager;
  874. JsonCommander jsonCommander(fileManager);
  875. const std::string command = "deletefile";
  876. const std::string file = "asdf.txt";
  877. Json::Value message;
  878. message["command"] = command;
  879. message["file"] = file;
  880. EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_such_file));
  881. JsonCommander::Response response = jsonCommander.execute(message);
  882. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  883. EXPECT_EQ(response.json["command"].asString(), command);
  884. EXPECT_EQ(response.json["file"].asString(), file);
  885. EXPECT_FALSE(response.json["accept"].asBool());
  886. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  887. }
  888. TEST(DeleteFile, DisabledInConfig) {
  889. FileManagerMock fileManager;
  890. JsonCommander jsonCommander(fileManager);
  891. const std::string command = "deletefile";
  892. const std::string file = "asdf.txt";
  893. Json::Value message;
  894. message["command"] = command;
  895. message["file"] = file;
  896. EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::not_allowed));
  897. JsonCommander::Response response = jsonCommander.execute(message);
  898. EXPECT_TRUE(response.action == JsonCommander::Action::send);
  899. EXPECT_EQ(response.json["command"].asString(), command);
  900. EXPECT_EQ(response.json["file"].asString(), file);
  901. EXPECT_FALSE(response.json["accept"].asBool());
  902. EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
  903. }
  904. } // namespace