Skip to content

Commit

Permalink
adds integrationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 22, 2024
1 parent 3350654 commit 101a7c0
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.assertj.MockMvcTester;

@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(
Expand All @@ -18,7 +18,7 @@
public abstract class AbstractIntegrationTest {

@Autowired
protected MockMvc mockMvc;
protected MockMvcTester mockMvcTester;

@Autowired
protected ObjectMapper objectMapper;
Expand Down
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);
}
}

0 comments on commit 101a7c0

Please sign in to comment.