[FINERACT-1922] Skip business date job when business date is not enabled

This commit is contained in:
taskain7
2023-04-19 12:21:15 +02:00
committed by Adam Saghy
parent e4c26e7e5c
commit 82231101c8
6 changed files with 184 additions and 4 deletions
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.increasebusinessdateby1day;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService;
import org.springframework.batch.core.Job;
@@ -38,6 +39,8 @@ public class IncreaseBusinessDateBy1DayConfig {
private StepBuilderFactory steps;
@Autowired
private IncreaseDateBy1DayService increaseDateBy1DayService;
@Autowired
private ConfigurationDomainService configurationDomainService;
@Bean
protected Step increaseBusinessDateBy1DayStep() {
@@ -52,6 +55,6 @@ public class IncreaseBusinessDateBy1DayConfig {
@Bean
public IncreaseBusinessDateBy1DayTasklet increaseBusinessDateBy1DayTasklet() {
return new IncreaseBusinessDateBy1DayTasklet(increaseDateBy1DayService);
return new IncreaseBusinessDateBy1DayTasklet(increaseDateBy1DayService, configurationDomainService);
}
}
@@ -21,7 +21,9 @@ package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.incre
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
@@ -32,10 +34,15 @@ import org.springframework.batch.repeat.RepeatStatus;
public class IncreaseBusinessDateBy1DayTasklet implements Tasklet {
private final IncreaseDateBy1DayService increaseDateBy1DayService;
private final ConfigurationDomainService configurationDomainService;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
increaseDateBy1DayService.increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE);
if (configurationDomainService.isBusinessDateEnabled()) {
increaseDateBy1DayService.increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE);
} else {
contribution.setExitStatus(ExitStatus.NOOP);
}
return RepeatStatus.FINISHED;
}
}
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.increasecobdateby1day;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService;
import org.springframework.batch.core.Job;
@@ -38,6 +39,8 @@ public class IncreaseCobDateBy1DayConfig {
private StepBuilderFactory steps;
@Autowired
private IncreaseDateBy1DayService increaseDateBy1DayService;
@Autowired
private ConfigurationDomainService configurationDomainService;
@Bean
protected Step increaseCobDateBy1DayStep() {
@@ -52,6 +55,6 @@ public class IncreaseCobDateBy1DayConfig {
@Bean
public IncreaseCobDateBy1DayTasklet increaseCobDateBy1DayTasklet() {
return new IncreaseCobDateBy1DayTasklet(increaseDateBy1DayService);
return new IncreaseCobDateBy1DayTasklet(increaseDateBy1DayService, configurationDomainService);
}
}
@@ -21,7 +21,9 @@ package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.incre
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
@@ -32,10 +34,15 @@ import org.springframework.batch.repeat.RepeatStatus;
public class IncreaseCobDateBy1DayTasklet implements Tasklet {
private final IncreaseDateBy1DayService increaseDateBy1DayService;
private final ConfigurationDomainService configurationDomainService;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
increaseDateBy1DayService.increaseDateByTypeByOneDay(BusinessDateType.COB_DATE);
if (configurationDomainService.isBusinessDateEnabled()) {
increaseDateBy1DayService.increaseDateByTypeByOneDay(BusinessDateType.COB_DATE);
} else {
contribution.setExitStatus(ExitStatus.NOOP);
}
return RepeatStatus.FINISHED;
}
}
@@ -0,0 +1,80 @@
/**
* 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.infrastructure.jobs.service.increasedateby1day.increasebusinessdateby1day;
import static org.junit.Assert.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService;
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.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.repeat.RepeatStatus;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class IncreaseBusinessDateBy1DayTaskletTest {
@Mock
private StepContribution stepContribution;
@Mock
private ChunkContext chunkContext;
@Mock
private ConfigurationDomainService configurationDomainService;
@Mock
private IncreaseDateBy1DayService increaseDateBy1DayService;
@InjectMocks
private IncreaseBusinessDateBy1DayTasklet underTest;
@Test
public void shouldBusinessDateJobBeSkippedWhenBusinessDateIsNotEnabled() throws Exception {
given(configurationDomainService.isBusinessDateEnabled()).willReturn(false);
RepeatStatus repeatStatus = underTest.execute(stepContribution, chunkContext);
verify(stepContribution, times(1)).setExitStatus(ExitStatus.NOOP);
assertEquals(RepeatStatus.FINISHED, repeatStatus);
}
@Test
public void shouldBusinessDateJobBeProcessedWhenBusinessDateIsEnabled() throws Exception {
given(configurationDomainService.isBusinessDateEnabled()).willReturn(true);
RepeatStatus repeatStatus = underTest.execute(stepContribution, chunkContext);
verify(increaseDateBy1DayService, times(1)).increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE);
assertEquals(RepeatStatus.FINISHED, repeatStatus);
}
}
@@ -0,0 +1,80 @@
/**
* 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.infrastructure.jobs.service.increasedateby1day.increasecobdateby1day;
import static org.junit.Assert.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService;
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.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.repeat.RepeatStatus;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class IncreaseCobDateBy1DayTaskletTest {
@Mock
private StepContribution stepContribution;
@Mock
private ChunkContext chunkContext;
@Mock
private ConfigurationDomainService configurationDomainService;
@Mock
private IncreaseDateBy1DayService increaseDateBy1DayService;
@InjectMocks
private IncreaseCobDateBy1DayTasklet underTest;
@Test
public void shouldBusinessDateJobBeSkippedWhenBusinessDateIsNotEnabled() throws Exception {
given(configurationDomainService.isBusinessDateEnabled()).willReturn(false);
RepeatStatus repeatStatus = underTest.execute(stepContribution, chunkContext);
verify(stepContribution, times(1)).setExitStatus(ExitStatus.NOOP);
assertEquals(RepeatStatus.FINISHED, repeatStatus);
}
@Test
public void shouldBusinessDateJobBeProcessedWhenBusinessDateIsEnabled() throws Exception {
given(configurationDomainService.isBusinessDateEnabled()).willReturn(true);
RepeatStatus repeatStatus = underTest.execute(stepContribution, chunkContext);
verify(increaseDateBy1DayService, times(1)).increaseDateByTypeByOneDay(BusinessDateType.COB_DATE);
assertEquals(RepeatStatus.FINISHED, repeatStatus);
}
}