2020-09-23 19:12:25 +02:00
|
|
|
package com.plannaplan.services;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
2020-12-26 14:18:47 +01:00
|
|
|
import org.springframework.test.annotation.DirtiesContext;
|
|
|
|
import org.springframework.test.annotation.DirtiesContext.MethodMode;
|
2020-09-23 19:12:25 +02:00
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
2020-09-24 17:44:23 +02:00
|
|
|
import java.io.InputStream;
|
2020-12-11 18:08:23 +01:00
|
|
|
import java.sql.Date;
|
2020-12-26 14:18:47 +01:00
|
|
|
import java.util.Optional;
|
2020-09-24 17:44:23 +02:00
|
|
|
|
|
|
|
import com.plannaplan.TestApplication;
|
2020-12-11 18:08:23 +01:00
|
|
|
import com.plannaplan.entities.AppConfig;
|
2020-12-26 14:18:47 +01:00
|
|
|
import com.plannaplan.entities.Groups;
|
2020-09-24 17:44:23 +02:00
|
|
|
import com.plannaplan.models.ConfigData;
|
2020-12-11 18:08:23 +01:00
|
|
|
import com.plannaplan.models.TourData;
|
|
|
|
import com.plannaplan.repositories.AppConfigRepository;
|
2020-09-24 17:44:23 +02:00
|
|
|
|
2020-09-23 19:12:25 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
@SpringBootTest
|
|
|
|
@ContextConfiguration
|
|
|
|
public class ConfiguratorServiceTest {
|
|
|
|
|
2020-12-26 14:18:47 +01:00
|
|
|
private final static String BEFORE_UPDATE_FILE = "ZajeciaBeforeUpdate.xlsx";
|
|
|
|
private final static String AFTER_UPDATE_FILE = "ZajeciaAfterUpdate.xlsx";
|
|
|
|
|
2020-09-23 19:12:25 +02:00
|
|
|
@Autowired
|
2020-09-25 16:43:24 +02:00
|
|
|
private ConfiguratorService configuratorService;
|
2020-09-23 19:12:25 +02:00
|
|
|
|
2020-09-24 17:44:23 +02:00
|
|
|
@Autowired
|
|
|
|
private CourseService courseService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private GroupService groupService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private LecturerService lecturerService;
|
|
|
|
|
2020-12-11 18:08:23 +01:00
|
|
|
@Autowired
|
|
|
|
private AppConfigRepository appConfigRepo;
|
|
|
|
|
2020-09-23 19:12:25 +02:00
|
|
|
@Test
|
|
|
|
public void shouldImportDataToDataBase() {
|
2020-09-24 17:44:23 +02:00
|
|
|
final InputStream inputStream = getClass().getClassLoader()
|
|
|
|
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
2020-12-11 18:08:23 +01:00
|
|
|
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);
|
2020-09-24 17:44:23 +02:00
|
|
|
this.configuratorService.config(data);
|
|
|
|
|
|
|
|
int courses_ammount = this.courseService.getCoursesAmmount();
|
|
|
|
int groups_ammount = this.groupService.getGroupsAmmount();
|
|
|
|
int lecturers_ammount = this.lecturerService.getLecturersAmmount();
|
2020-09-23 19:12:25 +02:00
|
|
|
|
2020-09-24 17:44:23 +02:00
|
|
|
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
|
2020-09-23 19:12:25 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 14:18:47 +01:00
|
|
|
@Test
|
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
2021-01-04 18:10:14 +01:00
|
|
|
public void shouldUpdatePreviousImport() {
|
2020-12-26 14:18:47 +01:00
|
|
|
final InputStream inputStream = getClass().getClassLoader()
|
2021-01-04 18:10:14 +01:00
|
|
|
.getResourceAsStream(ConfiguratorServiceTest.BEFORE_UPDATE_FILE);
|
2020-12-26 14:18:47 +01:00
|
|
|
this.configuratorService.importCoursesStream(inputStream);
|
|
|
|
int groups_ammount = this.groupService.getGroupsAmmount();
|
2021-01-04 18:10:14 +01:00
|
|
|
|
2020-12-26 14:18:47 +01:00
|
|
|
assertTrue(groups_ammount == 2);
|
|
|
|
|
|
|
|
final InputStream inputStream2 = getClass().getClassLoader()
|
2021-01-04 18:10:14 +01:00
|
|
|
.getResourceAsStream(ConfiguratorServiceTest.AFTER_UPDATE_FILE);
|
2020-12-26 14:18:47 +01:00
|
|
|
this.configuratorService.importCoursesStream(inputStream2);
|
|
|
|
int groups_ammount2 = this.groupService.getGroupsAmmount();
|
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
Optional<Groups> newGroup = this.groupService.find(456458, 3);
|
2020-12-26 14:18:47 +01:00
|
|
|
Optional<Groups> updateGroup = this.groupService.find(456457, 2);
|
|
|
|
|
|
|
|
assertTrue(groups_ammount2 == 3);
|
|
|
|
assertTrue(newGroup.isPresent());
|
|
|
|
assertTrue(updateGroup.get().getLecturer().getSurname().equals("Murawski"));
|
|
|
|
assertTrue(updateGroup.get().getLecturer().getName().equals("Roman"));
|
|
|
|
assertTrue(updateGroup.get().getLecturer().getTitle().equals("prof. dr hab."));
|
|
|
|
}
|
|
|
|
|
2020-12-11 18:08:23 +01:00
|
|
|
@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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
@Test
|
|
|
|
public void shlouldScheduleTaskWhenSetTourDate() {
|
|
|
|
assertTrue(false);
|
|
|
|
}
|
|
|
|
|
2020-09-23 19:12:25 +02:00
|
|
|
}
|