mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2025-12-30 22:23:15 +09:00
#37 added some mockMvcTest to TriggerController
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package it.fabioformosa.quartzmanager;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootTest
|
||||
@ComponentScan("it.fabioformosa.quartzmanager")
|
||||
@SpringBootConfiguration
|
||||
public class QuartManagerApplicationTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package it.fabioformosa.quartzmanager.controllers;
|
||||
|
||||
import it.fabioformosa.quartzmanager.QuartManagerApplicationTests;
|
||||
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.context.ContextConfiguration;
|
||||
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.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
|
||||
@Disabled
|
||||
@ContextConfiguration(classes = {QuartManagerApplicationTests.class})
|
||||
@WebMvcTest(controllers = TriggerController.class, properties = {
|
||||
"quartz-manager.jobClass=it.fabioformosa.quartzmanager.jobs.myjobs.SampleJob"
|
||||
})
|
||||
@@ -43,7 +45,7 @@ class TriggerControllerTest {
|
||||
|
||||
SchedulerConfigParam configParamToPost = SchedulerConfigParam.builder().maxCount(20).triggerPerDay(20000L).build();
|
||||
mockMvc.perform(
|
||||
post(TriggerController.TRIGGER_CONTROLLER_BASE_URL + "mytrigger")
|
||||
post(TriggerController.TRIGGER_CONTROLLER_BASE_URL + "/mytrigger")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(TestUtils.toJson(configParamToPost))
|
||||
)
|
||||
@@ -51,4 +53,15 @@ class TriggerControllerTest {
|
||||
.andExpect(MockMvcResultMatchers.content().json(TestUtils.toJson(expectedTriggerDTO)))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenGetIsCalled_thenATriggerIsReturned() throws Exception {
|
||||
TriggerDTO expectedTriggerDTO = TriggerUtils.getTriggerInstance();
|
||||
Mockito.when(schedulerService.getTriggerByName("mytrigger")).thenReturn(expectedTriggerDTO);
|
||||
|
||||
mockMvc.perform(get(TriggerController.TRIGGER_CONTROLLER_BASE_URL + "/mytrigger")
|
||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.content().json(TestUtils.toJson(expectedTriggerDTO)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package it.fabioformosa;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = QuartManagerApplication.class)
|
||||
@WebAppConfiguration
|
||||
public class QuartManagerApplicationTests {
|
||||
|
||||
Reference in New Issue
Block a user