1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.onap.aaf.cadi.aaf;
\r
24 import static org.junit.Assert.*;
\r
26 import org.junit.Test;
\r
30 import static org.hamcrest.CoreMatchers.is;
\r
31 import static org.junit.Assert.*;
\r
32 import static org.mockito.Mockito.when;
\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
41 public class JU_AAFPermissionTest {
\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
48 private String STRINGVALUE =
\r
49 "AAFPermission:\n\tType: " + TYPE +
\r
50 "\n\tInstance: " + INSTANCE +
\r
51 "\n\tAction: " + ACTION +
\r
55 private LocalPermission localPermission;
\r
58 private LocalPermission localPermission2;
\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
68 public void test() {
\r
69 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
71 assertTrue("This should Match",permission.match(permission));
\r
73 assertTrue("This should Match", permission.match(localPermission));
\r
75 assertFalse("This should Not Match", permission.match(localPermission2));
\r
77 assertThat(permission.getKey(), is(KEY));
\r
79 assertThat(permission.permType(), is("AAF"));
\r
81 assertThat(permission.toString(), is(STRINGVALUE));
\r
86 public void test4() {
\r
87 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
89 assertTrue("This should Match",permission.match(permission));
\r
91 assertTrue("This should Match", permission.match(localPermission));
\r
93 assertFalse("This should Not Match", permission.match(localPermission2));
\r
95 assertThat(permission.getKey(), is(KEY));
\r
97 assertThat(permission.permType(), is("AAF"));
\r
99 assertThat(permission.toString(), is(STRINGVALUE));
\r
104 public void test1() {
\r
105 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
107 assertTrue("This should Match",permission.match(permission));
\r
109 assertTrue("This should Match", permission.match(localPermission));
\r
111 assertFalse("This should Not Match", permission.match(localPermission2));
\r
113 assertThat(permission.getKey(), is(KEY));
\r
115 assertThat(permission.permType(), is("AAF"));
\r
117 assertThat(permission.toString(), is(STRINGVALUE));
\r
122 public void test2() {
\r
123 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
125 assertTrue("This should Match",permission.match(permission));
\r
127 assertTrue("This should Match", permission.match(localPermission));
\r
129 assertFalse("This should Not Match", permission.match(localPermission2));
\r
131 assertThat(permission.getKey(), is(KEY));
\r
133 assertThat(permission.permType(), is("AAF"));
\r
135 assertThat(permission.toString(), is(STRINGVALUE));
\r
141 public void test3() {
\r
142 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
144 assertTrue("This should Match",permission.match(permission));
\r
146 assertTrue("This should Match", permission.match(localPermission));
\r
148 assertFalse("This should Not Match", permission.match(localPermission2));
\r
150 assertThat(permission.getKey(), is(KEY));
\r
152 assertThat(permission.permType(), is("AAF"));
\r
154 assertThat(permission.toString(), is(STRINGVALUE));
\r
159 public void test5() {
\r
160 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
162 assertTrue("This should Match",permission.match(permission));
\r
164 assertTrue("This should Match", permission.match(localPermission));
\r
166 assertFalse("This should Not Match", permission.match(localPermission2));
\r
168 assertThat(permission.getKey(), is(KEY));
\r
170 assertThat(permission.permType(), is("AAF"));
\r
172 assertThat(permission.toString(), is(STRINGVALUE));
\r
177 public void test6() {
\r
178 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
180 assertTrue("This should Match",permission.match(permission));
\r
182 assertTrue("This should Match", permission.match(localPermission));
\r
184 assertFalse("This should Not Match", permission.match(localPermission2));
\r
186 assertThat(permission.getKey(), is(KEY));
\r
188 assertThat(permission.permType(), is("AAF"));
\r
190 assertThat(permission.toString(), is(STRINGVALUE));
\r
195 public void test7() {
\r
196 AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);
\r
198 assertTrue("This should Match",permission.match(permission));
\r
200 assertTrue("This should Match", permission.match(localPermission));
\r
202 assertFalse("This should Not Match", permission.match(localPermission2));
\r
204 assertThat(permission.getKey(), is(KEY));
\r
206 assertThat(permission.permType(), is("AAF"));
\r
208 assertThat(permission.toString(), is(STRINGVALUE));
\r