Merge "Remove CLM issues with commons-collections"
[policy/engine.git] / ONAP-SDK-APP / src / test / java / org / onap / portalapp / service / AdminAuthExtensionTest.java
1 /*-
2  * ================================================================================
3  * ONAP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.onap.portalapp.service;
21
22 import static org.junit.Assert.*;
23
24 import java.util.SortedSet;
25 import java.util.TreeSet;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mockito;
30 import org.onap.policy.rest.dao.CommonClassDao;
31 import org.onap.portalsdk.core.domain.Role;
32 import org.onap.portalsdk.core.domain.User;
33
34 public class AdminAuthExtensionTest {
35
36         private CommonClassDao commonClassDao;
37         private AdminAuthExtension extension;
38         private User user;
39
40
41         @Before
42         public void setUp(){
43                 extension = new AdminAuthExtension();
44                 commonClassDao = Mockito.mock(CommonClassDao.class);
45                 Mockito.doNothing().when(commonClassDao).updateQuery("");
46                 Mockito.doNothing().when(commonClassDao).save(new Object());
47                 extension.setCommonClassDao(commonClassDao);
48                 user = new User();
49                 user.setFirstName("Test");
50                 user.setLoginId("Test");
51         }
52
53         @Test
54         public void testAdminAuthExtension(){
55                 try{
56                         callSaveUserFunction("Policy Super Admin");
57                         callSaveUserFunction("Policy Super Editor");
58                         callSaveUserFunction("Policy Super Guest");
59                         callSaveUserFunction("Policy Admin");
60                         callSaveUserFunction("Policy Editor");
61                         callSaveUserFunction("Policy Guest");
62                         extension.editUserExtension(user);
63                         extension.saveUserRoleExtension(null, user);
64                 }catch(Exception e){
65                         fail("Not Expecting any exception.");
66                 }
67         }
68
69         @Test
70         public void expectException(){
71                 try{
72                         extension.saveUserExtension(null);
73                 }catch(Exception e){
74                         assertEquals(NullPointerException.class, e.getClass());
75                 }
76         }
77
78         public void callSaveUserFunction(String roleName){
79                 SortedSet<Role> roles = new TreeSet<>();
80                 Role role = new Role();
81                 role.setName(roleName);
82                 roles.add(role);
83                 user.setRoles(roles);
84                 extension.saveUserExtension(user);
85         }
86 }