mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2026-05-14 22:00:30 +09:00
#103 final step into multi-trigger feature
This commit is contained in:
1
quartz-manager-parent/.gitignore
vendored
1
quartz-manager-parent/.gitignore
vendored
@@ -4,3 +4,4 @@
|
||||
.classpath
|
||||
.project
|
||||
.idea
|
||||
/**/*.iml
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
|
||||
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
|
||||
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
|
||||
<sonar-maven-plugin.version>3.11.0.3922</sonar-maven-plugin.version>
|
||||
<sonar.organization>fabioformosa</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<sonar.exclusions>
|
||||
@@ -133,6 +134,11 @@
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${maven-failsafe-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>${sonar-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
|
||||
@@ -18,13 +18,17 @@ import java.util.Date;
|
||||
@SpringBootTest
|
||||
class SimpleTriggerServiceIntegrationTest {
|
||||
|
||||
private static final String SAMPLE_JOB_CLASS = "it.fabioformosa.quartzmanager.api.jobs.SampleJob";
|
||||
private static final String SAMPLE_EXTRA_JOB_CLASS = "it.fabioformosa.samplepackage.SampleExtraJob";
|
||||
private static final String FIRST_TRIGGER_SUFFIX = "A";
|
||||
private static final String SECOND_TRIGGER_SUFFIX = "B";
|
||||
|
||||
@Autowired
|
||||
private SimpleTriggerService simpleTriggerService;
|
||||
|
||||
@Test
|
||||
void givenASimpleTriggerCommandDTOWithAllData_whenANewSimpleTriggerIsScheduled_thenShouldGetATriggertDTO() throws SchedulerException, ClassNotFoundException {
|
||||
String simpleTriggerTestName = "simpleTriggerWithAllData";
|
||||
String jobClass = "it.fabioformosa.quartzmanager.api.jobs.SampleJob";
|
||||
Date startDate = new Date();
|
||||
Date endDate = DateUtils.addHoursToNow(5);
|
||||
int repeatCount = 3;
|
||||
@@ -41,7 +45,7 @@ class SimpleTriggerServiceIntegrationTest {
|
||||
.repeatCount(repeatCount)
|
||||
.repeatInterval(repeatInterval)
|
||||
.misfireInstruction(misfireInstructionFireNow)
|
||||
.jobClass(jobClass)
|
||||
.jobClass(SAMPLE_JOB_CLASS)
|
||||
.build())
|
||||
.build();
|
||||
SimpleTriggerDTO simpleTriggerDTO = simpleTriggerService.scheduleSimpleTrigger(simpleTriggerCommand);
|
||||
@@ -61,12 +65,11 @@ class SimpleTriggerServiceIntegrationTest {
|
||||
@Test
|
||||
void givenASimpleTriggerCommandDTOWithMissingOptionalField_whenANewSimpleTriggerIsScheduled_thenShouldGetATriggertDTO() throws SchedulerException, ClassNotFoundException {
|
||||
String simpleTriggerTestName = "simpleTriggerWithoutOptionalData";
|
||||
String jobClass = "it.fabioformosa.quartzmanager.api.jobs.SampleJob";
|
||||
|
||||
SimpleTriggerCommandDTO simpleTriggerCommand = SimpleTriggerCommandDTO.builder()
|
||||
.triggerName(simpleTriggerTestName)
|
||||
.simpleTriggerInputDTO(SimpleTriggerInputDTO.builder()
|
||||
.jobClass(jobClass)
|
||||
.jobClass(SAMPLE_JOB_CLASS)
|
||||
.build())
|
||||
.build();
|
||||
SimpleTriggerDTO simpleTriggerDTO = simpleTriggerService.scheduleSimpleTrigger(simpleTriggerCommand);
|
||||
@@ -81,4 +84,49 @@ class SimpleTriggerServiceIntegrationTest {
|
||||
Assertions.assertThat(simpleTriggerDTO.getRepeatInterval()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTwoSimpleTriggerCommandDTOsForTheSameJob_whenScheduled_thenShouldCreateTwoTriggers() throws SchedulerException, ClassNotFoundException {
|
||||
String triggerNamePrefix = "sameJobTrigger" + System.nanoTime();
|
||||
|
||||
SimpleTriggerDTO firstTrigger = simpleTriggerService.scheduleSimpleTrigger(
|
||||
buildSimpleTriggerCommand(triggerNamePrefix + FIRST_TRIGGER_SUFFIX, SAMPLE_JOB_CLASS)
|
||||
);
|
||||
SimpleTriggerDTO secondTrigger = simpleTriggerService.scheduleSimpleTrigger(
|
||||
buildSimpleTriggerCommand(triggerNamePrefix + SECOND_TRIGGER_SUFFIX, SAMPLE_JOB_CLASS)
|
||||
);
|
||||
|
||||
Assertions.assertThat(firstTrigger.getTriggerKeyDTO().getName()).isEqualTo(triggerNamePrefix + FIRST_TRIGGER_SUFFIX);
|
||||
Assertions.assertThat(secondTrigger.getTriggerKeyDTO().getName()).isEqualTo(triggerNamePrefix + SECOND_TRIGGER_SUFFIX);
|
||||
Assertions.assertThat(firstTrigger.getJobDetailDTO().getJobClassName()).isEqualTo(SAMPLE_JOB_CLASS);
|
||||
Assertions.assertThat(secondTrigger.getJobDetailDTO().getJobClassName()).isEqualTo(SAMPLE_JOB_CLASS);
|
||||
Assertions.assertThat(firstTrigger.getJobKeyDTO().getName()).isNotEqualTo(secondTrigger.getJobKeyDTO().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTwoSimpleTriggerCommandDTOsForDifferentJobs_whenScheduled_thenShouldCreateTwoTriggers() throws SchedulerException, ClassNotFoundException {
|
||||
String triggerNamePrefix = "differentJobTrigger" + System.nanoTime();
|
||||
|
||||
SimpleTriggerDTO firstTrigger = simpleTriggerService.scheduleSimpleTrigger(
|
||||
buildSimpleTriggerCommand(triggerNamePrefix + FIRST_TRIGGER_SUFFIX, SAMPLE_JOB_CLASS)
|
||||
);
|
||||
SimpleTriggerDTO secondTrigger = simpleTriggerService.scheduleSimpleTrigger(
|
||||
buildSimpleTriggerCommand(triggerNamePrefix + SECOND_TRIGGER_SUFFIX, SAMPLE_EXTRA_JOB_CLASS)
|
||||
);
|
||||
|
||||
Assertions.assertThat(firstTrigger.getTriggerKeyDTO().getName()).isEqualTo(triggerNamePrefix + FIRST_TRIGGER_SUFFIX);
|
||||
Assertions.assertThat(secondTrigger.getTriggerKeyDTO().getName()).isEqualTo(triggerNamePrefix + SECOND_TRIGGER_SUFFIX);
|
||||
Assertions.assertThat(firstTrigger.getJobDetailDTO().getJobClassName()).isEqualTo(SAMPLE_JOB_CLASS);
|
||||
Assertions.assertThat(secondTrigger.getJobDetailDTO().getJobClassName()).isEqualTo(SAMPLE_EXTRA_JOB_CLASS);
|
||||
}
|
||||
|
||||
private static SimpleTriggerCommandDTO buildSimpleTriggerCommand(String triggerName, String jobClass) {
|
||||
return SimpleTriggerCommandDTO.builder()
|
||||
.triggerName(triggerName)
|
||||
.simpleTriggerInputDTO(SimpleTriggerInputDTO.builder()
|
||||
.jobClass(jobClass)
|
||||
.startDate(DateUtils.addHoursToNow(1))
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package it.fabioformosa.quartzmanager.api.websockets;
|
||||
|
||||
import it.fabioformosa.quartzmanager.api.dto.TriggerFiredBundleDTO;
|
||||
import it.fabioformosa.quartzmanager.api.jobs.entities.LogRecord;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||
|
||||
import static org.mockito.MockitoAnnotations.openMocks;
|
||||
|
||||
class WebSocketNotifierTest {
|
||||
|
||||
@InjectMocks
|
||||
private WebSocketLogsNotifier webSocketLogsNotifier;
|
||||
|
||||
@InjectMocks
|
||||
private WebSocketProgressNotifier webSocketProgressNotifier;
|
||||
|
||||
@Mock
|
||||
private SimpMessageSendingOperations messagingTemplate;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenATriggerName_whenALogIsSent_thenShouldSendItToTheTriggerLogsTopic() {
|
||||
LogRecord logRecord = new LogRecord(LogRecord.LogType.INFO, "Hello!");
|
||||
|
||||
webSocketLogsNotifier.send("trigger-1", logRecord);
|
||||
|
||||
Mockito.verify(messagingTemplate).convertAndSend("/topic/logs/trigger-1", logRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenATriggerName_whenProgressIsSent_thenShouldSendItToTheTriggerProgressTopic() {
|
||||
TriggerFiredBundleDTO triggerFiredBundleDTO = new TriggerFiredBundleDTO();
|
||||
|
||||
webSocketProgressNotifier.send("trigger-1", triggerFiredBundleDTO);
|
||||
|
||||
Mockito.verify(messagingTemplate).convertAndSend("/topic/progress/trigger-1", triggerFiredBundleDTO);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user