1- /**
2- * Licensed to the Apache Software Foundation (ASF) under one
3- * or more contributor license agreements. See the NOTICE file
4- * distributed with this work for additional information
5- * regarding copyright ownership. The ASF licenses this file
6- * to you under the Apache License, Version 2.0 (the
7- * "License"); you may not use this file except in compliance
8- * with the License. You may obtain a copy of the License at
9- *
10- * http://www.apache.org/licenses/LICENSE-2.0
11- *
12- * Unless required by applicable law or agreed to in writing,
13- * software distributed under the License is distributed on an
14- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15- * KIND, either express or implied. See the License for the
16- * specific language governing permissions and limitations
17- * under the License.
18- */
191package org .apache .fineract .integrationtests .useradministration .roles ;
202
21-
22-
23-
24- import static org .mockito .Mockito .description ;
25- import org .apache .fineract .client .models .PostRolesRoleIdPermissionsRequest ;
26-
27- import org .apache .fineract .client .models .PostRolesRoleIdPermissionsResponse ;
28-
29- import java .util .HashMap ;
3+ import io .restassured .specification .RequestSpecification ;
4+ import io .restassured .specification .ResponseSpecification ;
305import java .util .List ;
316import java .util .Map ;
32- import org .apache .fineract .client .models .CommandProcessingResult ;
33- import org .apache .fineract .client .models .PutPermissionsRequest ;
7+ import lombok .extern .slf4j .Slf4j ;
8+ import org .apache .fineract .client .models .PostRolesRequest ;
9+ import org .apache .fineract .client .models .PostRolesResponse ;
10+ import org .apache .fineract .client .models .GetRolesRoleIdResponse ;
11+ import org .apache .fineract .client .models .PostRolesRoleIdPermissionsRequest ;
12+ import org .apache .fineract .client .models .PostRolesRoleIdPermissionsResponse ;
3413import org .apache .fineract .client .util .Calls ;
35- import org .apache .fineract .client .util .JSON ;
3614import org .apache .fineract .integrationtests .common .FineractClientHelper ;
3715import org .apache .fineract .integrationtests .common .Utils ;
38- import org .apache .fineract .useradministration .api .PermissionsApiResourceSwagger .GetPermissionsResponse ;
39- import org .apache .fineract .useradministration .api .RolesApiResourceSwagger .GetRolesRoleIdResponse ;
40- import org .apache .fineract .useradministration .api .RolesApiResourceSwagger .PostRolesRequest ;
41- import org .apache .fineract .useradministration .api .RolesApiResourceSwagger .PostRolesResponse ;
42-
4316
17+ @ Slf4j
4418public final class RolesHelper {
4519
46- public static final long SUPER_USER_ROLE_ID = 1L ; // This is hardcoded into the initial Liquibase migration
47-
48- public RolesHelper () {
20+ public static final long SUPER_USER_ROLE_ID = 1L ;
4921
50- }
22+ private RolesHelper () { }
5123
52- // TODO: Rewrite to use fineract-client instead!
53- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
54- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
5524
56-
57- //new method createRole by fiegn
58- public static Long createRole (){
59- PostRolesRequest request =new PostRolesRequest ()
60- .name (Utils .uniqueRandomStringGenerator ("Role_" ,4 ))
61- .description ("New Role" );
62-
63- PostRolesResponse response =Calls .ok (FineractClientHelper .getFineractClient ().roles .createRole (request ));
64- return response .getResourceId ();
25+ public static Integer createRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ) {
26+ log .info ("---------------------------------CREATING A ROLE (COMPATIBILITY)---------------------------------------------" );
27+ PostRolesRequest request = new PostRolesRequest ()
28+ .name (Utils .uniqueRandomStringGenerator ("Role_" , 4 ))
29+ .description ("New Role" );
30+
31+
32+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .createRole (request )).getResourceId ().intValue ();
6533 }
6634
67- // TODO: Rewrite to use fineract-client instead!
68- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
69- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
70- public static PostRolesRequest buildDefaultRoleRequest (){
71- return new PostRolesRequest ()
72- .name (Utils .uniqueRandomStringGenerator ("Role_Name_" ,5 ))
73- .description (Utils .randomStringGenerator ("Role_Description_" , 10 ));
74- }
75-
76- // TODO: Rewrite to use fineract-client instead!
77- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
78- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
79- public static GetRolesRoleIdResponse getRoleDetails (final Long roleId ){
80- return Calls .ok (FineractClientHelper .getFineractClient ().roles .retrieveRole (roleId ));
81- }
8235
83- // TODO: Rewrite to use fineract-client instead!
84- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
85- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
86- public static Integer disableRole (final Long roleId ){
87- return Calls .ok (FineractClientHelper .getFineractClient ().roles .disableRole (roleId )).getResourceId ();
88- }
89-
90- // TODO: Rewrite to use fineract-client instead!
91- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
92- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
93- public static Integer enableRole (final Long roleId ){
94- return Calls .ok (FineractClientHelper .getFineractClient ().roles .enableRole (roleId )).getResourceId ();
36+ public static Long createRole () {
37+ PostRolesRequest request = new PostRolesRequest ()
38+ .name (Utils .uniqueRandomStringGenerator ("Role_" , 4 ))
39+ .description ("New Role" );
40+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .createRole (request )).getResourceId ();
9541 }
9642
97- // TODO: Rewrite to use fineract-client instead!
98- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
99- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
100- public static Integer deleteRole (final Long roleId ){
101- return Calls .ok (FineractClientHelper .getFineractClient ().roles .deleteRole (roleId )).getResourceId ();
102- }
103-
104- // TODO: Rewrite to use fineract-client instead!
105- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
106- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
107- public static PostRolesRoleIdPermissionsResponse addPermissionsToRole (final Long roleId ,final PostRolesRoleIdPermissionsRequest request ){
108- return Calls .ok (FineractClientHelper .getFineractClient ().roles .updateRolePermissions (roleId ,request ));
109- }
110-
111- // TODO: Rewrite to use fineract-client instead!
112- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
113- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
114- public static List <GetPermissionsResponse > getPermissions (final Boolean makerCheckerable ){
115- return Calls .ok (FineractClientHelper .getFineractClient ().permissions .retrieveAllPermissions (makerCheckerable ));
116- }
43+
44+ public static GetRolesRoleIdResponse getRoleDetails (final Long roleId ) {
45+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .retrieveRole (roleId ));
46+ }
11747
118- public CommandProcessingResult updatePermissions (PutPermissionsRequest request ) {
119- return Calls .ok (FineractClientHelper .getFineractClient ().permissions .updatePermissionsDetails (request ));
48+
49+ public static String addPermissionsToRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
50+ final Integer roleId , final Map <String , Boolean > permissionMap ) {
51+ PostRolesRoleIdPermissionsRequest request = new PostRolesRoleIdPermissionsRequest ().permissions (permissionMap );
52+ Calls .ok (FineractClientHelper .getFineractClient ().roles .updateRolePermissions (roleId .longValue (), request ));
53+ return "" ;
12054 }
12155
122- // TODO: Rewrite to use fineract-client instead!
123- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
124- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
125- public static PostRolesRoleIdPermissionsResponse addPermissionsToRole (final Long roleId , final Map <String , Boolean > permissionMap ) {
126- PostRolesRoleIdPermissionsRequest request = new PostRolesRoleIdPermissionsRequest ()
127- .permissions (permissionMap );
12856
129- return Calls .ok (FineractClientHelper .getFineractClient ().roles .updateRolePermissions (roleId , request ));
130- }
57+ public static Integer disableRole (final Long roleId ) {
58+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .disableRole (roleId )).getResourceId ().intValue ();
59+ }
13160
132- // TODO: Rewrite to use fineract-client instead!
133- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
134- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
61+ public static Integer enableRole ( final Long roleId ) {
62+ return Calls . ok ( FineractClientHelper . getFineractClient (). roles . enableRole ( roleId )). getResourceId (). intValue ();
63+ }
13564
136- }
65+ public static Integer deleteRole (final Long roleId ) {
66+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .deleteRole (roleId )).getResourceId ().intValue ();
67+ }
68+ }
0 commit comments