diff --git a/quartz-manager-parent/quartz-manager-common/pom.xml b/quartz-manager-parent/quartz-manager-common/pom.xml
index cb1510df..a51d260c 100644
--- a/quartz-manager-parent/quartz-manager-common/pom.xml
+++ b/quartz-manager-parent/quartz-manager-common/pom.xml
@@ -1,17 +1,23 @@
-
- 4.0.0
-
- it.fabioformosa.quartz-manager
- quartz-manager-parent
- 3.0.2-SNAPSHOT
-
- quartz-manager-common
-
-
-
- org.projectlombok
- lombok
- provided
-
-
-
\ No newline at end of file
+
+ 4.0.0
+
+ it.fabioformosa.quartz-manager
+ quartz-manager-parent
+ 3.0.2-SNAPSHOT
+
+ quartz-manager-common
+
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.8.1
+ test
+
+
+
diff --git a/quartz-manager-parent/quartz-manager-common/src/main/java/it/fabioformosa/quartzmanager/common/utils/DateUtils.java b/quartz-manager-parent/quartz-manager-common/src/main/java/it/fabioformosa/quartzmanager/common/utils/DateUtils.java
new file mode 100644
index 00000000..c0cef7ec
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-common/src/main/java/it/fabioformosa/quartzmanager/common/utils/DateUtils.java
@@ -0,0 +1,18 @@
+package it.fabioformosa.quartzmanager.common.utils;
+
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
+
+public class DateUtils {
+
+ static public Date fromLocaleDateTimeToDate(LocalDateTime localDateTime){
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ static public Date getHoursFromNow(long hours){
+ return DateUtils.fromLocaleDateTimeToDate(LocalDateTime.now().plus(Duration.ofHours(hours)));
+ }
+
+}
diff --git a/quartz-manager-parent/quartz-manager-starter-api/pom.xml b/quartz-manager-parent/quartz-manager-starter-api/pom.xml
index b200ffa1..395b3f48 100644
--- a/quartz-manager-parent/quartz-manager-starter-api/pom.xml
+++ b/quartz-manager-parent/quartz-manager-starter-api/pom.xml
@@ -130,6 +130,13 @@
springfox-swagger-ui
${springfox.version}
+
+
+
+ org.junit.platform
+ junit-platform-launcher
+ test
+
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/controllers/TriggerController.java b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/controllers/TriggerController.java
index 19c3f138..73307698 100644
--- a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/controllers/TriggerController.java
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/controllers/TriggerController.java
@@ -7,14 +7,17 @@
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@Slf4j
-@RequestMapping("/quartz-manager/triggers")
+@RequestMapping(TriggerController.TRIGGER_CONTROLLER_BASE_URL)
@RestController
@Api(value = "triggers")
public class TriggerController {
+ static public final String TRIGGER_CONTROLLER_BASE_URL = "/quartz-manager/triggers";
+
@Value("${quartz-manager.jobClass}")
private String jobClassname;
@@ -29,6 +32,7 @@ public TriggerDTO getTrigger(@PathVariable String name) throws SchedulerExceptio
return schedulerService.getTriggerByName(name);
}
+ @ResponseStatus(HttpStatus.CREATED)
@PostMapping("/{name}")
public TriggerDTO postTrigger(@PathVariable String name, @RequestBody SchedulerConfigParam config) throws SchedulerException, ClassNotFoundException {
log.info("TRIGGER - CREATING a trigger {} {}", name, config);
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/JobKeyDTO.java b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/JobKeyDTO.java
index 1a9bfc3a..d1b302e2 100644
--- a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/JobKeyDTO.java
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/JobKeyDTO.java
@@ -1,5 +1,8 @@
package it.fabioformosa.quartzmanager.dto;
+import lombok.Builder;
+
+@Builder
public class JobKeyDTO {
private String name;
private String group;
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/SchedulerConfigParam.java b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/SchedulerConfigParam.java
index 60026ae1..f259a964 100644
--- a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/SchedulerConfigParam.java
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/SchedulerConfigParam.java
@@ -1,11 +1,13 @@
package it.fabioformosa.quartzmanager.dto;
import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
+@Builder
@Data
public class SchedulerConfigParam {
public long triggerPerDay;
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerDTO.java b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerDTO.java
index ff41c222..952c9b5a 100644
--- a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerDTO.java
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerDTO.java
@@ -1,6 +1,7 @@
package it.fabioformosa.quartzmanager.dto;
import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -9,6 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Data
+@Builder
public class TriggerDTO {
private TriggerKeyDTO triggerKeyDTO;
private int priority;
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerKeyDTO.java b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerKeyDTO.java
index 4a26e048..2992b48f 100644
--- a/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerKeyDTO.java
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/main/java/it/fabioformosa/quartzmanager/dto/TriggerKeyDTO.java
@@ -1,5 +1,8 @@
package it.fabioformosa.quartzmanager.dto;
+import lombok.Builder;
+
+@Builder
public class TriggerKeyDTO {
private String name;
private String group;
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/QuartManagerApplicationTests.java b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/QuartManagerApplicationTests.java
new file mode 100644
index 00000000..97f14ef8
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/QuartManagerApplicationTests.java
@@ -0,0 +1,13 @@
+package it.fabioformosa.quartzmanager;
+
+import org.junit.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class QuartManagerApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java
new file mode 100644
index 00000000..aabdc42c
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java
@@ -0,0 +1,54 @@
+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.Disabled;
+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;
+
+@Disabled
+@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-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java
new file mode 100644
index 00000000..34333cfa
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java
@@ -0,0 +1,15 @@
+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-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java
new file mode 100644
index 00000000..6c04827c
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-starter-api/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java
@@ -0,0 +1,33 @@
+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();
+ }
+
+}
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
new file mode 100644
index 00000000..a4d38797
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/TriggerControllerTest.java
@@ -0,0 +1,52 @@
+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
new file mode 100644
index 00000000..34333cfa
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TestUtils.java
@@ -0,0 +1,15 @@
+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
new file mode 100644
index 00000000..6c04827c
--- /dev/null
+++ b/quartz-manager-parent/quartz-manager-web-showcase/src/test/java/it/fabioformosa/quartzmanager/controllers/utils/TriggerUtils.java
@@ -0,0 +1,33 @@
+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();
+ }
+
+}