--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file test/common/protocols/agent/protocolagent.cpp
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @version 1.0
+ * @brief Negative tests for Cynara::ProtocolAgent
+ */
+
+#include <gtest/gtest.h>
+
+#include <exceptions/NotImplementedException.h>
+
+#include <protocol/ProtocolAgent.h>
+
+#include <request/AdminCheckRequest.h>
+#include <request/CancelRequest.h>
+#include <request/CheckRequest.h>
+#include <request/DescriptionListRequest.h>
+#include <request/EraseRequest.h>
+#include <request/InsertOrUpdateBucketRequest.h>
+#include <request/ListRequest.h>
+#include <request/MonitorEntriesPutRequest.h>
+#include <request/MonitorEntryPutRequest.h>
+#include <request/MonitorGetEntriesRequest.h>
+#include <request/MonitorGetFlushRequest.h>
+#include <request/RemoveBucketRequest.h>
+#include <request/SetPoliciesRequest.h>
+#include <request/SignalRequest.h>
+#include <request/SimpleCheckRequest.h>
+
+#include <response/AdminCheckResponse.h>
+#include <response/CancelResponse.h>
+#include <response/CheckResponse.h>
+#include <response/CodeResponse.h>
+#include <response/DescriptionListResponse.h>
+#include <response/ListResponse.h>
+#include <response/MonitorGetEntriesResponse.h>
+#include <response/SimpleCheckResponse.h>
+
+#include <NegativeTestHelper.h>
+#include <TestDataCollection.h>
+
+using namespace Cynara;
+using namespace NegativeTestHelper;
+using namespace TestDataCollection;
+
+namespace {
+
+const struct timespec SOME_TIMESPEC = {Times::Sec::mid, Times::NSec::max};
+const MonitorEntry SOME_ENTRY(Keys::k_nun, 42, SOME_TIMESPEC);
+const std::vector<MonitorEntry> SOME_ENTRIES = {{SOME_ENTRY}};
+
+} /* namespace anonymous */
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAgent, AdminCheckRequestNegative) {
+ testNotImplemented<ProtocolAgent, AdminCheckRequest>
+ (Keys::k_aaa, Buckets::empty, false, SN::mid);
+}
+
+TEST(ProtocolAgent, CancelRequestNegative) {
+ testNotImplemented<ProtocolAgent, CancelRequest>(SN::max);
+}
+
+TEST(ProtocolAgent, CheckRequestNegative) {
+ testNotImplemented<ProtocolAgent, CheckRequest>(Keys::k_cuw, SN::min);
+}
+
+TEST(ProtocolAgent, DescriptionListRequestNegative) {
+ testNotImplemented<ProtocolAgent, DescriptionListRequest>(SN::max_1);
+}
+
+TEST(ProtocolAgent, EraseRequestNegative) {
+ testNotImplemented<ProtocolAgent, EraseRequest>
+ (Buckets::not_empty, false, Keys::k_wwp, SN::min_2);
+}
+
+TEST(ProtocolAgent, InsertOrUpdateBucketRequestNegative) {
+ testNotImplemented<ProtocolAgent, InsertOrUpdateBucketRequest>
+ (Buckets::not_empty, Results::plugin_1, SN::min_1);
+}
+
+TEST(ProtocolAgent, ListRequestNegative) {
+ testNotImplemented<ProtocolAgent, ListRequest>(Buckets::empty, Keys::k_cww, SN::max_2);
+}
+
+TEST(ProtocolAgent, MonitorGetEntriesRequestNegative) {
+ testNotImplemented<ProtocolAgent, MonitorGetEntriesRequest>(Buffer::Size::min_2, SN::min_1);
+}
+
+TEST(ProtocolAgent, MonitorGetFlushRequestNegative) {
+ testNotImplemented<ProtocolAgent, MonitorGetFlushRequest>(SN::mid);
+}
+
+TEST(ProtocolAgent, MonitorEntriesPutRequestNegative) {
+ testNotImplemented<ProtocolAgent, MonitorEntriesPutRequest>(SOME_ENTRIES, SN::min_2);
+}
+
+TEST(ProtocolAgent, MonitorEntryPutRequestNegative) {
+ testNotImplemented<ProtocolAgent, MonitorEntryPutRequest>(SOME_ENTRY, SN::max_1);
+}
+
+TEST(ProtocolAgent, RemoveBucketRequestNegative) {
+ testNotImplemented<ProtocolAgent, RemoveBucketRequest>(Buckets::not_empty, SN::max);
+}
+
+TEST(ProtocolAgent, SetPoliciesRequestNegative) {
+ const std::map<PolicyBucketId, std::vector<Policy>> SOME_INSERT_POLICY =
+ {{Buckets::not_empty, {{Keys::k_nua, Results::deny}}}};
+ const std::map<PolicyBucketId, std::vector<PolicyKey>> SOME_REMOVE_POLICY =
+ {{Buckets::empty, {Keys::k_nun}}};
+ testNotImplemented<ProtocolAgent, SetPoliciesRequest>
+ (SOME_INSERT_POLICY, SOME_REMOVE_POLICY, SN::min);
+}
+
+TEST(ProtocolAgent, SignalRequestNegative) {
+ const struct signalfd_siginfo SOME_SIGINFO = {};
+ testNotImplemented<ProtocolAgent, SignalRequest>(SOME_SIGINFO);
+}
+
+TEST(ProtocolAgent, SimpleCheckRequestNegative) {
+ testNotImplemented<ProtocolAgent, SimpleCheckRequest>(Keys::k_aup, SN::mid);
+}
+
+TEST(ProtocolAgent, AdminCheckResponseNegative) {
+ testNotImplemented<ProtocolAgent, AdminCheckResponse>
+ (Results::plugin_2, false, false, SN::min);
+}
+
+TEST(ProtocolAgent, CancelResponseNegative) {
+ testNotImplemented<ProtocolAgent, CancelResponse>(SN::min_2);
+}
+
+TEST(ProtocolAgent, CheckResponseNegative) {
+ testNotImplemented<ProtocolAgent, CheckResponse>(Results::bucket_not_empty, SN::min_2);
+}
+
+TEST(ProtocolAgent, CodeResponseNegative) {
+ testNotImplemented<ProtocolAgent, CodeResponse>(CodeResponse::NOT_ALLOWED, SN::max_1);
+}
+
+TEST(ProtocolAgent, DescriptionListResponseNegative) {
+ const std::vector<PolicyDescription> SOME_DESCRIPTIONS = {{Types::plugin_type, "plugin_type"}};
+ testNotImplemented<ProtocolAgent, DescriptionListResponse>(SOME_DESCRIPTIONS, true, SN::mid);
+}
+
+TEST(ProtocolAgent, ListResponseNegative) {
+ const std::vector<Policy> SOME_POLICIES = {{Keys::k_wwa, Results::none}};
+ testNotImplemented<ProtocolAgent, ListResponse>(SOME_POLICIES, true, false, SN::max_2);
+}
+
+TEST(ProtocolAgent, MonitorGetEntriesResponseNegative) {
+ testNotImplemented<ProtocolAgent, MonitorGetEntriesResponse>(SOME_ENTRIES, SN::max);
+}
+
+TEST(ProtocolAgent, SimpleCheckResponseNegative) {
+ testNotImplemented<ProtocolAgent, SimpleCheckResponse>
+ (42, Results::bucket_not_empty, SN::min_2);
+}
+
+TEST(ProtocolAgent, WrongOpCodeRequestNegative) {
+ auto queue = prepareWrongOpCode();
+ auto protocol = std::make_shared<ProtocolAgent>();
+ ASSERT_THROW(protocol->extractRequestFromBuffer(queue), InvalidProtocolException);
+}
+
+TEST(ProtocolAgent, WrongOpCodeResponseNegative) {
+ auto queue = prepareWrongOpCode();
+ auto protocol = std::make_shared<ProtocolAgent>();
+ ASSERT_THROW(protocol->extractResponseFromBuffer(queue), InvalidProtocolException);
+}
+
+TEST(ProtocolAgent, UnfinishedFrameRequestNegative) {
+ auto queue = prepareUnfinishedFrame();
+ auto protocol = std::make_shared<ProtocolAgent>();
+ ASSERT_EQ(protocol->extractRequestFromBuffer(queue), nullptr);
+}
+
+TEST(ProtocolAgent, UnfinishedFrameResponseNegative) {
+ auto queue = prepareUnfinishedFrame();
+ auto protocol = std::make_shared<ProtocolAgent>();
+ ASSERT_EQ(protocol->extractResponseFromBuffer(queue), nullptr);
+}
+