2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.controller;
43 import static org.junit.jupiter.api.Assertions.*;
46 import java.io.FileNotFoundException;
47 import java.io.FileReader;
48 import java.sql.Connection;
49 import java.sql.SQLException;
50 import java.time.LocalDateTime;
51 import java.util.Arrays;
52 import java.util.Collections;
53 import java.util.HashSet;
54 import javax.persistence.EntityManager;
55 import javax.persistence.EntityManagerFactory;
56 import javax.persistence.Persistence;
57 import javax.sql.DataSource;
58 import org.h2.tools.RunScript;
59 import org.hibernate.Session;
60 import org.hibernate.jdbc.Work;
61 import org.junit.Before;
62 import org.junit.BeforeClass;
63 import org.junit.Ignore;
64 import org.junit.jupiter.api.Test;
65 import org.junit.runner.RunWith;
66 import org.onap.portal.domain.db.fn.FnApp;
67 import org.onap.portal.domain.db.fn.FnLanguage;
68 import org.onap.portal.domain.db.fn.FnRole;
69 import org.onap.portal.domain.db.fn.FnUser;
70 import org.onap.portal.domain.db.fn.FnUserRole;
71 import org.onap.portal.service.fn.FnAppService;
72 import org.onap.portal.service.fn.FnLanguageService;
73 import org.onap.portal.service.fn.FnLuTimezoneService;
74 import org.onap.portal.service.fn.FnRoleService;
75 import org.onap.portal.service.fn.FnUserRoleService;
76 import org.onap.portal.service.fn.FnUserService;
77 import org.springframework.beans.factory.annotation.Autowired;
78 import org.springframework.boot.test.context.SpringBootTest;
79 import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
80 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
81 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
82 import org.springframework.test.context.TestPropertySource;
83 import org.springframework.test.context.junit4.SpringRunner;
84 import org.springframework.test.web.servlet.MockMvc;
85 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
86 import org.springframework.transaction.annotation.Transactional;
87 import org.springframework.web.context.WebApplicationContext;
89 @RunWith(SpringRunner.class)
92 @TestPropertySource(locations = "classpath:test.properties")
93 class UserRolesControllerTest {
95 private UserRolesController userRolesController;
97 private FnUserService fnUserService;
99 private FnUserRoleService fnUserRoleService;
101 private FnLanguageService fnLanguageService;
103 private FnAppService fnAppService;
105 private FnRoleService fnRoleService;
108 void checkIfUserIsSuperAdminFalse() {
109 UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("ps0001",
112 boolean expected = false;
114 boolean actual = userRolesController.checkIfUserIsSuperAdmin(principal);
116 assertEquals(expected, actual);
120 void checkIfUserIsSuperAdminTrue() {
121 UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
124 boolean expected = true;
126 boolean actual = userRolesController.checkIfUserIsSuperAdmin(principal);
128 assertEquals(expected, actual);