feat: 删除测试文件
This commit is contained in:
parent
3bd1f2140a
commit
06c4c66d4c
|
@ -1,50 +0,0 @@
|
||||||
package cn.bunny.service;
|
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class FilesTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test1() throws IOException {
|
|
||||||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/backup.sh")) {
|
|
||||||
if (inputStream == null) return;
|
|
||||||
|
|
||||||
byte[] bytes = inputStream.readAllBytes();
|
|
||||||
Files.write(Path.of("H:\\资料\\backup.sh"), bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
@Test
|
|
||||||
void test2() {
|
|
||||||
// 读取资源目录下脚本文件并写入到主机中
|
|
||||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/backup.sh");
|
|
||||||
if (inputStream == null) return;
|
|
||||||
byte[] bytes = inputStream.readAllBytes();
|
|
||||||
Files.write(Path.of("H:/资料" + "/backup.sh"), bytes);
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test3() throws IOException {
|
|
||||||
String string = Files.readString(Path.of("E:\\data.js"));
|
|
||||||
System.out.println(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test4() throws IOException {
|
|
||||||
File file = FileUtils.listFiles(new File("E:\\资料\\其她\\分析日记\\2024\\10月"), null, true).stream()
|
|
||||||
.max(Comparator.comparing(File::lastModified))
|
|
||||||
.orElse(new File(""));
|
|
||||||
System.out.println(file.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
package cn.bunny.service;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
public class ResourceTest {
|
|
||||||
|
|
||||||
// 读取resource下目录方式1
|
|
||||||
@Test
|
|
||||||
void test1() {
|
|
||||||
try (InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("static/backup.sh")) {
|
|
||||||
if (resourceAsStream == null) return;
|
|
||||||
|
|
||||||
// 文件存储一共的内容
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
// 读取文件内容
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream));
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
builder.append(line).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 输出文件内容
|
|
||||||
System.out.println(builder);
|
|
||||||
reader.close();
|
|
||||||
} catch (Exception exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取resource下目录方式2
|
|
||||||
@Test
|
|
||||||
void test2() {
|
|
||||||
try (InputStream inputStream = getClass().getResourceAsStream("/static/backup.sh")) {
|
|
||||||
if (inputStream == null) return;
|
|
||||||
|
|
||||||
// 获取所有数组内容
|
|
||||||
byte[] bytes = inputStream.readAllBytes();
|
|
||||||
|
|
||||||
// 读取文件中内容
|
|
||||||
String string = new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
System.out.println(string);
|
|
||||||
|
|
||||||
// 读取文件转成Base64
|
|
||||||
String str = Base64.getEncoder().encodeToString(bytes);
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
} catch (Exception exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取resource下目录方式3
|
|
||||||
@Test
|
|
||||||
void test3() {
|
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
try (InputStream inputStream = classLoader.getResourceAsStream("static/backup.sh")) {
|
|
||||||
if (inputStream == null) return;
|
|
||||||
|
|
||||||
// 获取所有数组内容
|
|
||||||
byte[] bytes = inputStream.readAllBytes();
|
|
||||||
|
|
||||||
// 读取文件中内容
|
|
||||||
String string = new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
System.out.println(string);
|
|
||||||
|
|
||||||
// 读取文件转成Base64
|
|
||||||
String str = Base64.getEncoder().encodeToString(bytes);
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
} catch (Exception exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
package cn.bunny.service;
|
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.data.redis.core.script.ScriptExecutor;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class TestPath {
|
|
||||||
@SneakyThrows
|
|
||||||
@Test
|
|
||||||
void testPath() {
|
|
||||||
String scriptPath = Objects.requireNonNull(getClass().getClassLoader().getResource("static/backup.sh")).getPath();
|
|
||||||
String path = Objects.requireNonNull(ScriptExecutor.class.getClassLoader().getResource("static/backup.sh")).getPath();
|
|
||||||
System.out.println(path);
|
|
||||||
// 执行脚本
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder("bash", scriptPath);
|
|
||||||
processBuilder.redirectErrorStream(true);
|
|
||||||
Process process = processBuilder.start();
|
|
||||||
|
|
||||||
// 执行后读取内容
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
System.out.println(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
@Test
|
|
||||||
void test2() {
|
|
||||||
ClassLoader classLoader = ResourceLoader.class.getClassLoader();
|
|
||||||
InputStream inputStream = classLoader.getResourceAsStream("static/backup.sh");
|
|
||||||
assert inputStream != null;
|
|
||||||
try (java.util.Scanner s = new java.util.Scanner(inputStream)) {
|
|
||||||
while (s.hasNext()) {
|
|
||||||
System.out.println(s.nextLine());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] bytes = inputStream.readAllBytes();
|
|
||||||
String string = new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
System.out.println(string);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package cn.bunny.services.backup;
|
|
||||||
|
|
||||||
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
public class MysqlBackupTest {
|
|
||||||
@SneakyThrows
|
|
||||||
@Test
|
|
||||||
void testMysqlBackup() {
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.now();
|
|
||||||
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD_HH_MM_SS_UNDERLINE);
|
|
||||||
String timeNow = localDateTime.format(timeFormatter);
|
|
||||||
|
|
||||||
System.out.println(timeNow);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package cn.bunny.services.factory;
|
|
||||||
|
|
||||||
import cn.bunny.common.service.utils.mail.MailSenderUtil;
|
|
||||||
import cn.bunny.dao.pojo.common.EmailSend;
|
|
||||||
import cn.bunny.dao.pojo.common.EmailSendInit;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
class EmailFactoryTest {
|
|
||||||
@Test
|
|
||||||
void testSendEmail() throws Exception {
|
|
||||||
File file = new File("H:\\学习\\WpfApp2\\WpfApp2");
|
|
||||||
List<MultipartFile> fileList = Arrays.stream(Objects.requireNonNull(file.listFiles())).map(file1 -> {
|
|
||||||
try {
|
|
||||||
return (MultipartFile) new MockMultipartFile("file", file.getName(), null, new FileInputStream(file1));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
// 初始化发送内容
|
|
||||||
EmailSendInit emailSendInit = new EmailSendInit();
|
|
||||||
emailSendInit.setUsername("3324855376@qq.com");
|
|
||||||
emailSendInit.setPassword("fdehkkbmavalcjea");
|
|
||||||
emailSendInit.setPort(465);
|
|
||||||
emailSendInit.setHost("smtp.qq.com");
|
|
||||||
|
|
||||||
// 发送邮件信息
|
|
||||||
EmailSend emailSend = new EmailSend();
|
|
||||||
emailSend.setSendTo(List.of("794demetris@rustyload.com", "a0w_q6ct@linshiyouxiang.net"));
|
|
||||||
emailSend.setSubject("测试邮件发送");
|
|
||||||
emailSend.setText("<h1>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试</h1>");
|
|
||||||
emailSend.setRichText(true);
|
|
||||||
emailSend.setCcParam(List.of("tiec@snapmail.cc", "yenibex934@angewy.com"));
|
|
||||||
emailSend.setFiles(fileList.toArray(new MultipartFile[0]));
|
|
||||||
|
|
||||||
// 发送邮件
|
|
||||||
MailSenderUtil.sendEmail(emailSendInit, emailSend);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testReplace() {
|
|
||||||
final String[] modifiedTemplate = {"template"};
|
|
||||||
|
|
||||||
HashMap<String, Object> hashMap = new HashMap<>();
|
|
||||||
hashMap.put("#title#", "BunnyAdmin");
|
|
||||||
hashMap.put("#erifyCode#", "emailCode");
|
|
||||||
hashMap.put("#expires#", 15);
|
|
||||||
hashMap.put("#sendEmailUser#", "emailUsers.getEmail()");
|
|
||||||
hashMap.put("#companyName#", "BunnyAdmin");
|
|
||||||
|
|
||||||
hashMap.forEach((key, value) -> modifiedTemplate[0] = modifiedTemplate[0].replaceAll(key, String.valueOf(value)));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package cn.bunny.services.quartz;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
class DatabaseBackupJobTest {
|
|
||||||
@Test
|
|
||||||
void testProcess() {
|
|
||||||
// 执行备份命令
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "--version");
|
|
||||||
|
|
||||||
try {
|
|
||||||
Process process = processBuilder.start();
|
|
||||||
|
|
||||||
// 使用输出流读取命令的输出
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
||||||
reader.lines().forEach(System.out::println);
|
|
||||||
|
|
||||||
// 等待进程结束并获取退出值
|
|
||||||
int exitCode = process.waitFor();
|
|
||||||
System.out.println("Exit code: " + exitCode);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
package cn.bunny.services.service.impl;
|
|
||||||
|
|
||||||
import cn.bunny.dao.pojo.constant.MinioConstant;
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
class FilesServiceImplTest {
|
|
||||||
@Test
|
|
||||||
void stringTest() {
|
|
||||||
String filepath = "/auth-admin/avatar/2024/10-04/5a56ad8f-4468-4780-8a61-424e7de54e04.png";
|
|
||||||
int start = filepath.indexOf("/", 1);
|
|
||||||
filepath = filepath.substring(start + 1);
|
|
||||||
System.out.println(filepath);
|
|
||||||
|
|
||||||
int end = filepath.lastIndexOf("/");
|
|
||||||
String filename = filepath.substring(end + 1);
|
|
||||||
System.out.println(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
@Test
|
|
||||||
void getAllMediaTypeTest() {
|
|
||||||
Class<?> mediaTypeClass = MediaType.class;
|
|
||||||
for (Field declaredField : mediaTypeClass.getDeclaredFields()) {
|
|
||||||
declaredField.setAccessible(true);
|
|
||||||
String value = declaredField.get(null).toString();
|
|
||||||
if (value.matches("\\w+/.*")) {
|
|
||||||
System.out.println(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllPaths() {
|
|
||||||
Map<String, String> typeMap = MinioConstant.typeMap;
|
|
||||||
List<Map.Entry<String, String>> list = typeMap.entrySet().stream().toList();
|
|
||||||
System.out.println(list);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package cn.bunny.services.service.impl;
|
|
||||||
|
|
||||||
import cn.bunny.common.service.utils.ip.IpUtil;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
public class IpTest {
|
|
||||||
@Test
|
|
||||||
void ipTest() {
|
|
||||||
String ip = "58.214.13.154";
|
|
||||||
System.out.println(IpUtil.getIpRegion(ip));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package cn.bunny.services.service.impl;
|
|
||||||
|
|
||||||
import cn.bunny.services.aop.AnnotationScanner;
|
|
||||||
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class SchedulersServiceImplTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AnnotationScanner annotationScanner;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllJobClass() {
|
|
||||||
Set<Class<?>> classesWithAnnotation = annotationScanner.getClassesWithAnnotation(QuartzSchedulers.class);
|
|
||||||
classesWithAnnotation.forEach(cls -> {
|
|
||||||
String classReference = cls.getName();
|
|
||||||
String description = cls.getAnnotation(QuartzSchedulers.class).description();
|
|
||||||
System.out.println(classReference);
|
|
||||||
System.out.println(description);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package cn.bunny.services.service.impl;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
class UserServiceImplTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void updateAdminUserByLocalUser() {
|
|
||||||
String url1 = "http://192.168.3.98:9000/auth-admin/avatar/2024/10-22/a9f1794e-610a-471d-8f4f-75c8c738ef46";
|
|
||||||
|
|
||||||
String regex = "https?://.*?/(.*)";
|
|
||||||
Pattern pattern = Pattern.compile(regex);
|
|
||||||
Matcher matcher = pattern.matcher(url1);
|
|
||||||
if (matcher.matches()) {
|
|
||||||
System.out.println(matcher.group(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deleteAdminUser() {
|
|
||||||
ArrayList<Long> list = new ArrayList<>() {{
|
|
||||||
add(100L);
|
|
||||||
add(101L);
|
|
||||||
add(102L);
|
|
||||||
add(1L);
|
|
||||||
}};
|
|
||||||
list.remove(1L);
|
|
||||||
|
|
||||||
System.out.println(list);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue