You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudnote_server/src/test/java/com/bupt/note/NoteApplicationTests.java

48 lines
1.6 KiB

package com.bupt.note;
import com.bupt.note.service.FileService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.io.IOException;
@SpringBootTest
class NoteApplicationTests {
@Autowired
private WebApplicationContext context;
protected MockMvc mvc;
@Autowired
private FileService fileService;
@BeforeEach
public void setUp() {
mvc = MockMvcBuilders.webAppContextSetup(context).build();
}
//注册接口
@Test
public void testSignup() throws Exception {
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post("/v1/api/sign_up")
.content("{\"userName\":\"test\",\"password\":\"123\"}")
.contentType(MediaType.APPLICATION_JSON);
mvc.perform(builder).andDo(MockMvcResultHandlers.print());
}
@Test
public void testRead() throws IOException {
String a= fileService.getContent("E:\\JetBrains\\IdeaProjects\\back-end code\\target\\classes\\resources\\static\\txt\\1aee7062-58a7-46e0-ba4d-84a9a14f4205.txt");
}
}