From 0b807e355c0c4b39d8affeda9667ecd9696ce7b4 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Wed, 9 Dec 2020 17:43:48 +0100 Subject: [PATCH] chckpoint: test to buisnesslogic/src/test/java/com/plannaplan/repositories/AppConfigRepositoryTest.java --- .../repositories/AppConfigRepository.java | 3 ++ .../plannaplan/services/AppConfigService.java | 1 + .../repositories/AppConfigRepositoryTest.java | 33 +++++++++++++++++++ .../controllers/ConfigControllerTest.java | 23 +++++++++++++ 4 files changed, 60 insertions(+) create mode 100755 buisnesslogic/src/test/java/com/plannaplan/repositories/AppConfigRepositoryTest.java diff --git a/buisnesslogic/src/main/java/com/plannaplan/repositories/AppConfigRepository.java b/buisnesslogic/src/main/java/com/plannaplan/repositories/AppConfigRepository.java index c512311..798f94f 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/repositories/AppConfigRepository.java +++ b/buisnesslogic/src/main/java/com/plannaplan/repositories/AppConfigRepository.java @@ -3,7 +3,10 @@ package com.plannaplan.repositories; import com.plannaplan.entities.AppConfig; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface AppConfigRepository extends JpaRepository { + @Query("FROM AppConfig ORDER BY configDate DESC") + AppConfig getCurrentConfig(); } diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/AppConfigService.java b/buisnesslogic/src/main/java/com/plannaplan/services/AppConfigService.java index 6f66bd5..6950b53 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/AppConfigService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/AppConfigService.java @@ -23,4 +23,5 @@ public class AppConfigService { public AppConfig save(AppConfig appConfig) { return this.repo.save(appConfig); } + } diff --git a/buisnesslogic/src/test/java/com/plannaplan/repositories/AppConfigRepositoryTest.java b/buisnesslogic/src/test/java/com/plannaplan/repositories/AppConfigRepositoryTest.java new file mode 100755 index 0000000..0da417f --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/repositories/AppConfigRepositoryTest.java @@ -0,0 +1,33 @@ +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)); + } +} diff --git a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java index 72cafe8..d07445f 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java @@ -2,11 +2,14 @@ package com.plannaplan.controllers; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; import java.io.InputStream; +import com.plannaplan.entities.AppConfig; import com.plannaplan.entities.User; +import com.plannaplan.services.AppConfigService; import com.plannaplan.services.UserService; import com.plannaplan.types.UserRoles; @@ -36,6 +39,9 @@ public class ConfigControllerTest extends AbstractControllerTest { @Autowired private UserService service; + @Autowired + private AppConfigService configService; + @Test public void shouldReturnNoAuthorized() throws Exception { final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME); @@ -63,6 +69,23 @@ public class ConfigControllerTest extends AbstractControllerTest { } + @Test + public void shouldInsertedDataBeSameInDatabase() throws Exception { + final String mail = "shouldReturnOKAuthorized@ConfigController.test"; + final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN)); + + final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME); + final MockMultipartFile file = new MockMultipartFile("file", inputStream); + final String token = this.service.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020") + .param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020") + .param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token)) + .andExpect(status().isOk()); + assertFalse(true); + } + @Test public void shouldReturnDenyNoAdminAuthorized() throws Exception { final String mail = "shouldReturnDenyNoAdminAuthorized@ConfigController.test";