wangxuanran 2022-11-23 12:59:34 +08:00
commit 565a2e47f6
9 changed files with 158 additions and 12 deletions

3
.gitignore vendored
View File

@ -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
DirectoryV2.xml

View File

@ -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属于默认排除文件请不要将配置规则删除否则影响他人使用单元测试

View File

@ -1034,12 +1034,12 @@ public class HttpUtils {
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
Long totalSize = 0L;
for (MultipartFile multipartFile : multipartFileList) {
log.info(Util.logStr("add file, file info: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize()));
totalSize += multipartFile.getFileSize();
builder.addBinaryBody(multipartFile.getFileKey(), multipartFile.getStream(), ContentType.MULTIPART_FORM_DATA, multipartFile.getFileName());
}
log.info("total file size: [" + totalSize + "]");
log.info("total file size: [" + totalSize + "]kb");
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
for (Map.Entry<String, Object> param : params.entrySet()) {
StringBody stringBody = new StringBody(String.valueOf(param.getValue()), contentType);
@ -1083,12 +1083,12 @@ public class HttpUtils {
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
Long totalSize = 0L;
for (MultipartFile multipartFile : multipartFileList) {
log.info(Util.logStr("add file, file info: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize()));
totalSize += multipartFile.getFileSize();
builder.addBinaryBody(multipartFile.getFileKey(), multipartFile.getStream(), ContentType.MULTIPART_FORM_DATA, multipartFile.getFileName());
}
log.info("total file size: [" + totalSize + "]");
log.info("total file size: [" + totalSize + "]kb");
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
for (Map.Entry<String, Object> param : params.entrySet()) {
StringBody stringBody = new StringBody(String.valueOf(param.getValue()), contentType);

View File

@ -2,4 +2,5 @@
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
</beans>

View File

@ -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());
// 打印文件位置
}
}
}

View File

@ -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;
}

View File

@ -1,8 +1,7 @@
package youhong.ai.pcn;
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
import baseTest.BaseTest;
import com.jcraft.jsch.ChannelSftp;
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