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 org.onap.aaf.cadi;
\r
25 import static org.hamcrest.CoreMatchers.is;
\r
26 import static org.junit.Assert.*;
\r
27 import static org.mockito.Mockito.when;
\r
29 import java.security.Principal;
\r
30 import java.util.ArrayList;
\r
31 import java.util.HashMap;
\r
32 import java.util.List;
\r
33 import java.util.Map;
\r
35 import org.junit.Before;
\r
36 import org.junit.Test;
\r
37 import org.mockito.Mock;
\r
38 import org.mockito.MockitoAnnotations;
\r
39 import org.onap.aaf.cadi.lur.LocalPermission;
\r
41 public class UserTest {
\r
44 private Principal principal;
\r
47 private LocalPermission permission;
\r
50 public void setup() {
\r
51 MockitoAnnotations.initMocks(this);
\r
53 when(principal.getName()).thenReturn("Principal");
\r
55 when(permission.getKey()).thenReturn("NewKey");
\r
56 when(permission.match(permission)).thenReturn(true);
\r
60 public void testCountCheck() {
\r
61 User<Permission> user = new User<Permission>(principal);
\r
63 assertThat(user.count, is(0));
\r
65 assertThat(user.count, is(1));
\r
69 public void testPerm() throws InterruptedException {
\r
70 User<Permission> user = new User<Permission>(principal);
\r
71 assertThat(user.permExpires(), is(Long.MAX_VALUE));
\r
74 assertThat(user.permExpired(), is(true));
\r
75 user = new User<Permission>(principal,100);
\r
76 assertTrue(user.noPerms());
\r
77 user.add(permission);
\r
78 assertFalse(user.noPerms());
\r
80 assertThat(user.permExpired(), is(false));
\r
81 assertFalse(user.permsUnloaded());
\r
83 assertTrue(user.permsUnloaded());
\r
84 assertTrue(user.noPerms());
\r
88 public void testAddValuesToNewMap() {
\r
89 User<Permission> user = new User<Permission>(principal);
\r
90 Map<String, Permission> newMap = new HashMap<String,Permission>();
\r
92 assertFalse(user.contains(permission));
\r
94 user.add(newMap, permission);
\r
95 user.setMap(newMap);
\r
97 assertTrue(user.contains(permission));
\r
99 List<Permission> sink = new ArrayList<Permission>();
\r
100 user.copyPermsTo(sink);
\r
102 assertThat(sink.size(), is(1));
\r
103 assertTrue(sink.contains(permission));
\r
105 assertThat(user.toString(), is("Principal|:NewKey"));
\r