[FINERACT-1678] Inline COB API

This commit is contained in:
taskain7
2022-10-18 19:14:38 +02:00
committed by Arnold Gálovics
parent 22bcccb17b
commit ebe87433e7
53 changed files with 1489 additions and 206 deletions
@@ -46,7 +46,8 @@ public class LoanItemListenerStepDefinitions implements En {
private LoanAccountLockRepository accountLockRepository = mock(LoanAccountLockRepository.class);
private TransactionTemplate transactionTemplate = spy(TransactionTemplate.class);
private LoanItemListener loanItemListener = new LoanItemListener(accountLockRepository, transactionTemplate);
private ChunkProcessingLoanItemListener loanItemListener = new ChunkProcessingLoanItemListener(accountLockRepository,
transactionTemplate);
private Exception exception;
@@ -1,80 +0,0 @@
/**
* 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.cob.service;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class BusinessStepConfigUpdateHandlerTest {
@InjectMocks
private BusinessStepConfigUpdateHandler testObj;
@Mock
private ConfigJobParameterService configJobParameterService;
@Captor
private ArgumentCaptor<String> argumentCaptor;
@Test
void shouldProcessCommandGetsJobName() {
JsonCommand command = mock(JsonCommand.class);
given(command.getUrl()).willReturn("/jobs/jobName/steps");
testObj.processCommand(command);
verify(configJobParameterService).updateStepConfigByJobName(eq(command), argumentCaptor.capture());
assertEquals("jobName", argumentCaptor.getValue());
}
@Test
void shouldProcessCommandGetsJobNameEmptyString() {
JsonCommand command = mock(JsonCommand.class);
given(command.getUrl()).willReturn("/jobs//steps");
testObj.processCommand(command);
verify(configJobParameterService).updateStepConfigByJobName(eq(command), argumentCaptor.capture());
assertEquals("", argumentCaptor.getValue());
}
@Test
void shouldProcessCommandGetsJobNameNull() {
JsonCommand command = mock(JsonCommand.class);
given(command.getUrl()).willReturn("/jobs/" + null + "/steps");
testObj.processCommand(command);
verify(configJobParameterService).updateStepConfigByJobName(eq(command), argumentCaptor.capture());
assertEquals(null, argumentCaptor.getValue());
}
}
@@ -0,0 +1,61 @@
/**
* 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.cob.service;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.transaction.support.TransactionTemplate;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class InlineLoanCOBExecutorServiceImplTest {
@InjectMocks
private InlineLoanCOBExecutorServiceImpl testObj;
@Mock
private TransactionTemplate transactionTemplate;
@Mock
private InlineLoanCOBExecutionDataParser dataParser;
@Test
void shouldExceptionThrownIfLoanIsAlreadyLocked() {
JsonCommand command = mock(JsonCommand.class);
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
when(dataParser.parseExecution(any())).thenReturn(List.of(3L));
when(transactionTemplate.execute(any())).thenThrow(new LoanAccountLockCannotBeOverruledException(""));
assertThrows(LoanAccountLockCannotBeOverruledException.class, () -> testObj.executeInlineJob(command, "INLINE_LOAN_COB"));
}
}
@@ -42,7 +42,7 @@ public class CommandHandlerProviderStepDefinitions implements En {
When("The user processes the command with ID {long}", (Long id) -> {
this.result = commandHandler
.processCommand(JsonCommand.fromExistingCommand(id, null, null, null, null, null, null, null, null, null, null));
.processCommand(JsonCommand.fromExistingCommand(id, null, null, null, null, null, null, null, null, null, null, null));
});
Then("The command ID matches {long}", (Long id) -> {