Skip to content

Commit

Permalink
adds assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 22, 2024
1 parent 101a7c0 commit 4ba0017
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static Message success(String msg) {
return new Message(true, msg);
}

public Message() {
super();
}

public Message(boolean valid, String msg) {
super();
this.valid = valid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
package com.scheduler.quartz.web.controller;

import static org.assertj.core.api.Assertions.assertThat;

import com.scheduler.quartz.common.AbstractIntegrationTest;
import com.scheduler.quartz.model.common.Message;
import java.util.List;
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);
mockMvcTester
.get()
.uri("/api")
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(List.class);
}

@Test
void testGetJobsStatuses() {
mockMvcTester.get().uri("/api/statuses").assertThat().hasStatusOk().hasContentType(MediaType.APPLICATION_JSON);
mockMvcTester
.get()
.uri("/api/statuses")
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(List.class);
}

@Test
void testSaveOrUpdate() {
String requestBody =
"""
{
"jobName": "SampleJob",
"cronExpression": "0/5 * * * * ?",
"jobId": "12345",
"description": "Test job description"
}
""";
{
"jobName": "SampleJob",
"cronExpression": "0/5 * * * * ?",
"jobId": "12345",
"description": "Test job description"
}
""";

mockMvcTester
.post()
Expand All @@ -36,7 +54,14 @@ void testSaveOrUpdate() {
.accept(MediaType.APPLICATION_JSON)
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON);
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(Message.class)
.satisfies(message -> {
assertThat(message.getMsg()).isNull();
assertThat(message.isValid()).isEqualTo(true);
assertThat(message.getData()).isNull();
});
}

@Test
Expand All @@ -59,7 +84,12 @@ void testSaveOrUpdateWithInvalidCronExpression() {
.accept(MediaType.APPLICATION_JSON)
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON);
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(Message.class)
.satisfies(message -> {
assertThat(message.getMsg()).isEqualTo("CronExpression '0/5 * * * *' is invalid.");
});
}

@Test
Expand Down Expand Up @@ -101,7 +131,12 @@ void testPauseJobWithInvalidJobName() {
.accept(MediaType.APPLICATION_JSON)
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON);
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(Message.class)
.satisfies(message -> {
assertThat(message.getMsg()).isEqualTo("Job does not exist with key: DEFAULT.InvalidJob");
});
}

@Test
Expand Down Expand Up @@ -141,7 +176,12 @@ void testResumeJobWithInvalidJobName() {
.accept(MediaType.APPLICATION_JSON)
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON);
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(Message.class)
.satisfies(message -> {
assertThat(message.getMsg()).isEqualTo("Job does not exist with key: DEFAULT.InvalidJob");
});
}

@Test
Expand Down Expand Up @@ -183,7 +223,12 @@ void testRunJobWithInvalidJobName() {
.accept(MediaType.APPLICATION_JSON)
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON);
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(Message.class)
.satisfies(message -> {
assertThat(message.getMsg()).isEqualTo("Job does not exist with key: DEFAULT.InvalidJob");
});
}

@Test
Expand All @@ -206,4 +251,30 @@ void testDeleteJob() {
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON);
}

@Test
void testDeleteJobWithInvalidJobName() {
String requestBody =
"""
{
"jobName": "InvalidJob",
"jobId": "12345"
}
""";

mockMvcTester
.delete()
.uri("/api/deleteJob")
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
.accept(MediaType.APPLICATION_JSON)
.assertThat()
.hasStatusOk()
.hasContentType(MediaType.APPLICATION_JSON)
.bodyJson()
.convertTo(Message.class)
.satisfies(message -> {
assertThat(message.getMsg()).isEqualTo("Job does not exist with key: DEFAULT.InvalidJob");
});
}
}

0 comments on commit 4ba0017

Please sign in to comment.