json 序列化的时候。忽略不存在的字段。

This commit is contained in:
zhouxiunai
2019-04-28 15:16:03 +08:00
parent c666d23157
commit 0b04cd9447
3 changed files with 43 additions and 0 deletions
@@ -0,0 +1,39 @@
package com.gzzn.omms.msgexchangeapi.controller;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
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;
@RunWith(SpringRunner.class)
@SpringBootTest()
@AutoConfigureMockMvc
public class FlightsControllerTest {
@Autowired
private MockMvc mvc;
/**
* 测试获取所有航班信息接口
* @throws Exception
*/
@Test
public void testGetAllFilghts() throws Exception
{
mvc.
perform(get("/all/flights"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.is_success").value(true))
.andDo(print());
}
}