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.Matchers;
48 import org.mockito.Mock;
49 import org.mockito.Mockito;
50 import org.onap.portalsdk.core.domain.Role;
51 import org.onap.portalsdk.core.domain.RoleFunction;
52 import org.powermock.modules.junit4.PowerMockRunner;
54 @RunWith(PowerMockRunner.class)
55 public class RoleServiceCentralizedAccessTest {
58 private RoleServiceCentralizedAccess roleServiceCntrlAccess;
61 private RestApiRequestBuilder restApiRequestBuilder;
64 public void getRoleFunctionsTest() throws Exception {
65 String loginId ="1234";
66 String response ="[ { \"code\" : \"abc\", \"name\" : \"xyz\" }, { \"code\" : \"pqr\", \"name\" : \"str\" } ]";
67 Mockito.when(restApiRequestBuilder.getViaREST(Matchers.anyString(), Matchers.anyBoolean(), Matchers.anyString())).thenReturn(response);
68 List<RoleFunction> roleFunctions = roleServiceCntrlAccess.getRoleFunctions(loginId);
69 Assert.assertTrue(roleFunctions.size() > 0);
73 public void getAvailableChildRolesWithEmptyRoleIdTest() throws Exception {
74 String loginId = "123";
76 String response ="[ { \"active\" : true, \"name\" : \"xyz\" } ]";
77 Mockito.when(restApiRequestBuilder.getViaREST("/v1/roles", true, loginId)).thenReturn(response);
78 List<Role> roles = roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId);
79 Assert.assertNotNull(roles);
83 public void getAvailableChildRolesWithZeroRoleIdTest() throws Exception {
84 String loginId = "123";
86 String response ="[ { \"active\" : true, \"name\" : \"xyz\" } ]";
87 Mockito.when(restApiRequestBuilder.getViaREST("/v1/roles", true, loginId)).thenReturn(response);
88 List<Role> roles = roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId);
89 Assert.assertNotNull(roles);
93 public void getAvailableChildRolesTest() throws Exception {
94 String loginId = "123";
96 String response ="[ { \"active\" : false, \"name\" : \"xyz\" } ]";
97 Mockito.when(restApiRequestBuilder.getViaREST("/v1/roles", true, loginId)).thenReturn(response);
98 String roleResponse =" { \"active\" : true, \"name\" : \"xyz\", \"roleFunctions\" : [ { \"code\" : \"abc\", \"name\" : \"RF1\" , \"type\" : \"abc\", \"action\" : \"abc\" }, { \"code\" : \"pqr\", \"name\" : \"RF2\" , \"type\" : \"abc\", \"action\" : \"abc\" } ] , \"parentRoles\": [ {\"active\" : false, \"name\" : \"XYZ-ABC\"}, {\"active\" : true, \"name\" : \"ABC\"} ] } ";
99 Mockito.when(restApiRequestBuilder.getViaREST("/v1/role/" + roleId, true, loginId)).thenReturn(roleResponse);
100 roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId);
101 Assert.assertTrue(true);
105 public void saveRoleTest() throws Exception {
106 Role role = new Role();
107 role.setName("Role");
108 roleServiceCntrlAccess.saveRole("123", role);
109 Assert.assertTrue(true);
113 public void deleteRoleTest() throws Exception {
114 Role role = new Role();
115 role.setName("Role");
117 roleServiceCntrlAccess.deleteRole("123", role);
118 Assert.assertTrue(true);
122 public void getActiveRolesTest() throws Exception {
123 String requestedLoginId ="1234";
124 String response ="[ { \"active\" : true, \"name\" : \"role1\" }, { \"active\" : false, \"name\" : \"role2\" } ]";
125 Mockito.when(restApiRequestBuilder.getViaREST("/v1/activeRoles", true, requestedLoginId)).thenReturn(response);
126 List<Role> roles = roleServiceCntrlAccess.getActiveRoles(requestedLoginId);
127 Assert.assertNotNull(roles);
131 public void getRoleFunctionTest() throws IOException {
132 String requestedLoginId = "xyz";
135 String responseString = " { \"code\" : \"abc\", \"name\" : \"xyz\" , \"type\" : \"abc\", \"action\" : \"abc\" }";
136 // Mockito.when(restApiRequestBuilder.getViaREST("v1/function/" + code, true, requestedLoginId)).thenReturn(responseString);
137 Mockito.when(restApiRequestBuilder.getViaREST(Matchers.anyString(), Matchers.anyBoolean(), Matchers.anyString())).thenReturn(responseString);
138 RoleFunction roleFunction = roleServiceCntrlAccess.getRoleFunction(requestedLoginId, code);
139 Assert.assertNotNull(roleFunction);
143 public void saveRoleFunctionTest() throws IOException {
144 String requestedLoginId ="123";
145 RoleFunction domainRoleFunction = new RoleFunction();
146 domainRoleFunction.setId(1234L);
147 roleServiceCntrlAccess.saveRoleFunction(requestedLoginId, domainRoleFunction);
148 Assert.assertTrue(true);
152 public void deleteRoleFunctionTest() throws IOException {
153 String requestedLoginId ="123";
154 RoleFunction domainRoleFunction = new RoleFunction();
155 domainRoleFunction.setId(1234L);
156 roleServiceCntrlAccess.deleteRoleFunction(requestedLoginId, domainRoleFunction);
157 Assert.assertTrue(true);
161 public void deleteDependcyRoleRecord() throws IOException {
162 String requestedLoginId = "123";
164 roleServiceCntrlAccess.deleteDependcyRoleRecord(requestedLoginId, id);
165 Assert.assertTrue(true);