提交 90b52f7c authored 作者: mry's avatar mry

fix(base): 修复了注入失败的bug,修改了报告生成位置,优化了JDBC

上级 3220ad61
package org.matrix.testNg;
import org.springframework.beans.factory.annotation.Value;
import java.sql.*;
import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @author mry
......@@ -13,11 +13,10 @@ public class DataProviderForDb implements Iterator<Object[]> {
ResultSet resultSet;
ResultSetMetaData resultSetMetaData;
public DataProviderForDb(String ip, String port, String baseName,
String userName, String password, String sql) {
public DataProviderForDb(String driver, String url
, String userName, String password, String sql) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = String.format("jdbc:mysql://%s:%s/%s" + "?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC", ip, port, baseName);
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, userName, password);
Statement createStatement = conn.createStatement();
......
......@@ -9,7 +9,9 @@ import org.matrix.database.entity.TestCase;
import org.matrix.database.service.ITestCaseService;
import org.matrix.exception.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.ITestResult;
import org.testng.Reporter;
......@@ -21,6 +23,7 @@ import java.util.Map;
/**
* @author mry
*/
@Component
@SpringBootTest
public class TestPigeon extends AbstractTestNGSpringContextTests {
......@@ -28,6 +31,18 @@ public class TestPigeon extends AbstractTestNGSpringContextTests {
Long envId;
Long projectId;
@Value("${spring.datasource.dynamic.datasource.master.driverClassName}")
private String driver;
@Value("${spring.datasource.dynamic.datasource.master.url}")
private String url;
@Value("${spring.datasource.dynamic.datasource.master.username}")
private String username;
@Value("${spring.datasource.dynamic.datasource.master.password}")
private String password;
@Autowired
private ITestCaseService caseService;
......@@ -50,8 +65,7 @@ public class TestPigeon extends AbstractTestNGSpringContextTests {
*/
@DataProvider(name = "testData")
private Iterator<Object[]> getData() {
return new DataProviderForDb(TestConfig.DB_IP, TestConfig.DB_PORT,
TestConfig.DB_BASE_NAME, TestConfig.DB_USERNAME, TestConfig.DB_PASSWORD, sql);
return new DataProviderForDb(driver, url, username, password, sql);
}
......@@ -61,7 +75,7 @@ public class TestPigeon extends AbstractTestNGSpringContextTests {
CaseActuator caseActuator = new CaseActuator(checkPointActuator, httpClientActuator);
TestCase testCase = java.util.Optional.of(caseService.getById(caseId))
.orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的TestCase", caseId)));
TestCaseExecuteResult testCaseExecuteResult = caseActuator.executeTestCase(testCase,envId,projectId);
TestCaseExecuteResult testCaseExecuteResult = caseActuator.executeTestCase(testCase, envId, projectId);
CheckPointResult checkPointResult = testCaseExecuteResult.getCheckPointResult();
Reporter.log(checkPointResult.toString());
}
......
......@@ -19,7 +19,7 @@ import java.util.*;
*/
public class ExtentTestNgReporterListener implements IReporter {
private static final String OUTPUT_FOLDER = System.getProperty("user.dir");
private static final String OUTPUT_FOLDER = System.getProperty("user.dir") + "/";
private static final String FILE_NAME = "testNg.html";
private ExtentReports extent;
......
......@@ -8,9 +8,11 @@ spring:
datasource:
master: #增加默认数据源
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.100.248:3306/key_stone?useUnicode=true&characterEncoding=utf-8&useSSL=false
url: jdbc:mysql://192.168.100.248:3306/key_stone?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
username: root
password: root
mybatis-plus:
type-enums-package: org.matrix.enums
\ No newline at end of file
type-enums-package: org.matrix.enums
baseJsPath: syntaxCheck.js
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论