Add unit tests for MonitorEntryPutRequest in ProtocolClient 23/238623/6
authorZofia Abramowska <z.abramowska@samsung.com>
Wed, 15 Jul 2020 16:03:31 +0000 (18:03 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 12 Aug 2020 08:59:07 +0000 (10:59 +0200)
Change-Id: Idb17089a5061fb81fdd2b842c7366f2dbf6821c1

test/CMakeLists.txt
test/common/protocols/client/monitorentryputrequest.cpp [new file with mode: 0644]

index d0abe7f1343be5b47a1bfb4ce9cd39c64884f6f5..5bfa9532691065686d9539c8d3b4c8e0e196ccc1 100644 (file)
@@ -155,6 +155,7 @@ SET(CYNARA_TESTS_SOURCES
     common/protocols/client/cancelrequest.cpp
     common/protocols/client/checkrequest.cpp
     common/protocols/client/monitorentriesputrequest.cpp
+    common/protocols/client/monitorentryputrequest.cpp
     common/protocols/client/protocolclient.cpp
     common/protocols/client/simplecheckrequest.cpp
     common/protocols/monitor/flushrequest.cpp
diff --git a/test/common/protocols/client/monitorentryputrequest.cpp b/test/common/protocols/client/monitorentryputrequest.cpp
new file mode 100644 (file)
index 0000000..263ae31
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This file is licensed under the terms of MIT License or the Apache License
+ * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
+ * See the LICENSE file or the notice below for Apache License Version 2.0
+ * details.
+ *
+ * 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/client/monitorentryputrequest.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::MonitorPutEntryRequest usage in Cynara::ProtocolClient
+ */
+
+#include <gtest/gtest.h>
+
+#include <cynara-limits.h>
+#include <exceptions/InvalidProtocolException.h>
+#include <protocol/ProtocolClient.h>
+#include <request/MonitorEntryPutRequest.h>
+
+#include "../helpers.h"
+#include <CommonsTestHelper.h>
+#include <NegativeTestHelper.h>
+#include <RequestTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::MonitorEntryPutRequest &req1,
+             const Cynara::MonitorEntryPutRequest &req2) {
+    EXPECT_EQ(req1.monitorEntry(), req2.monitorEntry());
+    EXPECT_EQ(req1.sequenceNumber(), req2.sequenceNumber());
+}
+
+} /* namespace anonymous */
+
+using namespace Cynara;
+using namespace NegativeTestHelper;
+using namespace RequestTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolClient, MonitorEntryPutRequestPositive) {
+    for (auto &key : Keys::all) {
+        for (auto &result : Monitor::EntryResult::all) {
+            for (auto &sec : Times::Sec::all) {
+                for (auto &nsec : Times::NSec::all) {
+                    MonitorEntry entry(key, result, {sec, nsec});
+                    for (auto &sequenceNumber : SN::all) {
+                        auto request = std::make_shared<MonitorEntryPutRequest>
+                            (entry, sequenceNumber);
+                        auto protocol = std::make_shared<ProtocolClient>();
+                        testRequest(request, protocol);
+                    }
+                }
+            }
+        }
+    }
+}
+
+TEST(ProtocolClient, MonitorEntryPutRequestBinaryPositive) {
+    for (auto &key : Keys::all) {
+        for (auto &result : Monitor::EntryResult::all) {
+            for (auto &sec : Times::Sec::all) {
+                for (auto &nsec : Times::NSec::all) {
+                    MonitorEntry entry(key, result, {sec, nsec});
+                    for (auto &sequenceNumber : SN::all) {
+                        auto request = std::make_shared<MonitorEntryPutRequest>
+                            (entry, sequenceNumber);
+                        auto protocol = std::make_shared<ProtocolClient>();
+                        binaryTestRequest(request, protocol);
+                    }
+                }
+            }
+        }
+    }
+}
+
+TEST(ProtocolClient, MonitorEntryPutRequestTooLongClientNegative) {
+    MonitorEntry entry(PolicyKey(PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'c')),
+                                 Keys::k_nua.user(), Keys::k_nua.privilege()),
+                       Monitor::EntryResult::mid,
+                       {Times::Sec::min, Times::NSec::min});
+
+    testInvalidProtocol<ProtocolClient, MonitorEntryPutRequest>(entry, SN::mid);
+}
+
+TEST(ProtocolClient, MonitorEntryPutRequestTooLongUserNegative) {
+    MonitorEntry entry(PolicyKey(Keys::k_www.client(),
+                                 PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'u')),
+                                 Keys::k_www.privilege()),
+                       Monitor::EntryResult::mid,
+                       {Times::Sec::min, Times::NSec::min});
+
+    testInvalidProtocol<ProtocolClient, MonitorEntryPutRequest>(entry, SN::max);
+}
+
+TEST(ProtocolClient, MonitorEntryPutRequestTooLongPrivilegeNegative) {
+    MonitorEntry entry(PolicyKey(Keys::k_wua.client(), Keys::k_cup.user(),
+                                 PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'p'))),
+                       Monitor::EntryResult::mid,
+                       {Times::Sec::min, Times::NSec::min});
+
+    testInvalidProtocol<ProtocolClient, MonitorEntryPutRequest>(entry, SN::min);
+}