From 8a8cf33c4ac6e957553de9c33662c89cc916e347 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Wed, 23 Nov 2022 14:29:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BaseTest=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F=E5=BC=95=E7=94=A8?= =?UTF-8?q?log=E6=8A=A5=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/basetest/BaseTest.java | 68 ++++++++++++-- .../java/youhong/ai/pcn/TestOrganization.java | 88 +++++++++++++++++++ 2 files changed, 147 insertions(+), 9 deletions(-) diff --git a/src/test/java/basetest/BaseTest.java b/src/test/java/basetest/BaseTest.java index bf98d94..2255e2a 100644 --- a/src/test/java/basetest/BaseTest.java +++ b/src/test/java/basetest/BaseTest.java @@ -1,8 +1,11 @@ package basetest; +import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; import cn.hutool.core.lang.Console; +import org.apache.log4j.Logger; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -25,15 +28,14 @@ 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 static Properties propertiesStatic; + @BeforeClass + public static void beforeStatic(){ + BaseTest.getContextStatic(); + GCONST.setServerName(propertiesStatic.getProperty("serverName")); + GCONST.setRootPath(propertiesStatic.getProperty("rootPath")); + GCONST.setSystemFilePath(propertiesStatic.getProperty("systemFilePath")); + GCONST.setLogPath(propertiesStatic.getProperty("logPath")); } private void getContext() { @@ -74,9 +76,57 @@ public class BaseTest { } } + @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 static void getContextStatic() { + Properties propertiesXml = new Properties(); + try { + ApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml"); + 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); + } + propertiesStatic = properties; + } catch (IOException ex) { + throw new CustomerException("未发现application.properties",ex); + } + } + @Test public void with() { + Logger logger = Util.getLogger(); + logger.info("aafasdf"); String sql = "select COMPANYNAME,LICENSE,EXPIREDATE,CVERSION from license "; RecordSet rs = new RecordSet(); rs.executeQuery(sql); diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index a5fbe98..d3c61ba 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -1,11 +1,24 @@ package youhong.ai.pcn; +import aiyh.utils.Util; +import com.alibaba.fastjson.JSON; import ebu7common.youhong.ai.sftp.SftpConnectUtil; import basetest.BaseTest; +import org.apache.log4j.Logger; import org.junit.Test; import weaver.general.GCONST; import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** *