Browse Source

注解测试案例

ai_300
zhouhaibin 5 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; 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.Assertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -12,34 +14,33 @@ import org.junit.jupiter.api.Test;
@DisplayName("断言单元测试案例") @DisplayName("断言单元测试案例")
public class AssertUnitTest { public class AssertUnitTest {
@DisplayName("测试 assertEquals 方法") // @DisplayName("测试 assertEquals 方法")
@Test // @Test
public void testAssertEquals() { // public void testAssertEquals() {
Assertions.assertEquals("666", new String("666")); // Assertions.assertEquals("666", new String("666"));
Assertions.assertNotEquals("666", new String("666")); // Assertions.assertNotEquals("666", new String("666"));
} // }
//
@DisplayName("测试 assertSame 方法") // @DisplayName("测试 assertSame 方法")
@Test // @Test
public void testAssertSame() { // public void testAssertSame() {
Object obj = new Object(); // SM2 sm2 = SmUtil.sm2();
Object obj1 = obj; // System.out.println("私密钥:"+sm2.getPrivateKeyBase64());
Assertions.assertSame(obj, obj1); // System.out.println("公钥:"+sm2.getPublicKeyBase64());
Assertions.assertNotSame(obj, obj1); // }
} //
// @DisplayName("测试 assertTrue 方法")
@DisplayName("测试 assertTrue 方法") // @Test
@Test // public void testAssertTrue() {
public void testAssertTrue() { // Assertions.assertTrue(true);
Assertions.assertTrue(true); // Assertions.assertFalse(true);
Assertions.assertFalse(true); // }
} //
// @DisplayName("测试 assertNull 方法")
@DisplayName("测试 assertNull 方法") // @Test
@Test // public void testAssertNull() {
public void testAssertNull() { // Assertions.assertNull(null);
Assertions.assertNull(null); // Assertions.assertNotNull(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("单元测试案例") @DisplayName("单元测试案例")
public class DemoUnitTest { public class DemoUnitTest {
@Autowired // @Autowired
private RuoYiConfig ruoYiConfig; // private RuoYiConfig ruoYiConfig;
//
@DisplayName("测试 @SpringBootTest @Test @DisplayName 注解") // @DisplayName("测试 @SpringBootTest @Test @DisplayName 注解")
@Test // @Test
public void testTest() { // public void testTest() {
System.out.println(ruoYiConfig); // System.out.println(ruoYiConfig);
} // }
//
@Disabled // @Disabled
@DisplayName("测试 @Disabled 注解") // @DisplayName("测试 @Disabled 注解")
@Test // @Test
public void testDisabled() { // public void testDisabled() {
System.out.println(ruoYiConfig); // System.out.println(ruoYiConfig);
} // }
//
@Timeout(value = 2L, unit = TimeUnit.SECONDS) // @Timeout(value = 2L, unit = TimeUnit.SECONDS)
@DisplayName("测试 @Timeout 注解") // @DisplayName("测试 @Timeout 注解")
@Test // @Test
public void testTimeout() throws InterruptedException { // public void testTimeout() throws InterruptedException {
Thread.sleep(3000); // Thread.sleep(3000);
System.out.println(ruoYiConfig); // System.out.println(ruoYiConfig);
} // }
//
//
@DisplayName("测试 @RepeatedTest 注解") // @DisplayName("测试 @RepeatedTest 注解")
@RepeatedTest(3) // @RepeatedTest(3)
public void testRepeatedTest() { // public void testRepeatedTest() {
System.out.println(666); // System.out.println(666);
} // }
//
@BeforeAll // @BeforeAll
public static void testBeforeAll() { // public static void testBeforeAll() {
System.out.println("@BeforeAll =================="); // System.out.println("@BeforeAll ==================");
} // }
//
@BeforeEach // @BeforeEach
public void testBeforeEach() { // public void testBeforeEach() {
System.out.println("@BeforeEach =================="); // System.out.println("@BeforeEach ==================");
} // }
//
@AfterEach // @AfterEach
public void testAfterEach() { // public void testAfterEach() {
System.out.println("@AfterEach =================="); // System.out.println("@AfterEach ==================");
} // }
//
@AfterAll // @AfterAll
public static void testAfterAll() { // public static void testAfterAll() {
System.out.println("@AfterAll =================="); // 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("带参数单元测试案例") @DisplayName("带参数单元测试案例")
public class ParamUnitTest { public class ParamUnitTest {
@DisplayName("测试 @ValueSource 注解") // @DisplayName("测试 @ValueSource 注解")
@ParameterizedTest // @ParameterizedTest
@ValueSource(strings = {"t1", "t2", "t3"}) // @ValueSource(strings = {"t1", "t2", "t3"})
public void testValueSource(String str) { // public void testValueSource(String str) {
System.out.println(str); // System.out.println(str);
} // }
//
@DisplayName("测试 @NullSource 注解") // @DisplayName("测试 @NullSource 注解")
@ParameterizedTest // @ParameterizedTest
@NullSource // @NullSource
public void testNullSource(String str) { // public void testNullSource(String str) {
System.out.println(str); // System.out.println(str);
} // }
//
@DisplayName("测试 @EnumSource 注解") // @DisplayName("测试 @EnumSource 注解")
@ParameterizedTest // @ParameterizedTest
@EnumSource(UserType.class) // @EnumSource(UserType.class)
public void testEnumSource(UserType type) { // public void testEnumSource(UserType type) {
System.out.println(type.getUserType()); // System.out.println(type.getUserType());
} // }
//
@DisplayName("测试 @MethodSource 注解") // @DisplayName("测试 @MethodSource 注解")
@ParameterizedTest // @ParameterizedTest
@MethodSource("getParam") // @MethodSource("getParam")
public void testMethodSource(String str) { // public void testMethodSource(String str) {
System.out.println(str); // System.out.println(str);
} // }
//
public static Stream<String> getParam() { // public static Stream<String> getParam() {
List<String> list = new ArrayList<>(); // List<String> list = new ArrayList<>();
list.add("t1"); // list.add("t1");
list.add("t2"); // list.add("t2");
list.add("t3"); // list.add("t3");
return list.stream(); // return list.stream();
} // }
//
@BeforeEach // @BeforeEach
public void testBeforeEach() { // public void testBeforeEach() {
System.out.println("@BeforeEach =================="); // System.out.println("@BeforeEach ==================");
} // }
//
@AfterEach // @AfterEach
public void testAfterEach() { // public void testAfterEach() {
System.out.println("@AfterEach =================="); // System.out.println("@AfterEach ==================");
} // }
} }

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

@ -34,80 +34,80 @@ import java.io.FileInputStream;
@DisplayName("标签单元测试案例") @DisplayName("标签单元测试案例")
public class TagUnitTest { public class TagUnitTest {
@Tag("dev") // @Tag("dev")
@DisplayName("测试 @Tag dev") // @DisplayName("测试 @Tag dev")
@Test // @Test
public void testTagDev() throws Exception { // public void testTagDev() throws Exception {
String inputFilePath="C:\\Users\\gy051\\Desktop\\1223.doc"; // String inputFilePath="C:\\Users\\gy051\\Desktop\\1223.doc";
String outputFilePath="D:\\JPG\\test.html"; // String outputFilePath="D:\\JPG\\test.html";
InputStream is = new FileInputStream(inputFilePath); // InputStream is = new FileInputStream(inputFilePath);
// InputStream is = FileHelper.convertWordToUTF8Stream(inputFilePath); //// InputStream is = FileHelper.convertWordToUTF8Stream(inputFilePath);
System.out.println("outputFilePath:"+outputFilePath); // System.out.println("outputFilePath:"+outputFilePath);
HWPFDocument wordDocument = new HWPFDocument(is); // HWPFDocument wordDocument = new HWPFDocument(is);
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); // WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
String rootPath = "D:\\JPG\\"; // String rootPath = "D:\\JPG\\";
final int[] fileIndex = {0}; // final int[] fileIndex = {0};
wordToHtmlConverter.setPicturesManager(new PicturesManager() { // 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();
// //
// for (int i = 0; i < range.numParagraphs(); i++) { // @Override
// ParagraphProperties pp = range.getParagraph(i).getParagraphProperties(); // public String savePicture(byte[] bytes, PictureType pictureType, String s, float v, float v1) {
// if (pp != null && pp.getParaStyleIndex() >= 0) { // fileIndex[0]++;
// String styleName = hwpfDocument.getStyleSheet().getParagraphStyle(pp.getParaStyleIndex()).getName(); // File file = new File(rootPath + fileIndex[0]+".png");
// // 判断标题样式并转换为对应的 HTML 标签 // try {
// if (styleName.startsWith("Heading")) { // FileOutputStream out = new FileOutputStream(file);
// int headingLevel = Character.getNumericValue(styleName.charAt(7)); // out.write(bytes);
// // 这里只处理 H1 到 H6 // out.close();
// if (headingLevel >= 1 && headingLevel <= 6) { // } catch (Exception e) {
// // 你可以将段落内容直接插入到 HTML 中,适当修改格式 // e.printStackTrace();
// 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>");
// } // }
// return fileIndex[0]+".png"; // 返回图片的相对路径或者URL
// } // }
// } //
// 输出 HTML 字符串 //
String htmlString = writer.getBuffer().toString(); // });
// 将 HTML 字符串写入文件 // wordToHtmlConverter.processDocument(wordDocument);
FileOutputStream out = new FileOutputStream(outputFilePath); // Document htmlDocument = wordToHtmlConverter.getDocument();
byte[] bytes = htmlString.getBytes("UTF-8"); //
out.write(bytes); // // 将Document转换为XHTML
out.close(); // 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") // @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 @Validated
@RequiredArgsConstructor @RequiredArgsConstructor
@RestController @RestController
@RequestMapping("/productManagement/docAi") @RequestMapping("/productManagement/docAi1")
public class Qwen72bController extends BaseController { public class Qwen72bController extends BaseController {
@Value("${chat.filePath}") @Value("${chat.filePath}")
private String chatFilePath; private String chatFilePath;
@ -156,7 +156,8 @@ public class Qwen72bController extends BaseController {
FileUtil.writeFromStream(file.getInputStream(), destFile); FileUtil.writeFromStream(file.getInputStream(), destFile);
//不是docx文件需要转换 //不是docx文件需要转换
if (!originalFilename.endsWith(".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(); Process process = builder.start();

Loading…
Cancel
Save