Added tests
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.sql.Date;
|
||||
@ -141,22 +140,50 @@ public class AppConfigTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnFirstStartDatesCorns() {
|
||||
assertFalse(false);
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getFirstTourStartCron().getExpression().equals("0 0 0 12 11 ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSecondStartDatesCorns() {
|
||||
assertFalse(false);
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getSecondTourStartCron().getExpression().equals("0 0 0 14 11 ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFirstEndDatesCorns() {
|
||||
assertFalse(false);
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getFirstTourEndCron().getExpression().equals("0 0 0 13 11 ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSecondEndDatesCorns() {
|
||||
assertFalse(false);
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getSecondTourEndCron().getExpression().equals("0 0 0 15 11 ?"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,8 +10,11 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import com.plannaplan.TestApplication;
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
@ -46,6 +49,9 @@ public class ConfiguratorServiceTest {
|
||||
@Autowired
|
||||
private AppConfigRepository appConfigRepo;
|
||||
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
|
||||
@Test
|
||||
public void shouldImportDataToDataBase() {
|
||||
final InputStream inputStream = getClass().getClassLoader()
|
||||
@ -102,8 +108,27 @@ public class ConfiguratorServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shlouldScheduleTaskWhenSetTourDate() {
|
||||
assertTrue(false);
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shlouldScheduleTaskWhenSetTourDate()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
final InputStream inputStream = getClass().getClassLoader()
|
||||
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
||||
final ConfigData data = new ConfigData(
|
||||
new TourData(new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 86400000)),
|
||||
new TourData(new Date(System.currentTimeMillis() + 86400000),
|
||||
new Date(System.currentTimeMillis() + 2 * 86400000)),
|
||||
inputStream);
|
||||
this.configuratorService.config(data);
|
||||
|
||||
final Field reader = EventService.class.getDeclaredField("jobsMap");
|
||||
reader.setAccessible(true);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<Integer, ScheduledFuture<?>> map = (Map<Integer, ScheduledFuture<?>>) reader.get(this.eventService);
|
||||
|
||||
assertTrue(map.size() == 2);
|
||||
assertTrue(map.get(EventService.FIRST_TOUR_SCHEDULE).isDone() == false);
|
||||
assertTrue(map.get(EventService.SECOND_TOUR_SCHEDULE).isDone() == false);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user