9ca740308c96fb286bb59b638b0cf3fce0409ddc
[platform/core/security/cynara.git] / test / storage / inmemorystoragebackend / buckets.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        buckets.cpp
18  * @author      Aleksander Zdyb <a.zdyb@partner.samsung.com>
19  * @version     1.0
20  * @brief       Tests of buckets in InMemeoryStorageBackend
21  */
22
23 #include "gmock/gmock.h"
24
25 #include "inmemeorystoragebackendfixture.h"
26 #include "fakeinmemorystoragebackend.h"
27
28 #include "common/types/PolicyResult.h"
29 #include "common/types/PolicyBucket.h"
30
31 using namespace Cynara;
32
33 TEST_F(InMemeoryStorageBackendFixture, addBucket) {
34     using ::testing::ReturnRef;
35     using ::testing::IsEmpty;
36
37     FakeInMemoryStorageBackend backend;
38     EXPECT_CALL(backend, buckets())
39         .WillOnce(ReturnRef(m_buckets));
40
41     PolicyResult defaultPolicy(PolicyType::ALLOW);
42     PolicyBucketId bucketId = "new-bucket";
43     backend.createBucket(bucketId, defaultPolicy);
44
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());
49 }
50
51
52 TEST_F(InMemeoryStorageBackendFixture, deleteBucket) {
53     using ::testing::ReturnRef;
54     using ::testing::IsEmpty;
55
56     FakeInMemoryStorageBackend backend;
57     EXPECT_CALL(backend, buckets())
58         .WillOnce(ReturnRef(m_buckets));
59
60     PolicyBucketId bucketId = "delete-bucket";
61     m_buckets.insert({ bucketId, PolicyBucket() });
62
63     backend.deleteBucket(bucketId);
64
65     ASSERT_THAT(m_buckets, IsEmpty());
66 }
67
68 TEST_F(InMemeoryStorageBackendFixture, deleteNonexistentBucket) {
69     using ::testing::ReturnRef;
70
71     FakeInMemoryStorageBackend backend;
72     EXPECT_CALL(backend, buckets())
73         .WillOnce(ReturnRef(m_buckets));
74
75     EXPECT_THROW(backend.deleteBucket("non-existent"), BucketNotExistsException);
76 }