Added getting newest config

This commit is contained in:
Filip Izydorczyk
2020-12-11 18:08:23 +01:00
parent 15533525af
commit 5a1108e1bf
5 changed files with 56 additions and 67 deletions

View File

@ -1,33 +0,0 @@
package com.plannaplan.repositories;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.sql.Date;
import com.plannaplan.entities.AppConfig;
import com.plannaplan.models.TourData;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.junit.runner.RunWith;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class AppConfigRepositoryTest {
@Autowired
private AppConfigRepository repo;
@Test
public void shouldReturnNewestConfigInstance() {
final Date dateToCheck = new Date(System.currentTimeMillis());
this.repo.save(new AppConfig(new TourData(null, null), new TourData(null, null)));
this.repo.save(new AppConfig(new TourData(dateToCheck, null), new TourData(null, null)));
assertTrue(this.repo.getCurrentConfig().getFirstTourStart().equals(dateToCheck));
}
}

View File

@ -8,9 +8,13 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.sql.Date;
import com.plannaplan.TestApplication;
import com.plannaplan.entities.AppConfig;
import com.plannaplan.models.ConfigData;
import com.plannaplan.models.TourData;
import com.plannaplan.repositories.AppConfigRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -32,11 +36,18 @@ public class ConfiguratorServiceTest {
@Autowired
private LecturerService lecturerService;
@Autowired
private AppConfigRepository appConfigRepo;
@Test
public void shouldImportDataToDataBase() {
final InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
final ConfigData data = new ConfigData(null, null, inputStream);
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);
int courses_ammount = this.courseService.getCoursesAmmount();
@ -46,4 +57,16 @@ public class ConfiguratorServiceTest {
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
}
@Test
public void shouldRetrunNewestConfig() throws InterruptedException {
final Date dateToCheck = new Date(System.currentTimeMillis());
this.appConfigRepo.save(new AppConfig(new TourData(null, null), new TourData(null, null)));
Thread.sleep(2000);
this.appConfigRepo.save(new AppConfig(new TourData(dateToCheck, null), new TourData(null, null)));
AppConfig response = this.configuratorService.getCurrentConfig();
assertTrue(response.getFirstTourStart() != null);
}
}