Added reschedule loans api resource to Fineract Client and batch; minor swagger polishing
This commit is contained in:
committed by
Arnold Gálovics
parent
b21cdf59b1
commit
87204d5a8a
+3
@@ -32,6 +32,7 @@ import org.apache.fineract.batch.command.internal.ApproveLoanRescheduleCommandSt
|
||||
import org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateClientCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateLoanRescheduleRequestCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetDatatableEntryByAppTableIdCommandStrategy;
|
||||
@@ -77,6 +78,8 @@ public class CommandStrategyProviderTest {
|
||||
mock(ApproveLoanCommandStrategy.class)),
|
||||
Arguments.of("loans/123?command=disburse", HttpMethod.POST, "disburseLoanCommandStrategy",
|
||||
mock(DisburseLoanCommandStrategy.class)),
|
||||
Arguments.of("rescheduleloans", HttpMethod.POST, "createLoanRescheduleRequestCommandStrategy",
|
||||
mock(CreateLoanRescheduleRequestCommandStrategy.class)),
|
||||
Arguments.of("rescheduleloans/123?command=approve", HttpMethod.POST, "approveLoanRescheduleCommandStrategy",
|
||||
mock(ApproveLoanRescheduleCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions/123", HttpMethod.GET, "getTransactionByIdCommandStrategy",
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.api.RescheduleLoansApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class fpr {@link CreateLoanRescheduleRequestCommandStrategy}.
|
||||
*/
|
||||
public class CreateLoanRescheduleRequestCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link CreateLoanRescheduleRequestCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccessScenario() {
|
||||
final TestContext testContext = new TestContext();
|
||||
final BatchRequest batchRequest = getBatchRequest();
|
||||
final String responseBody = "myResponseBody";
|
||||
|
||||
when(testContext.rescheduleLoansApiResource.createLoanRescheduleRequest(batchRequest.getBody())).thenReturn(responseBody);
|
||||
|
||||
BatchResponse batchResponse = testContext.subjectToTest.execute(batchRequest, testContext.uriInfo);
|
||||
|
||||
assertEquals(HttpStatus.SC_OK, batchResponse.getStatusCode());
|
||||
assertSame(responseBody, batchResponse.getBody());
|
||||
assertEquals(batchRequest.getRequestId(), batchResponse.getRequestId());
|
||||
assertEquals(batchRequest.getHeaders(), batchResponse.getHeaders());
|
||||
|
||||
verify(testContext.rescheduleLoansApiResource).createLoanRescheduleRequest(batchRequest.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id and command value.
|
||||
*
|
||||
*
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest() {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "rescheduleloans";
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* Mock URI info.
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* Mock reschedule loans API resource.
|
||||
*/
|
||||
@Mock
|
||||
private RescheduleLoansApiResource rescheduleLoansApiResource;
|
||||
|
||||
/**
|
||||
* The {@link CreateLoanRescheduleRequestCommandStrategy} under test.
|
||||
*/
|
||||
private final CreateLoanRescheduleRequestCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new CreateLoanRescheduleRequestCommandStrategy(rescheduleLoansApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user