Last active
July 11, 2018 13:59
-
-
Save safebear/dba7413f423aff282dfbdb57224ca9b9 to your computer and use it in GitHub Desktop.
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
package com.safebear.tasklist.controller; | |
import com.safebear.tasklist.service.TaskService; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
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.junit4.SpringRunner; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | |
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; | |
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | |
@WebMvcTest | |
@RunWith(SpringRunner.class) | |
public class TaskRestControllerTest { | |
protected TaskController taskController; | |
protected MockMvc mockMvc; | |
@MockBean | |
TaskService taskService; | |
@Before | |
public void setUp(){ | |
this.taskController = new TaskController(taskService); | |
mockMvc = MockMvcBuilders.standaloneSetup(taskController).build(); | |
} | |
@Test | |
public void testTaskList() throws Exception { | |
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/tasks")) | |
.andDo(MockMvcResultHandlers.print()) | |
.andExpect(MockMvcResultMatchers.status().isOk()); | |
} | |
@Test | |
public void testSaveTask() throws Exception{ | |
this.mockMvc.perform(MockMvcRequestBuilders | |
.post("/api/tasks/save") | |
.contentType(MediaType.APPLICATION_JSON) | |
.content("{\"taskname\":\"mop the floor\",\"dueDate\":\"05/04/2018\",\"completed\":\"false\"}")) | |
.andDo(MockMvcResultHandlers.print()) | |
.andExpect(MockMvcResultMatchers.status().isOk()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment