-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3350654
commit 101a7c0
Showing
2 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 209 additions & 0 deletions
209
...duler-quartz/src/test/java/com/scheduler/quartz/web/controller/JobsControllerIntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
package com.scheduler.quartz.web.controller; | ||
|
||
import com.scheduler.quartz.common.AbstractIntegrationTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
|
||
class JobsControllerIntTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
void testGetJobs() { | ||
mockMvcTester.get().uri("/api").assertThat().hasStatusOk().hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testGetJobsStatuses() { | ||
mockMvcTester.get().uri("/api/statuses").assertThat().hasStatusOk().hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testSaveOrUpdate() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "SampleJob", | ||
"cronExpression": "0/5 * * * * ?", | ||
"jobId": "12345", | ||
"description": "Test job description" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.post() | ||
.uri("/api/saveOrUpdate") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testSaveOrUpdateWithInvalidCronExpression() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "SampleJob", | ||
"cronExpression": "0/5 * * * *", | ||
"jobId": "12345", | ||
"description": "Test job description" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.post() | ||
.uri("/api/saveOrUpdate") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testPauseJob() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "SampleJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.post() | ||
.uri("/api/pauseJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testPauseJobWithInvalidJobName() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "InvalidJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.post() | ||
.uri("/api/pauseJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testResumeJob() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "SampleJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
mockMvcTester | ||
.post() | ||
.uri("/api/resumeJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testResumeJobWithInvalidJobName() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "InvalidJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
mockMvcTester | ||
.post() | ||
.uri("/api/resumeJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testRunJob() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "SampleJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.post() | ||
.uri("/api/runJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testRunJobWithInvalidJobName() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "InvalidJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.post() | ||
.uri("/api/runJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
@Test | ||
void testDeleteJob() { | ||
String requestBody = | ||
""" | ||
{ | ||
"jobName": "SampleJob", | ||
"jobId": "12345" | ||
} | ||
"""; | ||
|
||
mockMvcTester | ||
.delete() | ||
.uri("/api/deleteJob") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON); | ||
} | ||
} |