Added new test for new columns and update groups

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-12-26 14:18:47 +01:00
parent f51979484f
commit c3d78505c8
Signed by: y0rune
GPG Key ID: F204C385F57EB348
5 changed files with 79 additions and 2 deletions

View File

@ -92,8 +92,12 @@ public class FileToDatabaseMigrator {
.orElseGet(() -> this.lecturerService
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
this.groupService.find(zajCykId, grNr).orElseGet(
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr)));
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr));
group.update(capacity, room, course, time, null, groupDay, lecturer);
this.groupService.save(group);
}

View File

@ -130,6 +130,47 @@ public class Groups {
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer);
}
/**
* Updates given values other that are not null
*
* @param capacity capacity given to the groups
* @param room room given to the groups
* @param course course given to the groups
* @param time time given to the groups
* @param endTime end time of class in minutes
* @param day day given to the groups
* @param lecturer lecturer given to the groups
*/
public void update(Integer capacity, String room, Course course, Integer time, Integer endTime, WeekDay day, Lecturer lecturer){
if (capacity != null){
this.capacity = capacity;
}
if (room != null){
this.room = room;
}
if (course != null){
this.course = course;
}
if (time != null){
this.time = time;
}
if (endTime != null){
this.endTime = endTime;
}
if (day != null){
this.day = day;
}
if (lecturer != null){
this.lecturer = lecturer;
}
}
/**
* get time of class end
*

View File

@ -2,6 +2,8 @@ package com.plannaplan.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.MethodMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@ -9,9 +11,11 @@ import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.sql.Date;
import java.util.Optional;
import com.plannaplan.TestApplication;
import com.plannaplan.entities.AppConfig;
import com.plannaplan.entities.Groups;
import com.plannaplan.models.ConfigData;
import com.plannaplan.models.TourData;
import com.plannaplan.repositories.AppConfigRepository;
@ -24,6 +28,9 @@ import org.junit.runner.RunWith;
@ContextConfiguration
public class ConfiguratorServiceTest {
private final static String BEFORE_UPDATE_FILE = "ZajeciaBeforeUpdate.xlsx";
private final static String AFTER_UPDATE_FILE = "ZajeciaAfterUpdate.xlsx";
@Autowired
private ConfiguratorService configuratorService;
@ -57,6 +64,31 @@ public class ConfiguratorServiceTest {
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
}
@Test
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
public void shouldUpdatePreviousImport(){
final InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream(ConfiguratorServiceTest.BEFORE_UPDATE_FILE);
this.configuratorService.importCoursesStream(inputStream);
int groups_ammount = this.groupService.getGroupsAmmount();
assertTrue(groups_ammount == 2);
final InputStream inputStream2 = getClass().getClassLoader()
.getResourceAsStream(ConfiguratorServiceTest.AFTER_UPDATE_FILE);
this.configuratorService.importCoursesStream(inputStream2);
int groups_ammount2 = this.groupService.getGroupsAmmount();
Optional<Groups> newGroup = this.groupService.find(456458, 3);
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."));
}
@Test
public void shouldRetrunNewestConfig() throws InterruptedException {
final Date dateToCheck = new Date(System.currentTimeMillis());