package com.casic.missiles.controller.system;


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
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;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SystemControllerTest {

    private MockMvc mockMvc;

    @Autowired
    private WebApplicationContext webApplicationContext;

    @Before
    public void setup() {
        // 实例化
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Test
    public void signListPage() throws Exception {
        String jsonRequest = "{\n" +
                "  \"signType\": \"1\",\n" +
                "  \"signNo\": \"\",\n" +
                "  \"signName\": \"\",\n" +
                "  \"signDirector\": \"\",\n" +
                "  \"signUserId\": 0,\n" +
                "  \"createStartTime\": \"\",\n" +
                "  \"createEndTime\": \"\",\n" +
                "  \"ids\": [\n" +
                "    0\n" +
                "  ]\n" +
                "}";
        mockMvc.perform(MockMvcRequestBuilders
                .post("/system/sign/listPage")
                .accept(MediaType.APPLICATION_JSON_VALUE)
                .contentType(MediaType.APPLICATION_JSON_VALUE)
                .content(jsonRequest.getBytes())
        ).andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200"))
                .andDo(MockMvcResultHandlers.print());
    }

}