Improve code coverage for aaf cadi modules
[aaf/cadi.git] / aaf / src / test / java / com / onap / aaf / cadi / aaf / AAFPermissionTest.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.onap.aaf.cadi.aaf;\r
24 import static org.junit.Assert.*;\r
25 \r
26 import org.junit.Test;\r
27 \r
28 \r
29 \r
30 import static org.hamcrest.CoreMatchers.is;\r
31 import static org.junit.Assert.*;\r
32 import static org.mockito.Mockito.when;\r
33 \r
34 import org.junit.Before;\r
35 import org.junit.Test;\r
36 import org.mockito.Mock;\r
37 import org.mockito.MockitoAnnotations;\r
38 import org.onap.aaf.cadi.aaf.AAFPermission;\r
39 import org.onap.aaf.cadi.lur.LocalPermission;\r
40 \r
41 public class AAFPermissionTest {\r
42 \r
43         private static final String INSTANCE = "*";\r
44         private static final String ACTION = "*";\r
45         private static final String TYPE = "Auth";\r
46         private static final String KEY =TYPE + '|' + INSTANCE + '|' + ACTION;\r
47         \r
48         private String STRINGVALUE =\r
49         "AAFPermission:\n\tType: " + TYPE + \r
50         "\n\tInstance: " + INSTANCE +\r
51         "\n\tAction: " + ACTION +\r
52         "\n\tKey: " + KEY;\r
53 \r
54         @Mock\r
55         private LocalPermission localPermission;\r
56         \r
57         @Mock\r
58         private LocalPermission localPermission2;\r
59 \r
60         @Before\r
61         public void setup() {\r
62                 MockitoAnnotations.initMocks(this);\r
63                 when(localPermission.getKey()).thenReturn(TYPE);\r
64                 when(localPermission2.getKey()).thenReturn(TYPE+" Default");\r
65         }\r
66         \r
67         @Test\r
68         public void test() {\r
69                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
70                 \r
71                 assertTrue("This should Match",permission.match(permission));\r
72                 \r
73                 assertTrue("This should Match", permission.match(localPermission));\r
74                 \r
75                 assertFalse("This should Not Match", permission.match(localPermission2));\r
76                 \r
77                 assertThat(permission.getKey(), is(KEY));\r
78                 \r
79                 assertThat(permission.permType(), is("AAF"));\r
80                 \r
81                 assertThat(permission.toString(), is(STRINGVALUE));\r
82                 \r
83         }\r
84         \r
85         @Test\r
86         public void test4() {\r
87                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
88                 \r
89                 assertTrue("This should Match",permission.match(permission));\r
90                 \r
91                 assertTrue("This should Match", permission.match(localPermission));\r
92                 \r
93                 assertFalse("This should Not Match", permission.match(localPermission2));\r
94                 \r
95                 assertThat(permission.getKey(), is(KEY));\r
96                 \r
97                 assertThat(permission.permType(), is("AAF"));\r
98                 \r
99                 assertThat(permission.toString(), is(STRINGVALUE));\r
100                 \r
101         }\r
102         \r
103         @Test\r
104         public void test1() {\r
105                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
106                 \r
107                 assertTrue("This should Match",permission.match(permission));\r
108                 \r
109                 assertTrue("This should Match", permission.match(localPermission));\r
110                 \r
111                 assertFalse("This should Not Match", permission.match(localPermission2));\r
112                 \r
113                 assertThat(permission.getKey(), is(KEY));\r
114                 \r
115                 assertThat(permission.permType(), is("AAF"));\r
116                 \r
117                 assertThat(permission.toString(), is(STRINGVALUE));\r
118                 \r
119         }\r
120         \r
121         @Test\r
122         public void test2() {\r
123                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
124                 \r
125                 assertTrue("This should Match",permission.match(permission));\r
126                 \r
127                 assertTrue("This should Match", permission.match(localPermission));\r
128                 \r
129                 assertFalse("This should Not Match", permission.match(localPermission2));\r
130                 \r
131                 assertThat(permission.getKey(), is(KEY));\r
132                 \r
133                 assertThat(permission.permType(), is("AAF"));\r
134                 \r
135                 assertThat(permission.toString(), is(STRINGVALUE));\r
136                 \r
137         }\r
138 \r
139         \r
140         @Test\r
141         public void test3() {\r
142                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
143                 \r
144                 assertTrue("This should Match",permission.match(permission));\r
145                 \r
146                 assertTrue("This should Match", permission.match(localPermission));\r
147                 \r
148                 assertFalse("This should Not Match", permission.match(localPermission2));\r
149                 \r
150                 assertThat(permission.getKey(), is(KEY));\r
151                 \r
152                 assertThat(permission.permType(), is("AAF"));\r
153                 \r
154                 assertThat(permission.toString(), is(STRINGVALUE));\r
155                 \r
156         }\r
157         \r
158         @Test\r
159         public void test5() {\r
160                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
161                 \r
162                 assertTrue("This should Match",permission.match(permission));\r
163                 \r
164                 assertTrue("This should Match", permission.match(localPermission));\r
165                 \r
166                 assertFalse("This should Not Match", permission.match(localPermission2));\r
167                 \r
168                 assertThat(permission.getKey(), is(KEY));\r
169                 \r
170                 assertThat(permission.permType(), is("AAF"));\r
171                 \r
172                 assertThat(permission.toString(), is(STRINGVALUE));\r
173                 \r
174         }\r
175         \r
176         @Test\r
177         public void test6() {\r
178                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
179                 \r
180                 assertTrue("This should Match",permission.match(permission));\r
181                 \r
182                 assertTrue("This should Match", permission.match(localPermission));\r
183                 \r
184                 assertFalse("This should Not Match", permission.match(localPermission2));\r
185                 \r
186                 assertThat(permission.getKey(), is(KEY));\r
187                 \r
188                 assertThat(permission.permType(), is("AAF"));\r
189                 \r
190                 assertThat(permission.toString(), is(STRINGVALUE));\r
191                 \r
192         }\r
193         \r
194         @Test\r
195         public void test7() {\r
196                 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
197                 \r
198                 assertTrue("This should Match",permission.match(permission));\r
199                 \r
200                 assertTrue("This should Match", permission.match(localPermission));\r
201                 \r
202                 assertFalse("This should Not Match", permission.match(localPermission2));\r
203                 \r
204                 assertThat(permission.getKey(), is(KEY));\r
205                 \r
206                 assertThat(permission.permType(), is("AAF"));\r
207                 \r
208                 assertThat(permission.toString(), is(STRINGVALUE));\r
209                 \r
210         }\r
211 }\r