parent
d62d3df997
commit
251da427b7
9 changed files with 299 additions and 109 deletions
@ -0,0 +1,70 @@ |
||||
package com.yipin.liuwanr; |
||||
|
||||
import com.yipin.liuwanr.service.AliyunOssService; |
||||
import org.apache.commons.fileupload.FileItem; |
||||
import org.apache.commons.fileupload.disk.DiskFileItem; |
||||
import org.apache.commons.io.IOUtils; |
||||
import org.junit.Before; |
||||
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.mock.web.MockHttpServletResponse; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
import org.springframework.test.web.servlet.MockMvc; |
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; |
||||
import org.springframework.web.context.WebApplicationContext; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.util.HashMap; |
||||
|
||||
@RunWith(SpringRunner.class) |
||||
@SpringBootTest |
||||
public class AliyunOssServiceTest { |
||||
|
||||
@Autowired |
||||
private AliyunOssService aliyunOssService; |
||||
|
||||
/** |
||||
* 测试上传文件 |
||||
*/ |
||||
@Test |
||||
public void testUploadFiles() throws IOException { |
||||
File file = new File("D:\\pic\\1.jpg"); |
||||
FileItem fileItem = new DiskFileItem("file", |
||||
Files.probeContentType(file.toPath()), |
||||
false, |
||||
file.getName(), |
||||
(int) file.length(), |
||||
file.getParentFile()); |
||||
IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream()); |
||||
MultipartFile multipartFile = new CommonsMultipartFile(fileItem); |
||||
HashMap<String, Object> map = aliyunOssService.uploadFiles(multipartFile); |
||||
map.forEach((key, value) -> System.out.println("key = " + key + " ===> value = " + value.toString())); |
||||
} |
||||
|
||||
/** |
||||
* 测试下载文件 |
||||
*/ |
||||
@Test |
||||
public void testDownloadFiles() throws IOException { |
||||
HttpServletResponse response = new MockHttpServletResponse(); |
||||
AliyunOssService aliyunOssService = this.aliyunOssService; |
||||
aliyunOssService.downloadFiles(response, |
||||
"http://liuwanr.oss-cn-shenzhen.aliyuncs.com/jpg/20200807/1596787474773.jpg"); |
||||
} |
||||
/** |
||||
* 测试根据文件路径+文件名称,删除该文件 |
||||
*/ |
||||
@Test |
||||
public void testDeleteFile() throws IOException { |
||||
aliyunOssService.deleteFile("http://liuwanr.oss-cn-shenzhen.aliyuncs.com/jpg/20200807/1596787474773.jpg"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,40 @@ |
||||
package com.yipin.liuwanr; |
||||
|
||||
import com.yipin.liuwanr.entity.City; |
||||
import com.yipin.liuwanr.entity.SutdentClass; |
||||
import com.yipin.liuwanr.mapper.CityMapper; |
||||
import com.yipin.liuwanr.service.CityService; |
||||
import com.yipin.liuwanr.service.ClassService; |
||||
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 org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
@RunWith(SpringRunner.class) |
||||
@SpringBootTest |
||||
public class ClassServiceTest { |
||||
|
||||
@Autowired |
||||
private ClassService classService; |
||||
|
||||
@Test |
||||
public void testQueryGetByClassName() { |
||||
HashMap<String, Object> map = classService.queryGetByClassName(""); |
||||
Integer retcode = (Integer) map.get("retcode"); |
||||
System.out.println(retcode); |
||||
if (retcode == 200) { |
||||
List<SutdentClass> classes = (List<SutdentClass>) map.get("retvalue"); |
||||
classes.forEach(item -> { |
||||
System.out.println(item.toString()); |
||||
}); |
||||
} else { |
||||
String msg = (String) map.get("retvalue"); |
||||
System.out.println(msg); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue