Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.fineract.integrationtests;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
Expand All @@ -26,6 +30,7 @@
import org.apache.fineract.client.models.PaymentTypeCreateRequest;
import org.apache.fineract.client.models.PaymentTypeData;
import org.apache.fineract.client.models.PaymentTypeUpdateRequest;
import org.apache.fineract.client.util.CallFailedRuntimeException;
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.Assertions;
Expand All @@ -36,55 +41,55 @@ public class PaymentTypeIntegrationTest {

private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private PaymentTypeHelper paymentTypeHelper;

@BeforeEach
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testPaymentType() {
// 1. Setup Data
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
Boolean isCashPayment = true;
Long position = 1L;

var paymentTypesResponse = paymentTypeHelper.createPaymentType(
// 2. Create Payment Type
var paymentTypesResponse = PaymentTypeHelper.createPaymentType(
new PaymentTypeCreateRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));

Long paymentTypeId = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(paymentTypeId);
paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
PaymentTypeData paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
Assertions.assertEquals(name, paymentTypeResponse.getName());
Assertions.assertEquals(description, paymentTypeResponse.getDescription());
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
Assertions.assertEquals(position, paymentTypeResponse.getPosition());

// Update Payment Type
Assertions.assertNotNull(paymentTypeId, "Payment Type Resource ID should not be null");

// 3. Verify Creation
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);

// 4. Retrieve and Assert
PaymentTypeData paymentTypeResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
Assertions.assertEquals(name, paymentTypeResponse.getName(), "Name mismatch after creation");

// 5. Update Payment Type
String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5);
String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15);
Boolean isCashPaymentUpdatedValue = false;
Long newPosition = 2L;

paymentTypeHelper.updatePaymentType(paymentTypeId, new PaymentTypeUpdateRequest().name(newName).description(newDescription)
.isCashPayment(isCashPaymentUpdatedValue).position(newPosition));
var paymentTypeUpdatedResponse = paymentTypeHelper.retrieveById(paymentTypeId);
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName());
Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());

// Delete
var responseDelete = paymentTypeHelper.deletePaymentType(paymentTypeId);
Long deletedPaymentTypeId = responseDelete.getResourceId();
Assertions.assertEquals(paymentTypeId, deletedPaymentTypeId);
ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build();
paymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId);
PaymentTypeHelper.updatePaymentType(paymentTypeId,
new PaymentTypeUpdateRequest().name(newName).description(description).isCashPayment(isCashPayment).position(position));

// 6. Verify Update
var paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName(), "Name mismatch after update");

// 7. Delete Payment Type
var responseDelete = PaymentTypeHelper.deletePaymentType(paymentTypeId);
Assertions.assertEquals(paymentTypeId, responseDelete.getResourceId(), "Deleted Resource ID mismatch");

// JUnit style assertThrows
final CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class, () -> {
PaymentTypeHelper.retrieveById(paymentTypeId);
});

assertEquals(404, exception.getResponse().code());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.fineract.integrationtests.common;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.List;
Expand All @@ -34,60 +33,44 @@
import org.apache.fineract.client.models.PaymentTypeUpdateResponse;
import org.apache.fineract.client.util.Calls;

@SuppressWarnings({ "rawtypes", "unchecked" })
@Slf4j
@SuppressWarnings("HideUtilityClassConstructor")
public final class PaymentTypeHelper {

public PaymentTypeHelper() {

}
public PaymentTypeHelper() {}

private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes";
private static final String CREATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "?" + Utils.TENANT_IDENTIFIER;

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

public PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest paymentTypeRequest) {
public static PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest request) {
log.info("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(paymentTypeRequest));
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(request));
}

public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
public static void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
PaymentTypeData response = Calls
.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
Long responsePaymentTypeID = response.getId();
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
assertEquals(generatedPaymentTypeID, response.getId(), "ERROR IN CREATING THE PAYMENT TYPE");
}

public PaymentTypeData retrieveById(final Long paymentTypeId) {
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------");
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
}

// TODO: Rewrite to use fineract-client instead!
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
@Deprecated(forRemoval = true)
public PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER;
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "");
final String jsonData = new Gson().toJson(get);
return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType());
public static PaymentTypeData retrieveById(final Long paymentTypeId) {
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
}

public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId,
PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) {
public static PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) {
log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId,
putPaymentTypesPaymentTypeIdRequest));
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request));
}

public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
public static PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId));
}
Expand Down
Loading