Browse Source

注解测试案例

ai_300
zhouhaibin 2 months ago
parent
commit
9632c38e94
  1. 59
      ruoyi-admin/src/test/java/org/dromara/test/AssertUnitTest.java
  2. 100
      ruoyi-admin/src/test/java/org/dromara/test/DemoUnitTest.java
  3. 90
      ruoyi-admin/src/test/java/org/dromara/test/ParamUnitTest.java
  4. 142
      ruoyi-admin/src/test/java/org/dromara/test/TagUnitTest.java
  5. 5
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/controller/Qwen72bController.java

59
ruoyi-admin/src/test/java/org/dromara/test/AssertUnitTest.java

@ -1,5 +1,7 @@
package org.dromara.test;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.asymmetric.SM2;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@ -12,34 +14,33 @@ import org.junit.jupiter.api.Test;
@DisplayName("断言单元测试案例")
public class AssertUnitTest {
@DisplayName("测试 assertEquals 方法")
@Test
public void testAssertEquals() {
Assertions.assertEquals("666", new String("666"));
Assertions.assertNotEquals("666", new String("666"));
}
@DisplayName("测试 assertSame 方法")
@Test
public void testAssertSame() {
Object obj = new Object();
Object obj1 = obj;
Assertions.assertSame(obj, obj1);
Assertions.assertNotSame(obj, obj1);
}
@DisplayName("测试 assertTrue 方法")
@Test
public void testAssertTrue() {
Assertions.assertTrue(true);
Assertions.assertFalse(true);
}
@DisplayName("测试 assertNull 方法")
@Test
public void testAssertNull() {
Assertions.assertNull(null);
Assertions.assertNotNull(null);
}
// @DisplayName("测试 assertEquals 方法")
// @Test
// public void testAssertEquals() {
// Assertions.assertEquals("666", new String("666"));
// Assertions.assertNotEquals("666", new String("666"));
// }
//
// @DisplayName("测试 assertSame 方法")
// @Test
// public void testAssertSame() {
// SM2 sm2 = SmUtil.sm2();
// System.out.println("私密钥:"+sm2.getPrivateKeyBase64());
// System.out.println("公钥:"+sm2.getPublicKeyBase64());
// }
//
// @DisplayName("测试 assertTrue 方法")
// @Test
// public void testAssertTrue() {
// Assertions.assertTrue(true);
// Assertions.assertFalse(true);
// }
//
// @DisplayName("测试 assertNull 方法")
// @Test
// public void testAssertNull() {
// Assertions.assertNull(null);
// Assertions.assertNotNull(null);
// }
}

100
ruoyi-admin/src/test/java/org/dromara/test/DemoUnitTest.java

@ -16,55 +16,55 @@ import java.util.concurrent.TimeUnit;
@DisplayName("单元测试案例")
public class DemoUnitTest {
@Autowired
private RuoYiConfig ruoYiConfig;
@DisplayName("测试 @SpringBootTest @Test @DisplayName 注解")
@Test
public void testTest() {
System.out.println(ruoYiConfig);
}
@Disabled
@DisplayName("测试 @Disabled 注解")
@Test
public void testDisabled() {
System.out.println(ruoYiConfig);
}
@Timeout(value = 2L, unit = TimeUnit.SECONDS)
@DisplayName("测试 @Timeout 注解")
@Test
public void testTimeout() throws InterruptedException {
Thread.sleep(3000);
System.out.println(ruoYiConfig);
}
@DisplayName("测试 @RepeatedTest 注解")
@RepeatedTest(3)
public void testRepeatedTest() {
System.out.println(666);
}
@BeforeAll
public static void testBeforeAll() {
System.out.println("@BeforeAll ==================");
}
@BeforeEach
public void testBeforeEach() {
System.out.println("@BeforeEach ==================");
}
@AfterEach
public void testAfterEach() {
System.out.println("@AfterEach ==================");
}
@AfterAll
public static void testAfterAll() {
System.out.println("@AfterAll ==================");
}
// @Autowired
// private RuoYiConfig ruoYiConfig;
//
// @DisplayName("测试 @SpringBootTest @Test @DisplayName 注解")
// @Test
// public void testTest() {
// System.out.println(ruoYiConfig);
// }
//
// @Disabled
// @DisplayName("测试 @Disabled 注解")
// @Test
// public void testDisabled() {
// System.out.println(ruoYiConfig);
// }
//
// @Timeout(value = 2L, unit = TimeUnit.SECONDS)
// @DisplayName("测试 @Timeout 注解")
// @Test
// public void testTimeout() throws InterruptedException {
// Thread.sleep(3000);
// System.out.println(ruoYiConfig);
// }
//
//
// @DisplayName("测试 @RepeatedTest 注解")
// @RepeatedTest(3)
// public void testRepeatedTest() {
// System.out.println(666);
// }
//
// @BeforeAll
// public static void testBeforeAll() {
// System.out.println("@BeforeAll ==================");
// }
//
// @BeforeEach
// public void testBeforeEach() {
// System.out.println("@BeforeEach ==================");
// }
//
// @AfterEach
// public void testAfterEach() {
// System.out.println("@AfterEach ==================");
// }
//
// @AfterAll
// public static void testAfterAll() {
// System.out.println("@AfterAll ==================");
// }
}

