springboot @SpringBootTest 단위 테스트 호출 controller 인터페이스
2459 단어 springboot
get、post、put、delete
@Test
public void testGetMethod() throws Exception {
MvcResult result = mockMvc.perform(get("/face/match"))
.andExpect(status().isOk())// testRest get
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))// text/plain;charset=UTF-8
.andReturn();//
System.out.println(result.getResponse().getContentAsString());
}
/** */
@Test
public void testAddFace() throws Exception {
FaceDTO faceDTO = new FaceDTO();
faceDTO.setGroupId("litsoft07");
faceDTO.setUserId("xf");
String image = ImageToBase64Utils.GetImageStrFromPath("C:\\Users\\Administrator\\Desktop\\test.jpg");
log.info(image);
faceDTO.setImage(image);
faceDTO.setImageType(BaiduImageTypeMenu.BASE64.getCode());
log.info(" :"+JSON.toJSONString(faceDTO));
MvcResult result = mockMvc.perform(
post("/face/addFace").contentType(MediaType.APPLICATION_JSON_UTF8_VALUE).content(JSON.toJSONString(faceDTO)))
.andReturn();
System.out.println(result.getResponse().getContentAsString());
}
/** */
@Test
public void testUpateFace() throws Exception {
FaceDTO faceDTO = new FaceDTO();
faceDTO.setGroupId("litsoft07");
faceDTO.setUserId("xf");
String image = ImageToBase64Utils.GetImageStrFromPath("C:\\Users\\Administrator\\Desktop\\test.jpg");
log.info(image);
faceDTO.setImage(image);
faceDTO.setImageType(BaiduImageTypeMenu.BASE64.getCode());
log.info(" :"+JSON.toJSONString(faceDTO));
MvcResult result = mockMvc.perform(
put("/face/updateFace").contentType(MediaType.APPLICATION_JSON_UTF8_VALUE).content(JSON.toJSONString(faceDTO)))
.andReturn();
System.out.println(result.getResponse().getContentAsString());
}
/** */
@Test
public void testDeleteFace() throws Exception {
FaceDTO faceDTO = new FaceDTO();
faceDTO.setGroupId("litsoft07");
faceDTO.setUserId("xf");
faceDTO.setFaceToken("11c7a123a10bcbf3bcc46e5ef0a01767");
log.info(" :"+JSON.toJSONString(faceDTO));
MvcResult result = mockMvc.perform(
delete("/face/deleteFace").contentType(MediaType.APPLICATION_JSON_UTF8_VALUE).content(JSON.toJSONString(faceDTO)))
.andReturn();
System.out.println(result.getResponse().getContentAsString());
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin Springboot -- 파트 14 사용 사례 REST로 전환하여 POST로 JSON으로 전환前回 前回 前回 記事 の は は で で で で で で を 使っ 使っ 使っ て て て て て リクエスト を を 受け取り 、 reqeustbody で 、 その リクエスト の ボディ ボディ を を 受け取り 、 関数 内部 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.