From 1f736dc9c90a2cba1506e333fbcd6bd0e7dfa8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B5=B7?= Date: Fri, 29 Nov 2019 23:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=B5=84=E6=BA=90=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/controller/UserControllerTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/test/java/cn/celess/blog/controller/UserControllerTest.java b/src/test/java/cn/celess/blog/controller/UserControllerTest.java index d404191..39c0d46 100644 --- a/src/test/java/cn/celess/blog/controller/UserControllerTest.java +++ b/src/test/java/cn/celess/blog/controller/UserControllerTest.java @@ -14,10 +14,9 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; - -import java.io.File; -import java.io.FileInputStream; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.*; import static org.junit.Assert.*; @@ -93,8 +92,12 @@ public class UserControllerTest extends BaseTest { @Test public void upload() throws Exception { - File logoFile = new File("C:\\Users\\zh564\\Pictures\\logo.png"); - MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, new FileInputStream(logoFile)); + URL url = new URL("https://56462271.oss-cn-beijing.aliyuncs.com/web/logo.png"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + InputStream inputStream = connection.getInputStream(); + assertNotNull(inputStream); + MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream); mockMvc.perform(multipart("/user/imgUpload").file(file)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))); mockMvc.perform(multipart("/user/imgUpload").file(file).header("Authorization", userLogin())).andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());