FINERACT-1971: Fixing Loan COB error on startup when Loan COB is disabled

This commit is contained in:
Peter Bagrij
2024-03-22 12:16:40 +01:00
committed by Adam Saghy
parent c34f2b4f59
commit c404f474e9
6 changed files with 16 additions and 40 deletions
@@ -21,12 +21,10 @@ package org.apache.fineract.cob.conditions;
import org.apache.fineract.infrastructure.core.condition.PropertiesCondition; import org.apache.fineract.infrastructure.core.condition.PropertiesCondition;
import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.core.config.FineractProperties;
public class LoanCOBWorkerCondition extends PropertiesCondition { public class BatchManagerCondition extends PropertiesCondition {
@Override @Override
protected boolean matches(FineractProperties properties) { protected boolean matches(FineractProperties properties) {
boolean loanCobEnabled = properties.getJob().isLoanCobEnabled(); return properties.getMode().isBatchManagerEnabled();
boolean batchWorkerEnabled = properties.getMode().isBatchWorkerEnabled();
return loanCobEnabled && batchWorkerEnabled;
} }
} }
@@ -21,12 +21,10 @@ package org.apache.fineract.cob.conditions;
import org.apache.fineract.infrastructure.core.condition.PropertiesCondition; import org.apache.fineract.infrastructure.core.condition.PropertiesCondition;
import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.core.config.FineractProperties;
public class LoanCOBManagerCondition extends PropertiesCondition { public class BatchWorkerCondition extends PropertiesCondition {
@Override @Override
protected boolean matches(FineractProperties properties) { protected boolean matches(FineractProperties properties) {
boolean loanCobEnabled = properties.getJob().isLoanCobEnabled(); return properties.getMode().isBatchWorkerEnabled();
boolean batchManagerEnabled = properties.getMode().isBatchManagerEnabled();
return loanCobEnabled && batchManagerEnabled;
} }
} }
@@ -20,7 +20,7 @@ package org.apache.fineract.cob.loan;
import org.apache.fineract.cob.COBBusinessStepService; import org.apache.fineract.cob.COBBusinessStepService;
import org.apache.fineract.cob.common.CustomJobParameterResolver; import org.apache.fineract.cob.common.CustomJobParameterResolver;
import org.apache.fineract.cob.conditions.LoanCOBManagerCondition; import org.apache.fineract.cob.conditions.BatchManagerCondition;
import org.apache.fineract.cob.listener.COBExecutionListenerRunner; import org.apache.fineract.cob.listener.COBExecutionListenerRunner;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.apache.fineract.infrastructure.jobs.service.JobName; import org.apache.fineract.infrastructure.jobs.service.JobName;
@@ -47,7 +47,7 @@ import org.springframework.transaction.PlatformTransactionManager;
@Configuration @Configuration
@EnableBatchIntegration @EnableBatchIntegration
@Conditional(LoanCOBManagerCondition.class) @Conditional(BatchManagerCondition.class)
public class LoanCOBManagerConfiguration { public class LoanCOBManagerConfiguration {
@Autowired @Autowired
@@ -22,7 +22,7 @@ import org.apache.fineract.cob.COBBusinessStepService;
import org.apache.fineract.cob.common.CustomJobParameterResolver; import org.apache.fineract.cob.common.CustomJobParameterResolver;
import org.apache.fineract.cob.common.InitialisationTasklet; import org.apache.fineract.cob.common.InitialisationTasklet;
import org.apache.fineract.cob.common.ResetContextTasklet; import org.apache.fineract.cob.common.ResetContextTasklet;
import org.apache.fineract.cob.conditions.LoanCOBWorkerCondition; import org.apache.fineract.cob.conditions.BatchWorkerCondition;
import org.apache.fineract.cob.listener.ChunkProcessingLoanItemListener; import org.apache.fineract.cob.listener.ChunkProcessingLoanItemListener;
import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.jobs.service.JobName; import org.apache.fineract.infrastructure.jobs.service.JobName;
@@ -51,7 +51,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
@Configuration @Configuration
@Conditional(LoanCOBWorkerCondition.class) @Conditional(BatchWorkerCondition.class)
public class LoanCOBWorkerConfiguration { public class LoanCOBWorkerConfiguration {
@Autowired @Autowired
@@ -32,7 +32,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.env.MockEnvironment;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class LoanCOBManagerConditionTest { class BatchManagerConditionTest {
@Mock @Mock
private ConditionContext conditionContext; private ConditionContext conditionContext;
@@ -43,7 +43,7 @@ class LoanCOBManagerConditionTest {
private MockEnvironment environment; private MockEnvironment environment;
@InjectMocks @InjectMocks
private LoanCOBManagerCondition testObj = new LoanCOBManagerCondition(); private BatchManagerCondition testObj = new BatchManagerCondition();
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
@@ -52,24 +52,14 @@ class LoanCOBManagerConditionTest {
} }
@Test @Test
public void testMatchesShouldReturnFalseWhenLoanCobIsDisabledAndManager() { public void testMatchesShouldReturnFalseWhenManagerDisabled() {
environment.withProperty("fineract.job.loan-cob-enabled", "false");
environment.withProperty("fineract.mode.batch-manager-enabled", "true");
boolean result = testObj.matches(conditionContext, metadata);
assertThat(result).isFalse();
}
@Test
public void testMatchesShouldReturnFalseWhenLoanCobIsEnabledAndNotManager() {
environment.withProperty("fineract.job.loan-cob-enabled", "true");
environment.withProperty("fineract.mode.batch-manager-enabled", "false"); environment.withProperty("fineract.mode.batch-manager-enabled", "false");
boolean result = testObj.matches(conditionContext, metadata); boolean result = testObj.matches(conditionContext, metadata);
assertThat(result).isFalse(); assertThat(result).isFalse();
} }
@Test @Test
public void testMatchesShouldReturnTrueWhenLoanCobIsEnabledAndManager() { public void testMatchesShouldReturnTrueWhenManagerEnabled() {
environment.withProperty("fineract.job.loan-cob-enabled", "true");
environment.withProperty("fineract.mode.batch-manager-enabled", "true"); environment.withProperty("fineract.mode.batch-manager-enabled", "true");
boolean result = testObj.matches(conditionContext, metadata); boolean result = testObj.matches(conditionContext, metadata);
assertThat(result).isTrue(); assertThat(result).isTrue();
@@ -32,7 +32,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.env.MockEnvironment;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class LoanCOBWorkerConditionTest { class BatchWorkerConditionTest {
@Mock @Mock
private ConditionContext conditionContext; private ConditionContext conditionContext;
@@ -43,7 +43,7 @@ class LoanCOBWorkerConditionTest {
private MockEnvironment environment; private MockEnvironment environment;
@InjectMocks @InjectMocks
private LoanCOBWorkerCondition testObj = new LoanCOBWorkerCondition(); private BatchWorkerCondition testObj = new BatchWorkerCondition();
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
@@ -52,24 +52,14 @@ class LoanCOBWorkerConditionTest {
} }
@Test @Test
public void testMatchesShouldReturnFalseWhenLoanCobIsDisabledAndWorker() { public void testMatchesShouldReturnFalseWhenWorkerDisabled() {
environment.withProperty("fineract.job.loan-cob-enabled", "false");
environment.withProperty("fineract.mode.batch-worker-enabled", "true");
boolean result = testObj.matches(conditionContext, metadata);
assertThat(result).isFalse();
}
@Test
public void testMatchesShouldReturnFalseWhenLoanCobIsEnabledAndNotWorker() {
environment.withProperty("fineract.job.loan-cob-enabled", "true");
environment.withProperty("fineract.mode.batch-worker-enabled", "false"); environment.withProperty("fineract.mode.batch-worker-enabled", "false");
boolean result = testObj.matches(conditionContext, metadata); boolean result = testObj.matches(conditionContext, metadata);
assertThat(result).isFalse(); assertThat(result).isFalse();
} }
@Test @Test
public void testMatchesShouldReturnTrueWhenLoanCobIsEnabledAndWorker() { public void testMatchesShouldReturnTrueWhenWorkerEnabled() {
environment.withProperty("fineract.job.loan-cob-enabled", "true");
environment.withProperty("fineract.mode.batch-worker-enabled", "true"); environment.withProperty("fineract.mode.batch-worker-enabled", "true");
boolean result = testObj.matches(conditionContext, metadata); boolean result = testObj.matches(conditionContext, metadata);
assertThat(result).isTrue(); assertThat(result).isTrue();