90
ruoyi-admin/src/test/java/org/dromara/test/ParamUnitTest.java

@ -22,51 +22,51 @@ import java.util.stream.Stream;
@DisplayName("带参数单元测试案例")
public class ParamUnitTest {
@DisplayName("测试 @ValueSource 注解")
@ParameterizedTest
@ValueSource(strings = {"t1", "t2", "t3"})
public void testValueSource(String str) {
System.out.println(str);
}
@DisplayName("测试 @NullSource 注解")
@ParameterizedTest
@NullSource
public void testNullSource(String str) {
System.out.println(str);
}
@DisplayName("测试 @EnumSource 注解")
@ParameterizedTest
@EnumSource(UserType.class)
public void testEnumSource(UserType type) {
System.out.println(type.getUserType());
}
@DisplayName("测试 @MethodSource 注解")
@ParameterizedTest
@MethodSource("getParam")
public void testMethodSource(String str) {
System.out.println(str);
}
public static Stream<String> getParam() {
List<String> list = new ArrayList<>();
list.add("t1");
list.add("t2");
list.add("t3");
return list.stream();
}
@BeforeEach
public void testBeforeEach() {
System.out.println("@BeforeEach ==================");
}
@AfterEach
public void testAfterEach() {
System.out.println("@AfterEach ==================");
}
// @DisplayName("测试 @ValueSource 注解")
// @ParameterizedTest
// @ValueSource(strings = {"t1", "t2", "t3"})
// public void testValueSource(String str) {
// System.out.println(str);
// }
//
// @DisplayName("测试 @NullSource 注解")
// @ParameterizedTest
// @NullSource
// public void testNullSource(String str) {
// System.out.println(str);
// }
//
// @DisplayName("测试 @EnumSource 注解")
// @ParameterizedTest
// @EnumSource(UserType.class)
// public void testEnumSource(UserType type) {
// System.out.println(type.getUserType());
// }
//
// @DisplayName("测试 @MethodSource 注解")
// @ParameterizedTest
// @MethodSource("getParam")
// public void testMethodSource(String str) {
// System.out.println(str);
// }
//
// public static Stream<String> getParam() {
// List<String> list = new ArrayList<>();
// list.add("t1");
// list.add("t2");
// list.add("t3");
// return list.stream();
// }
//
// @BeforeEach
// public void testBeforeEach() {
// System.out.println("@BeforeEach ==================");
// }
//
// @AfterEach
// public void testAfterEach() {
// System.out.println("@AfterEach ==================");
// }
}

142
ruoyi-admin/src/test/java/org/dromara/test/TagUnitTest.java

