Skip to content

Commit 25c5217

Browse files
committed
FINERACT-2553: Modernize User and Role helpers with Fineract-Client and backward compatibility
1 parent 5956214 commit 25c5217

4 files changed

Lines changed: 90 additions & 491 deletions

File tree

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
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-
*/
191
package org.apache.fineract.integrationtests.common;
202

213
import static org.junit.jupiter.api.Assertions.assertEquals;
22-
23-
import com.google.common.reflect.TypeToken;
24-
import com.google.gson.Gson;
254
import io.restassured.specification.RequestSpecification;
265
import io.restassured.specification.ResponseSpecification;
276
import java.util.List;
@@ -34,65 +13,34 @@
3413
import org.apache.fineract.client.models.PaymentTypeUpdateResponse;
3514
import org.apache.fineract.client.util.Calls;
3615

37-
@SuppressWarnings({ "rawtypes", "unchecked" })
3816
@Slf4j
3917
public final class PaymentTypeHelper {
4018

41-
public PaymentTypeHelper() {
42-
43-
}
44-
45-
private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes";
46-
private static final String CREATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "?" + Utils.TENANT_IDENTIFIER;
19+
private PaymentTypeHelper() {}
4720

4821
public List<PaymentTypeData> getAllPaymentTypes(final Boolean onlyWithCode) {
4922
log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------");
5023
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.getAllPaymentTypes(onlyWithCode));
5124
}
5225

53-
public PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest paymentTypeRequest) {
26+
public PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest request) {
5427
log.info("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
55-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(paymentTypeRequest));
56-
}
57-
58-
public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
59-
log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
60-
PaymentTypeData response = Calls
61-
.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
62-
Long responsePaymentTypeID = response.getId();
63-
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
28+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(request));
6429
}
6530

66-
public PaymentTypeData retrieveById(final Long paymentTypeId) {
67-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
31+
32+
public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
33+
log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------");
6834
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
6935
}
7036

71-
// TODO: Rewrite to use fineract-client instead!
72-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
73-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
74-
@Deprecated(forRemoval = true)
75-
public PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
76-
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER;
77-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
78-
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "");
79-
final String jsonData = new Gson().toJson(get);
80-
return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType());
81-
}
82-
83-
public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId,
84-
PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) {
37+
public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) {
8538
log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
86-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId,
87-
putPaymentTypesPaymentTypeIdRequest));
39+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request));
8840
}
8941

9042
public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
9143
log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
9244
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId));
9345
}
94-
95-
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
96-
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
97-
}
98-
}
46+
}
Lines changed: 37 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,68 @@
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-
*/
191
package org.apache.fineract.integrationtests.useradministration.roles;
202

21-
import com.google.gson.Gson;
22-
import com.google.gson.reflect.TypeToken;
233
import io.restassured.specification.RequestSpecification;
244
import io.restassured.specification.ResponseSpecification;
25-
import java.lang.reflect.Type;
26-
import java.util.HashMap;
275
import java.util.List;
286
import java.util.Map;
29-
import org.apache.fineract.client.models.CommandProcessingResult;
30-
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;
3113
import org.apache.fineract.client.util.Calls;
32-
import org.apache.fineract.client.util.JSON;
3314
import org.apache.fineract.integrationtests.common.FineractClientHelper;
3415
import org.apache.fineract.integrationtests.common.Utils;
35-
import org.apache.fineract.useradministration.data.PermissionData;
3616

17+
@Slf4j
3718
public final class RolesHelper {
3819

39-
public static final long SUPER_USER_ROLE_ID = 1L; // This is hardcoded into the initial Liquibase migration
20+
public static final long SUPER_USER_ROLE_ID = 1L;
4021

41-
public RolesHelper() {
22+
private RolesHelper() {}
4223

43-
}
44-
45-
private static final String CREATE_ROLE_URL = "/fineract-provider/api/v1/roles?" + Utils.TENANT_IDENTIFIER;
46-
private static final String ROLE_URL = "/fineract-provider/api/v1/roles";
47-
private static final String PERMISSIONS_URL = "/fineract-provider/api/v1/permissions";
48-
private static final String DISABLE_ROLE_COMMAND = "disable";
49-
private static final String ENABLE_ROLE_COMMAND = "enable";
50-
51-
private static final Gson GSON = new JSON().getGson();
52-
53-
// TODO: Rewrite to use fineract-client instead!
54-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
55-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
56-
@Deprecated(forRemoval = true)
24+
5725
public static Integer createRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
58-
return Utils.performServerPost(requestSpec, responseSpec, CREATE_ROLE_URL, getTestCreateRoleAsJSON(), "resourceId");
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();
5933
}
6034

61-
// TODO: Rewrite to use fineract-client instead!
62-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
63-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
64-
@Deprecated(forRemoval = true)
65-
public static String getTestCreateRoleAsJSON() {
66-
final HashMap<String, String> map = new HashMap<>();
67-
map.put("name", Utils.uniqueRandomStringGenerator("Role_Name_", 5));
68-
map.put("description", Utils.randomStringGenerator("Role_Description_", 10));
69-
return new Gson().toJson(map);
70-
}
7135

