From 694fe746907375c447bc8875d27f28c9ef808fcf Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Wed, 23 Sep 2020 19:12:25 +0200 Subject: [PATCH] CHECKPOINT: Made configuyrator as a service. Test and java access modifier correction needs to be done before pull request --- .../main/java/com/plannaplan/Controller.java | 41 ------------------- .../ConfiguratorService.java} | 6 +-- .../plannaplan/statisticutils/Statistics.java | 10 ----- .../transferutils/TransferMatcher.java | 9 ---- .../transferutils/TransfersExecuter.java | 9 ---- .../com/plannaplan/types/ActionTypes.java | 5 --- .../java/com/plannaplan/types/AppStates.java | 5 --- .../java/com/plannaplan/types/EventTypes.java | 5 --- .../java/com/plannaplan/TestApplication.java | 2 +- .../FileToDatabaseMigratorTest.java | 23 +++++------ .../services/ConfiguratorServiceTest.java | 26 ++++++++++++ .../plannaplan/services/UserServiceTest.java | 2 + .../controllers/ConfigController.java | 4 +- 13 files changed, 44 insertions(+), 103 deletions(-) delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/Controller.java rename buisnesslogic/src/main/java/com/plannaplan/{Configurator.java => services/ConfiguratorService.java} (83%) delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/statisticutils/Statistics.java delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/transferutils/TransferMatcher.java delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/transferutils/TransfersExecuter.java delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/types/ActionTypes.java delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/types/AppStates.java delete mode 100755 buisnesslogic/src/main/java/com/plannaplan/types/EventTypes.java create mode 100755 buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java diff --git a/buisnesslogic/src/main/java/com/plannaplan/Controller.java b/buisnesslogic/src/main/java/com/plannaplan/Controller.java deleted file mode 100755 index f16ff41..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/Controller.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.plannaplan; - -import com.plannaplan.models.ConfigData; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class Controller { - - @Autowired - private Configurator configurator; - - public Controller() { - } - - public void startApp() { - } - - public void assignCourse() { - } - - public void addUnavailibility() { - } - - public void addGroup() { - } - - public void editGroup() { - } - - public void getHistoryAtPoint() { - } - - public void config(ConfigData data) { - configurator.config(data); - } - - public void createTransfer() { - } -} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/Configurator.java b/buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java similarity index 83% rename from buisnesslogic/src/main/java/com/plannaplan/Configurator.java rename to buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java index 19a4bb0..500015a 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/Configurator.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java @@ -1,4 +1,4 @@ -package com.plannaplan; +package com.plannaplan.services; import com.plannaplan.models.ConfigData; import com.plannaplan.models.FileData; @@ -9,12 +9,12 @@ import org.springframework.stereotype.Component; import com.plannaplan.configutils.*; @Component -public class Configurator { +public class ConfiguratorService { @Autowired FileToDatabaseMigrator migrator; - public Configurator() { + public ConfiguratorService() { } public void config(ConfigData data) { diff --git a/buisnesslogic/src/main/java/com/plannaplan/statisticutils/Statistics.java b/buisnesslogic/src/main/java/com/plannaplan/statisticutils/Statistics.java deleted file mode 100755 index ac75813..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/statisticutils/Statistics.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.plannaplan.statisticutils; - -public class Statistics { - - public Statistics() { - } - - public void getAll() { - } -} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/transferutils/TransferMatcher.java b/buisnesslogic/src/main/java/com/plannaplan/transferutils/TransferMatcher.java deleted file mode 100755 index 6395220..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/transferutils/TransferMatcher.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plannaplan.transferutils; - -public class TransferMatcher { - public TransferMatcher() { - } - - public void findMatches() { - } -} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/transferutils/TransfersExecuter.java b/buisnesslogic/src/main/java/com/plannaplan/transferutils/TransfersExecuter.java deleted file mode 100755 index 43db7c9..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/transferutils/TransfersExecuter.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plannaplan.transferutils; - -public class TransfersExecuter { - public TransfersExecuter() { - } - - public void execute() { - } -} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/types/ActionTypes.java b/buisnesslogic/src/main/java/com/plannaplan/types/ActionTypes.java deleted file mode 100755 index 5088138..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/types/ActionTypes.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.plannaplan.types; - -public enum ActionTypes { - ADD, DELETE, REPLACE -} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/types/AppStates.java b/buisnesslogic/src/main/java/com/plannaplan/types/AppStates.java deleted file mode 100755 index 4983619..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/types/AppStates.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.plannaplan.types; - -public enum AppStates { - STOPPED, RUNNING, PAUSED -} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/types/EventTypes.java b/buisnesslogic/src/main/java/com/plannaplan/types/EventTypes.java deleted file mode 100755 index 73ca9b0..0000000 --- a/buisnesslogic/src/main/java/com/plannaplan/types/EventTypes.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.plannaplan.types; - -public enum EventTypes { - DROPPED_OUT, TOUR_STARTED, TRANSFER_FOUND, TOUR_FINISHED, COURSES_ACCEPTED -} \ No newline at end of file diff --git a/buisnesslogic/src/test/java/com/plannaplan/TestApplication.java b/buisnesslogic/src/test/java/com/plannaplan/TestApplication.java index 613d816..b47ea28 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/TestApplication.java +++ b/buisnesslogic/src/test/java/com/plannaplan/TestApplication.java @@ -4,5 +4,5 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class TestApplication { - + public final static String TEST_CONFIG_FILE = "Zajecia.xlsx"; } diff --git a/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java b/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java index 65dc116..0129999 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java @@ -9,8 +9,7 @@ import static org.junit.Assert.assertTrue; import java.io.InputStream; -import com.plannaplan.Configurator; -import com.plannaplan.models.ConfigData; +import com.plannaplan.TestApplication; import com.plannaplan.services.CourseService; import com.plannaplan.services.GroupService; import com.plannaplan.services.LecturerService; @@ -18,31 +17,29 @@ 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 + FileToDatabaseMigrator migrator; + @Autowired private CourseService courseService; @Autowired private GroupService groupService; - @Autowired + @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); + public void shouldImportDataFromFileToDatabase() throws Exception { + final InputStream inputStream = getClass().getClassLoader() + .getResourceAsStream(TestApplication.TEST_CONFIG_FILE); + final FileReader reader = new FileReader(inputStream); + this.migrator.migrate(reader.read()); int courses_ammount = this.courseService.getCoursesAmmount(); int groups_ammount = this.groupService.getGroupsAmmount(); int lecturers_ammount = this.lecturerService.getLecturersAmmount(); diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java new file mode 100755 index 0000000..e23b7a5 --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java @@ -0,0 +1,26 @@ +package com.plannaplan.services; + +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 org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ContextConfiguration +public class ConfiguratorServiceTest { + + @Autowired + ConfiguratorService configuratorService; + + @Test + public void shouldImportDataToDataBase() { + + } + +} diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java index 7a764f6..b7308fa 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java @@ -12,6 +12,7 @@ import com.plannaplan.exceptions.UserNotFoundException; import com.plannaplan.types.UserRoles; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; @@ -40,6 +41,7 @@ public class UserServiceTest { } @Test + @Ignore public void shouldReturnToken() { try { String token = this.userService.login(TEST_USER_MAIL); diff --git a/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java b/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java index 6438c74..1ce9aa9 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java @@ -6,8 +6,8 @@ import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import com.plannaplan.App; -import com.plannaplan.Controller; import com.plannaplan.models.ConfigData; +import com.plannaplan.services.ConfiguratorService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -23,7 +23,7 @@ import org.springframework.web.multipart.MultipartFile; public class ConfigController { @Autowired - private Controller contrl; + private ConfiguratorService contrl; @PostMapping("/config") public ResponseEntity configApp(@RequestParam("file") MultipartFile file) {