@ -34,80 +34,80 @@ import java.io.FileInputStream;
@DisplayName("标签单元测试案例")
public class TagUnitTest {
@Tag("dev")
@DisplayName("测试 @Tag dev")
@Test
public void testTagDev() throws Exception {
String inputFilePath="C:\\Users\\gy051\\Desktop\\1223.doc";
String outputFilePath="D:\\JPG\\test.html";
InputStream is = new FileInputStream(inputFilePath);
// InputStream is = FileHelper.convertWordToUTF8Stream(inputFilePath);
System.out.println("outputFilePath:"+outputFilePath);
HWPFDocument wordDocument = new HWPFDocument(is);
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
String rootPath = "D:\\JPG\\";
final int[] fileIndex = {0};
wordToHtmlConverter.setPicturesManager(new PicturesManager() {
@Override
public String savePicture(byte[] bytes, PictureType pictureType, String s, float v, float v1) {
fileIndex[0]++;
File file = new File(rootPath + fileIndex[0]+".png");
try {
FileOutputStream out = new FileOutputStream(file);
out.write(bytes);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return fileIndex[0]+".png"; // 返回图片的相对路径或者URL
}
});
wordToHtmlConverter.processDocument(wordDocument);
Document htmlDocument = wordToHtmlConverter.getDocument();
// 将Document转换为XHTML
StringWriter writer = new StringWriter();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.transform(new DOMSource(htmlDocument), new StreamResult(writer));
// 自定义处理标题
// W3CDocument w3cDocument = converter.getDocument();
// Range range = hwpfDocument.getRange();
// @Tag("dev")
// @DisplayName("测试 @Tag dev")
// @Test
// public void testTagDev() throws Exception {
// String inputFilePath="C:\\Users\\gy051\\Desktop\\1223.doc";
// String outputFilePath="D:\\JPG\\test.html";
// InputStream is = new FileInputStream(inputFilePath);
//// InputStream is = FileHelper.convertWordToUTF8Stream(inputFilePath);
// System.out.println("outputFilePath:"+outputFilePath);
// HWPFDocument wordDocument = new HWPFDocument(is);
// WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
// String rootPath = "D:\\JPG\\";
// final int[] fileIndex = {0};
// wordToHtmlConverter.setPicturesManager(new PicturesManager() {
//
// for (int i = 0; i < range.numParagraphs(); i++) {
// ParagraphProperties pp = range.getParagraph(i).getParagraphProperties();
// if (pp != null && pp.getParaStyleIndex() >= 0) {
// String styleName = hwpfDocument.getStyleSheet().getParagraphStyle(pp.getParaStyleIndex()).getName();
// // 判断标题样式并转换为对应的 HTML 标签
// if (styleName.startsWith("Heading")) {
// int headingLevel = Character.getNumericValue(styleName.charAt(7));
// // 这里只处理 H1 到 H6
// if (headingLevel >= 1 && headingLevel <= 6) {
// // 你可以将段落内容直接插入到 HTML 中,适当修改格式
// String headingTag = "h" + headingLevel;
// writer.append("<").append(headingTag).append(">")
// .append(range.getParagraph(i).text().trim())
// .append("</").append(headingTag).append(">");
// }
// } else {
// writer.append("<p>").append(range.getParagraph(i).text().trim()).append("</p>");
// @Override
// public String savePicture(byte[] bytes, PictureType pictureType, String s, float v, float v1) {
// fileIndex[0]++;
// File file = new File(rootPath + fileIndex[0]+".png");
// try {
// FileOutputStream out = new FileOutputStream(file);
// out.write(bytes);
// out.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
// return fileIndex[0]+".png"; // 返回图片的相对路径或者URL
// }
// }
// 输出 HTML 字符串
String htmlString = writer.getBuffer().toString();
// 将 HTML 字符串写入文件
FileOutputStream out = new FileOutputStream(outputFilePath);
byte[] bytes = htmlString.getBytes("UTF-8");
out.write(bytes);
out.close();
}
//
//
// });
// wordToHtmlConverter.processDocument(wordDocument);
// Document htmlDocument = wordToHtmlConverter.getDocument();
//
// // 将Document转换为XHTML
// StringWriter writer = new StringWriter();
// TransformerFactory transformerFactory = TransformerFactory.newInstance();
// Transformer transformer = transformerFactory.newTransformer();
// transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.setOutputProperty(OutputKeys.METHOD, "html");
// transformer.transform(new DOMSource(htmlDocument), new StreamResult(writer));
//// 自定义处理标题
//// W3CDocument w3cDocument = converter.getDocument();
//// Range range = hwpfDocument.getRange();
////
//// for (int i = 0; i < range.numParagraphs(); i++) {
//// ParagraphProperties pp = range.getParagraph(i).getParagraphProperties();
//// if (pp != null && pp.getParaStyleIndex() >= 0) {
//// String styleName = hwpfDocument.getStyleSheet().getParagraphStyle(pp.getParaStyleIndex()).getName();
//// // 判断标题样式并转换为对应的 HTML 标签
//// if (styleName.startsWith("Heading")) {
//// int headingLevel = Character.getNumericValue(styleName.charAt(7));
//// // 这里只处理 H1 到 H6
//// if (headingLevel >= 1 && headingLevel <= 6) {
//// // 你可以将段落内容直接插入到 HTML 中,适当修改格式
//// String headingTag = "h" + headingLevel;
//// writer.append("<").append(headingTag).append(">")
//// .append(range.getParagraph(i).text().trim())
//// .append("</").append(headingTag).append(">");
//// }
//// } else {
//// writer.append("<p>").append(range.getParagraph(i).text().trim()).append("</p>");
//// }
//// }
//// }
// // 输出 HTML 字符串
// String htmlString = writer.getBuffer().toString();
// // 将 HTML 字符串写入文件
// FileOutputStream out = new FileOutputStream(outputFilePath);
// byte[] bytes = htmlString.getBytes("UTF-8");
// out.write(bytes);
// out.close();
//
// }
//
// @Tag("prod")

5
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/controller/Qwen72bController.java

@ -35,7 +35,7 @@ import org.springframework.web.multipart.MultipartFile;
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/productManagement/docAi")
@RequestMapping("/productManagement/docAi1")
public class Qwen72bController extends BaseController {
@Value("${chat.filePath}")
private String chatFilePath;
@ -156,7 +156,8 @@ public class Qwen72bController extends BaseController {
FileUtil.writeFromStream(file.getInputStream(), destFile);
//不是docx文件需要转换
if (!originalFilename.endsWith(".docx")) {
ProcessBuilder builder = new ProcessBuilder("unoconv","-o" ,destDir,"-f", "docx", destFile.getAbsolutePath());
// ProcessBuilder builder = new ProcessBuilder("unoconv","-o" ,destDir,"-f", "docx", );
ProcessBuilder builder = new ProcessBuilder("libreoffice", "--headless", "--convert-to", "docx",destFile.getAbsolutePath(), "--outdir", destDir);
Process process = builder.start();

Loading…
Cancel
Save