修改baseTest类,使其更加通用
parent
8d8375bded
commit
15dd223a9b
|
@ -24,11 +24,12 @@ log
|
|||
|
||||
/target/
|
||||
/log/
|
||||
/src/test/java/baseTest/BaseTest.java
|
||||
.DS_Store
|
||||
/src/main/resources/WEB-INF/prop/weaver.properties
|
||||
/lib/classbean
|
||||
/file/
|
||||
/src/test/resources/application.properties
|
||||
/src/test/resources/application.xml
|
||||
|
||||
|
||||
|
||||
|
|
37
README.md
37
README.md
|
@ -42,6 +42,10 @@
|
|||
|
||||
5. 设置项目
|
||||
|
||||
在test文件夹中创建`resources`文件夹
|
||||
|
||||
<img src="static/image-20221123113034272.png" alt="image-20221123113034272" style="zoom: 50%;" />
|
||||
|
||||
新建lib\classbean文件夹(在lib下面新建classbean)
|
||||
|
||||
<img src="static/image-20221122114236545.png" alt="image-20221122114236545" style="zoom:50%;" />
|
||||
|
@ -54,7 +58,7 @@
|
|||
|
||||
![image-20221122114029683](static/image-20221122114029683.png)
|
||||
|
||||
![image-20221122114455378](static/image-20221122114455378.png)
|
||||
![image-20221123101605986](static/image-20221123101605986.png)
|
||||
|
||||
![image-20221122114530103](static/image-20221122114530103.png)
|
||||
|
||||
|
@ -86,11 +90,35 @@
|
|||
|
||||
<img src="static/image-20221122115303606.png" alt="image-20221122115303606" style="zoom:33%;" />
|
||||
|
||||
修改BaseTest文件中的应用跟路径
|
||||
在test/resources文件夹中创建两个文件
|
||||
|
||||
![image-20221122124437336](static/image-20221122124437336.png)
|
||||
`application.xml`
|
||||
|
||||
修改为当前项目的resource文件的绝对路径,文件路径可以设置也可以不设置,设置的话需要设置到你实际应用的附件地址,即ecology/web-inf/systemfile/
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
<beans>
|
||||
<bean id="propertyPlaceholderConfigurer"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="locations" value="classpath:application.properties" />
|
||||
</bean>
|
||||
<bean id="basetest" class="basetest.BaseTestConfig">
|
||||
<property name="serverName" value="${serverName}"/>
|
||||
<property name="rootPath" value="${rootPath}"/>
|
||||
<property name="systemFilePath" value="${systemFilePath}"/>
|
||||
<property name="logPath" value="${logPath}"/>
|
||||
</bean>
|
||||
</beans>
|
||||
```
|
||||
|
||||
`application.properties`
|
||||
|
||||
```properties
|
||||
serverName=ecology
|
||||
rootPath=/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/src/main/resources/ # 修改为实际的地址
|
||||
systemFilePath=/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/file # 修改为实际的地址,这里可以是你实际ecology的文件地址,即.../ecolog/web-inf/systemfile 绝对路径
|
||||
logPath=/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/log # 修改为实际的地址
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
@ -126,7 +154,6 @@
|
|||
* 提交代码之前先拉取代码到本地
|
||||
* 遇到代码冲突时,冲突代码需要与他人沟通后处理
|
||||
* maven文件中导如依赖需要注意依赖是否会和应用产生冲突
|
||||
* 测试代码中的BaseTest.java属于默认排除文件,请不要将配置规则删除,否则影响他人使用单元测试
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
<beans>
|
||||
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,93 @@
|
|||
package basetest;
|
||||
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.GCONST;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author EBU7-dev1-ayh
|
||||
* create 2021/12/13 0013 23:08
|
||||
*/
|
||||
|
||||
|
||||
public class BaseTest {
|
||||
|
||||
private ApplicationContext ctx;
|
||||
private Properties properties;
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
this.getContext();
|
||||
GCONST.setServerName(this.properties.getProperty("serverName"));
|
||||
GCONST.setRootPath(this.properties.getProperty("rootPath"));
|
||||
GCONST.setSystemFilePath(this.properties.getProperty("systemFilePath"));
|
||||
GCONST.setLogPath(this.properties.getProperty("logPath"));
|
||||
}
|
||||
|
||||
private void getContext() {
|
||||
Properties propertiesXml = new Properties();
|
||||
try {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");
|
||||
this.ctx = ctx;
|
||||
BaseTestConfig baseTestConfig = (BaseTestConfig) ctx.getBean("basetest");
|
||||
propertiesXml.setProperty("serverName", baseTestConfig.getServerName());
|
||||
propertiesXml.setProperty("rootPath", baseTestConfig.getRootPath());
|
||||
propertiesXml.setProperty("systemFilePath", baseTestConfig.getSystemFilePath());
|
||||
propertiesXml.setProperty("logPath", baseTestConfig.getLogPath());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
// 使用ClassLoader加载properties配置文件生成对应的输入流
|
||||
InputStream in = BaseTest.class.getClassLoader().getResourceAsStream("application.properties");
|
||||
// 使用properties对象加载输入流
|
||||
try {
|
||||
properties.load(in);
|
||||
if(in != null){
|
||||
try{
|
||||
in.close();
|
||||
}catch (IOException ex){
|
||||
|
||||
}
|
||||
}
|
||||
Enumeration<?> enumeration = propertiesXml.propertyNames();
|
||||
while (enumeration.hasMoreElements()){
|
||||
String key = (String) enumeration.nextElement();
|
||||
String value = propertiesXml.getProperty(key);
|
||||
properties.setProperty(key,value);
|
||||
}
|
||||
this.properties = properties;
|
||||
} catch (IOException ex) {
|
||||
throw new CustomerException("未发现application.properties",ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void with() {
|
||||
String sql = "select COMPANYNAME,LICENSE,EXPIREDATE,CVERSION from license ";
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery(sql);
|
||||
if (rs.next()) {
|
||||
System.out.println("公司名称:" + rs.getString(1));
|
||||
System.out.println("LICENSE:" + rs.getString(2));
|
||||
System.out.println("授权到期日期:" + rs.getString(3));
|
||||
System.out.println("版本:" + rs.getString(4));
|
||||
Console.log(sql);
|
||||
System.out.println(GCONST.getSysFilePath());
|
||||
// 打印文件位置
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package basetest;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <h1>配置信息</h1>
|
||||
*
|
||||
* <p>create: 2022-11-23 10:17</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BaseTestConfig {
|
||||
private String serverName;
|
||||
private String rootPath;
|
||||
private String systemFilePath;
|
||||
private String logPath;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package youhong.ai.pcn;
|
||||
|
||||
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
|
||||
import baseTest.BaseTest;
|
||||
import basetest.BaseTest;
|
||||
import org.junit.Test;
|
||||
import weaver.general.GCONST;
|
||||
import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil;
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 300 KiB |
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Loading…
Reference in New Issue