Removed ConfiguratorTest.java, and rewrite it into configutils/FileToDatabaseMigratorTest.java

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-09-09 16:26:42 +02:00
parent 333ceb9b74
commit 408c8a8242
2 changed files with 41 additions and 58 deletions

View File

@ -1,50 +0,0 @@
package com.plannaplan;
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 static org.junit.Assert.assertTrue;
import java.io.InputStream;
import com.plannaplan.models.ConfigData;
import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.LecturerService;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class ConfiguratorTest {
private static String FILE_NAME = "Zajecia.xlsx";
@Autowired
private Configurator restTemplate;
@Autowired
private CourseService courseService;
@Autowired
private GroupService groupService;
@Autowired
private LecturerService lecturerService;
@Test
public void shouldImportDataFromFileToDatabase() throws Exception {
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
final ConfigData data = new ConfigData(null, null, inputStream);
this.restTemplate.config(data);
int courses_ammount = this.courseService.getCoursesAmmount();
int groups_ammount = this.groupService.getGroupsAmmount();
int lecturers_ammount = this.lecturerService.getLecturersAmmount();
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
}
}

View File

@ -1,19 +1,52 @@
package com.plannaplan.configutils;
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 static org.junit.Assert.assertTrue;
import java.io.InputStream;
import com.plannaplan.models.FileData;
import com.plannaplan.Configurator;
import com.plannaplan.models.ConfigData;
import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.LecturerService;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class FileToDatabaseMigratorTest {
private static String FILE_NAME = "Zajecia.xlsx";
@Autowired
private Configurator restTemplate;
@Autowired
private CourseService courseService;
@Autowired
private GroupService groupService;
@Autowired
private LecturerService lecturerService;
@Test
public void shouldInsertToDatabase() {
// FileToDatabaseMigrator migrator = new FileToDatabaseMigrator();
// InputStream inputStream =
// getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
// FileReader r = new FileReader(inputStream);
// FileData d = r.read();
// migrator.migrate(d);
public void shouldImportDataFromFileToDatabase() throws Exception {
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
final ConfigData data = new ConfigData(null, null, inputStream);
this.restTemplate.config(data);
int courses_ammount = this.courseService.getCoursesAmmount();
int groups_ammount = this.groupService.getGroupsAmmount();
int lecturers_ammount = this.lecturerService.getLecturersAmmount();
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
}
}