Browse Source

Merge branch '99-there-are-no-tests-for-executequeue-and-executedequeue' into 'develop'

Resolve "There are no tests for executeQueue and executeDequeue"

Closes #99

See merge request tobias.wach/ccats!104
Sander, Paul 4 years ago
parent
commit
d68c02a34b
2 changed files with 113 additions and 7 deletions
  1. 111 1
      daemon/test/JsonCommanderTest.cpp
  2. 2 6
      daemon/test/QueueMock.cpp

+ 111 - 1
daemon/test/JsonCommanderTest.cpp

@@ -1011,7 +1011,9 @@ TEST(Head, FileTooSmall) {
 	message["file"] = file;
 
 	std::vector<char> bytes;
-	EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).Times(2).WillRepeatedly(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
+	EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_))
+	    .Times(2)
+	    .WillRepeatedly(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
 
 	JsonCommander::Response response = jsonCommander.execute(message);
 
@@ -1724,4 +1726,112 @@ TEST(ExtendedListData, InvalidRequest) {
 	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
 }
 
+TEST(Queue, InvalidRequest) {
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "queue";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = 5;
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), "");
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+}
+
+TEST(Queue, PushToQueueFailed) {
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "queue";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = "negative";
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), "negative");
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+}
+
+TEST(Queue, Positive) {
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "queue";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = "positive";
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), "positive");
+	EXPECT_EQ(response.json["error"].asString(), "");
+}
+
+TEST(Dequeue, InvalidRequest) {
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "dequeue";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = 5;
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), "");
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+}
+
+TEST(Dequeue, QueueRemoveFailed) {
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "dequeue";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = "negative";
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), "negative");
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+}
+
+TEST(Dequeue, Positive) {
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "dequeue";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = "positive";
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), "positive");
+	EXPECT_EQ(response.json["error"].asString(), "");
+}
+
 } // namespace

+ 2 - 6
daemon/test/QueueMock.cpp

@@ -6,13 +6,9 @@ std::string fileName = "";
 ChannelControls *channel;
 } // namespace Queue
 
-bool Queue::push(const std::string &file) {
-	queue.push_back(file);
+bool Queue::push(const std::string &file) { return file == "positive"; }
 
-	return true;
-}
-
-bool Queue::remove(const std::string &file) { return true; }
+bool Queue::remove(const std::string &file) { return file == "positive"; }
 
 void Queue::schedule() {}