package com.izouma.awesomeAdmin; import com.izouma.awesomeAdmin.domain.BaseEntity; import com.izouma.awesomeAdmin.domain.User; import com.izouma.awesomeAdmin.web.BaseController; import lombok.SneakyThrows; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.text.CaseUtils; import org.apache.poi.util.TempFile; import org.junit.Test; import org.libjpegturbo.turbojpeg.processor.api.ImageProcessInfo; import org.libjpegturbo.turbojpeg.processor.api.ImageProcessor; import org.libjpegturbo.turbojpeg.processor.impl.ImageProcessorImpl; import org.libjpegturbo.turbojpeg.processor.utils.ImageProcessorUtils; import org.pngquant.Image; import org.pngquant.PngQuant; import org.pngquant.Result; import org.reflections.ReflectionUtils; import org.reflections.Reflections; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.imageio.ImageIO; import java.awt.*; import java.awt.font.FontRenderContext; import java.awt.geom.AffineTransform; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; public class CommonTest { @Test public void getGenericsClass() { List data = new ArrayList<>(); data.add(new User()); System.out.println(data.get(0).getClass().getSimpleName()); System.out.println(data.getClass()); Reflections reflections = new Reflections(this.getClass().getPackage().getName() + ".domain"); Set> allClasses = reflections.getSubTypesOf(BaseEntity.class); for (Class allClass : allClasses) { System.out.println(allClass.getName()); } } @Test public void getapis() { List> entities = new ArrayList<>(); Reflections classReflections = new Reflections(this.getClass().getPackage().getName()); Set> controllers = classReflections.getSubTypesOf(BaseController.class); Set> list = ReflectionUtils .getAll(controllers, ReflectionUtils.withAnnotation(RestController.class)); System.out.println(list); for (Class aClass : list) { RequestMapping requestMapping = aClass.getAnnotation(RequestMapping.class); String baseUrl = requestMapping.value()[0]; for (Method method : ReflectionUtils.getMethods(aClass, ReflectionUtils.withAnnotation(GetMapping.class))) { GetMapping getMapping = method.getAnnotation(GetMapping.class); System.out.println(getMapping.value()[0]); } for (Method method : ReflectionUtils .getMethods(aClass, ReflectionUtils.withAnnotation(PostMapping.class))) { PostMapping postMapping = method.getAnnotation(PostMapping.class); System.out.println(postMapping.value()[0]); } } } @Test public void testCaseUtils() { System.out.println(CaseUtils.toCamelCase("test_Model", true, '_')); } @Test public void testMeasureText() throws IOException, FontFormatException { AffineTransform affinetransform = new AffineTransform(); FontRenderContext frc = new FontRenderContext(affinetransform, true, true); Font font = Font.createFont(Font.TRUETYPE_FONT, this.getClass() .getResourceAsStream("/font/SourceHanSansCN-Normal.ttf")); System.out.println((int) (font.deriveFont(14f).getStringBounds("aaa", frc).getWidth())); } @Test public void testIdNoRegexp() { boolean b = Pattern .matches("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0-2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0-2]\\d)|3[0-1])\\d{3}[0-9xX]$", "32100219950830461X"); System.out.println(b); } @Test public void tesSms() throws IOException { Reflections reflections = new Reflections(this.getClass().getPackage().getName() + ".enums"); Set> entitySet = reflections.getSubTypesOf(Enum.class); StringBuilder idxJs = new StringBuilder(); for (Class entity : entitySet) { idxJs.append("import ").append(entity.getSimpleName()).append(" from \"./").append(entity.getSimpleName()) .append("\";\n"); StringBuilder str = new StringBuilder("export default {\n"); for (Enum enumConstant : entity.getEnumConstants()) { str.append(" ").append(enumConstant.name()).append(": \"").append(enumConstant.name()) .append("\",\n"); } str.append("}"); Files.write(Paths.get(System.getProperty("user.dir"), "src", "main", "vue", "src", "constants", entity .getSimpleName() + ".js"), str.toString() .getBytes(StandardCharsets.UTF_8), CREATE, TRUNCATE_EXISTING); Files.write(Paths.get(System.getProperty("user.dir"), "src", "main", "zmj_mp", "src", "constants", entity .getSimpleName() + ".js"), str.toString() .getBytes(StandardCharsets.UTF_8), CREATE, TRUNCATE_EXISTING); } idxJs.append("export default {\n"); for (Class entity : entitySet) { idxJs.append(" ").append(entity.getSimpleName()).append(": ").append(entity.getSimpleName()) .append(",\n"); } idxJs.append("}"); System.out.println(idxJs.toString()); Files.write(Paths .get(System.getProperty("user.dir"), "src", "main", "vue", "src", "constants", "index.js"), idxJs .toString().getBytes(StandardCharsets.UTF_8), CREATE, TRUNCATE_EXISTING); Files.write(Paths .get(System.getProperty("user.dir"), "src", "main", "zmj_mp", "src", "constants", "index.js"), idxJs .toString().getBytes(StandardCharsets.UTF_8), CREATE, TRUNCATE_EXISTING); } @Test public void gen() { System.out.println(RandomStringUtils.randomAlphabetic(32)); } @Test public void password() { String password = new BCryptPasswordEncoder().encode("123456"); System.out.println(password); } @SneakyThrows @Test public void pngquant() { PngQuant pngQuant = new PngQuant(); ImageIO.write(pngQuant .getRemapped(ImageIO.read(new File("/Users/drew/Downloads/国内申请-案件新增(客户经理).png"))), "png", new File("/Users/drew/Downloads/111.png")); } @SneakyThrows @Test public void mozjpeg() { File out = TempFile.createTempFile("kljasdlkhfasldg", ".jpg"); ImageProcessor processor = new ImageProcessorImpl(); ImageProcessInfo processInfo = ImageProcessInfo.fromMap(ImageProcessorUtils.compressImage(processor, new File("/Users/drew/Downloads/2020-09-08-17-07-21zwBhaHeQ.jpg"), out, 75)); FileCopyUtils.copy(out, new File("/Users/drew/Desktop/111.jpg")); System.out.println(out); } @Test public void ssdfsd() { System.out.println(306 & 0xFF); } }