From 27fab8accaea3d22d3fddb8dd3f2f669aa94ec0d Mon Sep 17 00:00:00 2001 From: Fabio Formosa Date: Mon, 1 Nov 2021 19:15:25 +0100 Subject: [PATCH] #39 cleanUp --- .../quartz-manager-web-showcase/pom.xml | 7 +++ .../controllers/TriggerControllerTest.java | 52 ------------------- .../controllers/utils/TestUtils.java | 15 ------ .../controllers/utils/TriggerUtils.java | 33 ------------ 4 files changed, 7 insertions(+), 100 deletions(-) delete mode 100644 quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java delete mode 100644 quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java delete mode 100644 quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java diff --git a/quartz-manager-parent/quartz-manager-web-showcase/pom.xml b/quartz-manager-parent/quartz-manager-web-showcase/pom.xml index d291ec7e..73755dd5 100644 --- a/quartz-manager-parent/quartz-manager-web-showcase/pom.xml +++ b/quartz-manager-parent/quartz-manager-web-showcase/pom.xml @@ -110,6 +110,13 @@ org.apache.commons commons-lang3 + + + + org.junit.platform + junit-platform-launcher + test + diff --git a/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java b/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java deleted file mode 100644 index a4d38797..00000000 --- a/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package it.fabioformosa.quartzmanager.controllers; - -import it.fabioformosa.quartzmanager.controllers.utils.TestUtils; -import it.fabioformosa.quartzmanager.controllers.utils.TriggerUtils; -import it.fabioformosa.quartzmanager.dto.SchedulerConfigParam; -import it.fabioformosa.quartzmanager.dto.TriggerDTO; -import it.fabioformosa.quartzmanager.services.SchedulerService; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import static org.mockito.ArgumentMatchers.any; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; - -@WebMvcTest(controllers = TriggerController.class, properties = { - "quartz-manager.jobClass=it.fabioformosa.quartzmanager.jobs.myjobs.SampleJob" -}) -class TriggerControllerTest { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private SchedulerService schedulerService; - - @AfterEach - void cleanUp(){ - Mockito.reset(schedulerService); - } - - @Test - void givenASchedulerConfigParam_whenPosted_thenANewTriggerIsCreated() throws Exception { - TriggerDTO expectedTriggerDTO = TriggerUtils.getTriggerInstance(); - Mockito.when(schedulerService.scheduleNewTrigger(any(), any(), any())).thenReturn(expectedTriggerDTO); - - SchedulerConfigParam configParamToPost = SchedulerConfigParam.builder().maxCount(20).triggerPerDay(20000L).build(); - mockMvc.perform( - post(TriggerController.TRIGGER_CONTROLLER_BASE_URL + "mytrigger") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.toJson(configParamToPost)) - ) - .andExpect(MockMvcResultMatchers.status().isCreated()) - .andExpect(MockMvcResultMatchers.content().json(TestUtils.toJson(expectedTriggerDTO))) - ; - } -} diff --git a/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java b/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java deleted file mode 100644 index 34333cfa..00000000 --- a/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java +++ /dev/null @@ -1,15 +0,0 @@ -package it.fabioformosa.quartzmanager.controllers.utils; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.SneakyThrows; - -public class TestUtils { - - static public ObjectMapper objectMapper = new ObjectMapper(); - - @SneakyThrows - static public String toJson(Object object){ - return objectMapper.writeValueAsString(object); - }; - -} diff --git a/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java b/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java deleted file mode 100644 index 6c04827c..00000000 --- a/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package it.fabioformosa.quartzmanager.controllers.utils; - -import it.fabioformosa.quartzmanager.common.utils.DateUtils; -import it.fabioformosa.quartzmanager.dto.JobKeyDTO; -import it.fabioformosa.quartzmanager.dto.TriggerDTO; -import it.fabioformosa.quartzmanager.dto.TriggerKeyDTO; - -import java.time.LocalDateTime; - -public class TriggerUtils { - - static public TriggerDTO getTriggerInstance(){ - return TriggerDTO.builder() - .description("sample trigger") - .endTime(DateUtils.getHoursFromNow(2L)) - .finalFireTime(DateUtils.getHoursFromNow(2L)) - .jobKeyDTO(JobKeyDTO.builder() - .group("defaultJobGroup") - .name("sampleJob") - .build()) - .mayFireAgain(true) - .triggerKeyDTO(TriggerKeyDTO.builder() - .group("defaultTriggerGroup") - .name("sampleTrigger") - .build()) - .misfireInstruction(1) - .nextFireTime(DateUtils.getHoursFromNow(1L)) - .priority(1) - .startTime(DateUtils.fromLocaleDateTimeToDate(LocalDateTime.now())) - .build(); - } - -}