2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.onap.portalapp.service;
22 import static org.junit.Assert.*;
24 import java.util.SortedSet;
25 import java.util.TreeSet;
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;
34 public class AdminAuthExtensionTest {
36 private CommonClassDao commonClassDao;
37 private AdminAuthExtension extension;
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);
49 user.setFirstName("Test");
50 user.setLoginId("Test");
54 public void testAdminAuthExtension(){
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);
65 fail("Not Expecting any exception.");
70 public void expectException(){
72 extension.saveUserExtension(null);
74 assertEquals(NullPointerException.class, e.getClass());
78 public void callSaveUserFunction(String roleName){
79 SortedSet<Role> roles = new TreeSet<>();
80 Role role = new Role();
81 role.setName(roleName);
84 extension.saveUserExtension(user);