72-
// TODO: Rewrite to use fineract-client instead!
73-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
74-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
75-
@Deprecated(forRemoval = true)
76-
public static HashMap<String, Object> getRoleDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
77-
final Integer roleId) {
78-
final String GET_ROLE_URL = "/fineract-provider/api/v1/roles/" + roleId + "?" + Utils.TENANT_IDENTIFIER;
79-
return Utils.performServerGet(requestSpec, responseSpec, GET_ROLE_URL, "");
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();
8041
}
8142

82-
// TODO: Rewrite to use fineract-client instead!
83-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
84-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
85-
@Deprecated(forRemoval = true)
86-
public static Integer disableRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
87-
final Integer roleId) {
88-
return Utils.performServerPost(requestSpec, responseSpec, createRoleOperationURL(DISABLE_ROLE_COMMAND, roleId), "", "resourceId");
43+
44+
public static GetRolesRoleIdResponse getRoleDetails(final Long roleId) {
45+
return Calls.ok(FineractClientHelper.getFineractClient().roles.retrieveRole(roleId));
8946
}
9047

91-
// TODO: Rewrite to use fineract-client instead!
92-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
93-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
94-
@Deprecated(forRemoval = true)
95-
public static Integer enableRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
96-
final Integer roleId) {
97-
return Utils.performServerPost(requestSpec, responseSpec, createRoleOperationURL(ENABLE_ROLE_COMMAND, roleId), "", "resourceId");
98-
}
99-
100-
// TODO: Rewrite to use fineract-client instead!
101-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
102-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
103-
@Deprecated(forRemoval = true)
104-
public static Integer deleteRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
105-
final Integer roleId) {
106-
return Utils.performServerDelete(requestSpec, responseSpec, createRoleOperationURL(ENABLE_ROLE_COMMAND, roleId), "resourceId");
107-
}
108-
109-
// TODO: Rewrite to use fineract-client instead!
110-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
111-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
112-
@Deprecated(forRemoval = true)
48+
11349
public static String addPermissionsToRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
11450
final Integer roleId, final Map<String, Boolean> permissionMap) {
115-
return Utils.performServerPut(requestSpec, responseSpec, ROLE_URL + "/" + roleId + "/permissions?" + Utils.TENANT_IDENTIFIER,
116-
getAddPermissionsToRoleJSON(permissionMap));
117-
}
118-
119-
// TODO: Rewrite to use fineract-client instead!
120-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
121-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
122-
@Deprecated(forRemoval = true)
123-
public static List<PermissionData> getPermissions(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
124-
boolean makerCheckerable) {
125-
String response = Utils.performServerGet(requestSpec, responseSpec,
126-
PERMISSIONS_URL + "?" + makerCheckerable + "=" + makerCheckerable);
127-
final Type listType = new TypeToken<List<PermissionData>>() {}.getType();
128-
return GSON.fromJson(response, listType);
51+
PostRolesRoleIdPermissionsRequest request = new PostRolesRoleIdPermissionsRequest().permissions(permissionMap);
52+
Calls.ok(FineractClientHelper.getFineractClient().roles.updateRolePermissions(roleId.longValue(), request));
53+
return "";
12954
}
13055

131-
public CommandProcessingResult updatePermissions(PutPermissionsRequest request) {
132-
return Calls.ok(FineractClientHelper.getFineractClient().permissions.updatePermissionsDetails(request));
56+
57+
public static Integer disableRole(final Long roleId) {
58+
return Calls.ok(FineractClientHelper.getFineractClient().roles.disableRole(roleId)).getResourceId().intValue();
13359
}
13460

135-
// TODO: Rewrite to use fineract-client instead!
136-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
137-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
138-
@Deprecated(forRemoval = true)
139-
private static String getAddPermissionsToRoleJSON(Map<String, Boolean> permissionMap) {
140-
final HashMap<String, Map<String, Boolean>> map = new HashMap<>();
141-
map.put("permissions", permissionMap);
142-
return new Gson().toJson(map);
61+
public static Integer enableRole(final Long roleId) {
62+
return Calls.ok(FineractClientHelper.getFineractClient().roles.enableRole(roleId)).getResourceId().intValue();
14363
}
14464

145-
// TODO: Rewrite to use fineract-client instead!
146-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
147-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
148-
@Deprecated(forRemoval = true)
149-
private static String createRoleOperationURL(final String command, final Integer roleId) {
150-
return ROLE_URL + "/" + roleId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
65+
public static Integer deleteRole(final Long roleId) {
66+
return Calls.ok(FineractClientHelper.getFineractClient().roles.deleteRole(roleId)).getResourceId().intValue();
15167
}
152-
}
68+
}

0 commit comments

Comments
 (0)