From 80b5e018c1d4b47f3b200b1f5359439a1cf5ed68 Mon Sep 17 00:00:00 2001 From: chentianming Date: Wed, 26 Oct 2022 19:17:49 +0800 Subject: [PATCH] remove download test --- .../spring/boot/test/DownloadTest.java | 57 ------------------- .../spring/boot/test/RetrofitStarterTest.java | 2 - .../spring/boot/test/http/DownloadApi.java | 20 ------- 3 files changed, 79 deletions(-) delete mode 100644 src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java delete mode 100644 src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/DownloadApi.java diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java deleted file mode 100644 index 5453dbe..0000000 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/DownloadTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.github.lianjiatech.retrofit.spring.boot.test; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.util.UUID; - -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.test.context.junit4.SpringRunner; - -import com.github.lianjiatech.retrofit.spring.boot.test.http.DownloadApi; - -import okhttp3.ResponseBody; -import retrofit2.Response; - -/** - * @author 陈添明 - */ - -@SpringBootTest(classes = RetrofitTestApplication.class) -@RunWith(SpringRunner.class) -public class DownloadTest { - - @Autowired - DownloadApi downLoadApi; - - @Test - public void download() throws Exception { - String fileKey = "6302d742-ebc8-4649-95cf-62ccf57a1add"; - Response response = downLoadApi.download(fileKey); - ResponseBody responseBody = response.body(); - // 二进制流 - InputStream is = responseBody.byteStream(); - - // 具体如何处理二进制流,由业务自行控制。这里以写入文件为例 - File tempDirectory = new File("temp"); - if (!tempDirectory.exists()) { - tempDirectory.mkdir(); - } - File file = new File(tempDirectory, UUID.randomUUID().toString()); - if (!file.exists()) { - file.createNewFile(); - } - try (FileOutputStream fos = new FileOutputStream(file)) { - byte[] b = new byte[1024]; - int length; - while ((length = is.read(b)) > 0) { - fos.write(b, 0, length); - } - is.close(); - fos.close(); - } - } -} diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java index 53c5078..7e074f4 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/RetrofitStarterTest.java @@ -25,11 +25,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.lianjiatech.retrofit.spring.boot.test.entity.Person; import com.github.lianjiatech.retrofit.spring.boot.test.entity.Result; -import com.github.lianjiatech.retrofit.spring.boot.test.http.DownloadApi; import com.github.lianjiatech.retrofit.spring.boot.test.http.HttpApi; import com.github.lianjiatech.retrofit.spring.boot.test.http.HttpApi2; import com.github.lianjiatech.retrofit.spring.boot.test.http.HttpApi3; -import com.github.lianjiatech.retrofit.spring.boot.test.http.InterceptApi; import lombok.extern.slf4j.Slf4j; import okhttp3.Request; diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/DownloadApi.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/DownloadApi.java deleted file mode 100644 index d5bd5ab..0000000 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/http/DownloadApi.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.lianjiatech.retrofit.spring.boot.test.http; - -import com.github.lianjiatech.retrofit.spring.boot.core.RetrofitClient; - -import okhttp3.ResponseBody; -import retrofit2.Response; -import retrofit2.http.GET; -import retrofit2.http.Path; - -/** - * 文件下载API - * - * @author 陈添明 - */ -@RetrofitClient(baseUrl = "https://img.ljcdn.com/hc-picture/") -public interface DownloadApi { - - @GET("{fileKey}") - Response download(@Path("fileKey") String fileKey); -}