diff --git a/.gitignore b/.gitignore index 3fd8530..6e63481 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index ca8c000..fc73479 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ 5. 设置项目 +在test文件夹中创建`resources`文件夹 + +image-20221123113034272 + 新建lib\classbean文件夹(在lib下面新建classbean) image-20221122114236545 @@ -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 @@ image-20221122115303606 -修改BaseTest文件中的应用跟路径 +在test/resources文件夹中创建两个文件 -![image-20221122124437336](static/image-20221122124437336.png) +`application.xml` -修改为当前项目的resource文件的绝对路径,文件路径可以设置也可以不设置,设置的话需要设置到你实际应用的附件地址,即ecology/web-inf/systemfile/ +```xml + + + + + + + + + + + + + +``` + +`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属于默认排除文件,请不要将配置规则删除,否则影响他人使用单元测试 diff --git a/src/main/resources/application.xml b/src/main/resources/application.xml index 16b1c41..9ffe6c2 100644 --- a/src/main/resources/application.xml +++ b/src/main/resources/application.xml @@ -2,4 +2,5 @@ + \ No newline at end of file diff --git a/src/test/java/basetest/BaseTest.java b/src/test/java/basetest/BaseTest.java new file mode 100644 index 0000000..bf98d94 --- /dev/null +++ b/src/test/java/basetest/BaseTest.java @@ -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()); + // 打印文件位置 + } + } +} diff --git a/src/test/java/basetest/BaseTestConfig.java b/src/test/java/basetest/BaseTestConfig.java new file mode 100644 index 0000000..3b7d5ce --- /dev/null +++ b/src/test/java/basetest/BaseTestConfig.java @@ -0,0 +1,25 @@ +package basetest; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + *

配置信息

+ * + *

create: 2022-11-23 10:17

+ * + * @author youHong.ai + */ + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class BaseTestConfig { + private String serverName; + private String rootPath; + private String systemFilePath; + private String logPath; +} diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 824965f..a5fbe98 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -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; diff --git a/static/image-20221123101605986.png b/static/image-20221123101605986.png new file mode 100644 index 0000000..d7cdd79 Binary files /dev/null and b/static/image-20221123101605986.png differ diff --git a/static/image-20221123113034272.png b/static/image-20221123113034272.png new file mode 100644 index 0000000..ec46f0a Binary files /dev/null and b/static/image-20221123113034272.png differ