2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
20 * @brief Tests of buckets in InMemeoryStorageBackend
23 #include "gmock/gmock.h"
25 #include "inmemeorystoragebackendfixture.h"
26 #include "fakeinmemorystoragebackend.h"
28 #include "common/types/PolicyResult.h"
29 #include "common/types/PolicyBucket.h"
31 using namespace Cynara;
33 TEST_F(InMemeoryStorageBackendFixture, addBucket) {
34 using ::testing::ReturnRef;
35 using ::testing::IsEmpty;
37 FakeInMemoryStorageBackend backend;
38 EXPECT_CALL(backend, buckets())
39 .WillOnce(ReturnRef(m_buckets));
41 PolicyResult defaultPolicy(PredefinedPolicyType::ALLOW);
42 PolicyBucketId bucketId = "new-bucket";
43 backend.createBucket(bucketId, defaultPolicy);
45 ASSERT_EQ(1, m_buckets.size());
46 ASSERT_NE(m_buckets.end(), m_buckets.find(bucketId));
47 ASSERT_EQ(defaultPolicy, m_buckets.at(bucketId).defaultPolicy());
48 ASSERT_THAT(m_buckets.at(bucketId).policyCollection(), IsEmpty());
52 TEST_F(InMemeoryStorageBackendFixture, deleteBucket) {
53 using ::testing::ReturnRef;
54 using ::testing::IsEmpty;
56 FakeInMemoryStorageBackend backend;
57 EXPECT_CALL(backend, buckets())
58 .WillOnce(ReturnRef(m_buckets));
60 PolicyBucketId bucketId = "delete-bucket";
61 m_buckets.insert({ bucketId, PolicyBucket() });
63 backend.deleteBucket(bucketId);
65 ASSERT_THAT(m_buckets, IsEmpty());
68 TEST_F(InMemeoryStorageBackendFixture, deleteNonexistentBucket) {
69 using ::testing::ReturnRef;
71 FakeInMemoryStorageBackend backend;
72 EXPECT_CALL(backend, buckets())
73 .WillOnce(ReturnRef(m_buckets));
75 EXPECT_THROW(backend.deleteBucket("non-existent"), BucketNotExistsException);