2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.core.service;
40 import java.io.IOException;
41 import java.util.List;
43 import org.junit.Assert;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mock;
48 import org.mockito.Mockito;
49 import org.onap.portalsdk.core.domain.Role;
50 import org.onap.portalsdk.core.domain.RoleFunction;
51 import org.powermock.modules.junit4.PowerMockRunner;
53 @RunWith(PowerMockRunner.class)
54 public class RoleServiceCentralizedAccessTest {
57 private RoleServiceCentralizedAccess roleServiceCntrlAccess;
60 private RestApiRequestBuilder restApiRequestBuilder;
63 public void getRoleFunctionsTest() throws Exception {
64 String loginId ="1234";
65 String response ="[ { \"code\" : \"abc\", \"name\" : \"xyz\" }, { \"code\" : \"pqr\", \"name\" : \"str\" } ]";
66 Mockito.when(restApiRequestBuilder.getViaREST("/functions", true, loginId)).thenReturn(response);
67 List<RoleFunction> roleFunctions = roleServiceCntrlAccess.getRoleFunctions(loginId);
68 Assert.assertTrue(roleFunctions.size() > 0);
72 public void getAvailableChildRolesWithEmptyRoleIdTest() throws Exception {
73 String loginId = "123";
75 String response ="[ { \"active\" : true, \"name\" : \"xyz\" } ]";
76 Mockito.when(restApiRequestBuilder.getViaREST("/roles", true, loginId)).thenReturn(response);
77 List<Role> roles = roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId);
78 Assert.assertNotNull(roles);
82 public void getAvailableChildRolesWithZeroRoleIdTest() throws Exception {
83 String loginId = "123";
85 String response ="[ { \"active\" : true, \"name\" : \"xyz\" } ]";
86 Mockito.when(restApiRequestBuilder.getViaREST("/roles", true, loginId)).thenReturn(response);
87 List<Role> roles = roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId);
88 Assert.assertNotNull(roles);
92 public void getAvailableChildRolesTest() throws Exception {
93 String loginId = "123";
95 String response ="[ { \"active\" : false, \"name\" : \"xyz\" } ]";
96 Mockito.when(restApiRequestBuilder.getViaREST("/roles", true, loginId)).thenReturn(response);
97 String roleResponse =" { \"active\" : true, \"name\" : \"xyz\", \"roleFunctions\" : [ { \"code\" : \"abc\", \"name\" : \"RF1\" }, { \"code\" : \"pqr\", \"name\" : \"RF2\" } ] , \"parentRoles\": [ {\"active\" : false, \"name\" : \"XYZ-ABC\"}, {\"active\" : true, \"name\" : \"ABC\"} ] } ";
98 Mockito.when(restApiRequestBuilder.getViaREST("/role/" + roleId, true, loginId)).thenReturn(roleResponse);
99 roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId);
100 Assert.assertTrue(true);
104 public void saveRoleTest() throws Exception {
105 Role role = new Role();
106 role.setName("Role");
107 roleServiceCntrlAccess.saveRole("123", role);
108 Assert.assertTrue(true);
112 public void deleteRoleTest() throws Exception {
113 Role role = new Role();
114 role.setName("Role");
116 roleServiceCntrlAccess.deleteRole("123", role);
117 Assert.assertTrue(true);
121 public void getActiveRolesTest() throws Exception {
122 String requestedLoginId ="1234";
123 String response ="[ { \"active\" : true, \"name\" : \"role1\" }, { \"active\" : false, \"name\" : \"role2\" } ]";
124 Mockito.when(restApiRequestBuilder.getViaREST("/activeRoles", true, requestedLoginId)).thenReturn(response);
125 List<Role> roles = roleServiceCntrlAccess.getActiveRoles(requestedLoginId);
126 Assert.assertNotNull(roles);
130 public void getRoleFunctionTest() throws IOException {
131 String requestedLoginId = "xyz";
134 String responseString = " { \"code\" : \"abc\", \"name\" : \"xyz\" }";
135 Mockito.when(restApiRequestBuilder.getViaREST("/function/" + code, true, requestedLoginId)).thenReturn(responseString);
136 RoleFunction roleFunction = roleServiceCntrlAccess.getRoleFunction(requestedLoginId, code);
137 Assert.assertNotNull(roleFunction);
141 public void saveRoleFunctionTest() throws IOException {
142 String requestedLoginId ="123";
143 RoleFunction domainRoleFunction = new RoleFunction();
144 domainRoleFunction.setId(1234L);
145 roleServiceCntrlAccess.saveRoleFunction(requestedLoginId, domainRoleFunction);
146 Assert.assertTrue(true);
150 public void deleteRoleFunctionTest() throws IOException {
151 String requestedLoginId ="123";
152 RoleFunction domainRoleFunction = new RoleFunction();
153 domainRoleFunction.setId(1234L);
154 roleServiceCntrlAccess.deleteRoleFunction(requestedLoginId, domainRoleFunction);
155 Assert.assertTrue(true);
159 public void deleteDependcyRoleRecord() throws IOException {
160 String requestedLoginId = "123";
162 roleServiceCntrlAccess.deleteDependcyRoleRecord(requestedLoginId, id);
163 Assert.assertTrue(true);