单元测试

web_backend_develope
chenlw 9 years ago
parent 7d0c47afe2
commit 385ad58fb5

@ -1,27 +1,23 @@
package com.platform.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import com.platform.utils.BeanCopy;
import com.platform.utils.Constant;
import com.platform.entities.PreDataInfo;
import com.platform.entities.PreDataInfoFull;
import com.platform.entities.RegionalismEntity;
import com.platform.utils.BeanCopy;
import com.platform.utils.Constant;
import com.platform.utils.excelUtils.ExcelOperation;
public class ExcelTest {
@ -47,7 +43,7 @@ public class ExcelTest {
XSSFWorkbook result = null;
try {
workbook = new XSSFWorkbook(res.getInputStream());
result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list,"id", "workRange");
result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list,"id", "workRange","sysCode","updateTime");
} catch (IllegalArgumentException
| IllegalAccessException | IOException e) {
// TODO Auto-generated catch block
@ -56,16 +52,23 @@ public class ExcelTest {
System.out.println("----"+result);
try {
File f = new File("D:/test/4.xlsx");
File f = new File("D:/test/6.xlsx");
FileOutputStream fileOut = null;
if (f.exists()) {
f.createNewFile();
fileOut = new FileOutputStream(f);
result.write(fileOut);
fileOut.close();
}
else {
System.out.println("no file");
f.createNewFile();
fileOut = new FileOutputStream(f);
result.write(fileOut);
fileOut.close();
}
File f3 = new File("D:/test/3.xlsx");
f3.delete();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -84,7 +87,7 @@ public class ExcelTest {
XSSFWorkbook workbook = null;
try {
workbook = new XSSFWorkbook(f);
list = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class,"id");
list = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class, "workRange","id","sysCode","updateTime");
} catch (IllegalArgumentException
| IllegalAccessException | InstantiationException | InvalidFormatException | IOException e) {
e.printStackTrace();
@ -117,9 +120,9 @@ public class ExcelTest {
info.setFunctionDetails("这是一个神奇的功能");
info.setDataVersion("2");
PreDataInfoFull full = new PreDataInfoFull();
PreDataInfo full = new PreDataInfo();
try {
BeanCopy.copyBean(info, full);
BeanCopy.copyBean(info, full,"id");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();

@ -0,0 +1,39 @@
package com.platform.test;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
import com.platform.utils.FileOperateHelper;
public class FileOperationTest {
@Test
public void addLastSeparator() {
System.out.println(FileOperateHelper.addLastSeparator("D:/gitTmp3/aggregation-platform"));
}
@Test
public void removeLastSeparator() {
System.out.println(FileOperateHelper.removeLastSeparator("D:/gitTmp3/aggregation-platform/"));
}
@Test
public void fileCreate() {
File f = new File("D:/Create1");
f.mkdir();
File f2 = new File("D:/Create1/1.txt");
try {
f2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File f3 = new File("D:/Create1");
f3.mkdir();
}
}
Loading…
Cancel
Save