From b56e1a8deb1eb6ed8f5ed43d2b301346eed0cf41 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Tue, 20 Sep 2016 14:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8Dtest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - test/com/platform/test/Brick.java | 26 ++++++++ test/com/platform/test/FolderReader.java | 35 ++++++++++ test/com/platform/test/SMBasedTest.java | 15 +++++ test/com/platform/test/TestConnectOralce.java | 29 +++++++++ test/com/platform/test/TestController.java | 53 +++++++++++++++ test/com/platform/test/TestEncodeInfoDao.java | 64 +++++++++++++++++++ test/com/platform/test/TestEncodeService.java | 45 +++++++++++++ test/com/platform/test/User.java | 42 ++++++++++++ test/com/platform/test/Volume.java | 64 +++++++++++++++++++ test/com/platform/test/testSystemInfoDao.java | 19 ++++++ test/spring-applicationContext-test.xml | 64 +++++++++++++++++++ 12 files changed, 456 insertions(+), 1 deletion(-) create mode 100644 test/com/platform/test/Brick.java create mode 100644 test/com/platform/test/FolderReader.java create mode 100644 test/com/platform/test/SMBasedTest.java create mode 100644 test/com/platform/test/TestConnectOralce.java create mode 100644 test/com/platform/test/TestController.java create mode 100644 test/com/platform/test/TestEncodeInfoDao.java create mode 100644 test/com/platform/test/TestEncodeService.java create mode 100644 test/com/platform/test/User.java create mode 100644 test/com/platform/test/Volume.java create mode 100644 test/com/platform/test/testSystemInfoDao.java create mode 100644 test/spring-applicationContext-test.xml diff --git a/.gitignore b/.gitignore index c0b1f670..700b6555 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ .project .settings .metadata -/test \ No newline at end of file diff --git a/test/com/platform/test/Brick.java b/test/com/platform/test/Brick.java new file mode 100644 index 00000000..f83b37c1 --- /dev/null +++ b/test/com/platform/test/Brick.java @@ -0,0 +1,26 @@ +package com.platform.test; + +public class Brick { + private String ip; + private String path; + + public Brick(String ip, String path) { + super(); + this.ip = ip; + this.path = path; + } + public String getIp() { + return ip; + } + public void setIp(String ip) { + this.ip = ip; + } + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; + } + + +} diff --git a/test/com/platform/test/FolderReader.java b/test/com/platform/test/FolderReader.java new file mode 100644 index 00000000..57456af1 --- /dev/null +++ b/test/com/platform/test/FolderReader.java @@ -0,0 +1,35 @@ +package com.platform.test; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import com.platform.entities.FolderNode; + +public class FolderReader { + + public static FolderNode reader(String path) { + FolderNode folderNode = null; + File file = new File(path); + if (file.exists()) { + List childrens = new ArrayList(); + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + FolderNode children = reader(files[i].getAbsolutePath()); + if (children != null) + childrens.add(children); + } + } + } + return folderNode; + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + FolderReader folderReader = new FolderReader(); + FolderNode folderNode = folderReader.reader("D:/bootstrap"); + //folderReader.print(folderNode); + } + +} diff --git a/test/com/platform/test/SMBasedTest.java b/test/com/platform/test/SMBasedTest.java new file mode 100644 index 00000000..b0a77f9f --- /dev/null +++ b/test/com/platform/test/SMBasedTest.java @@ -0,0 +1,15 @@ +package com.platform.test; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.FileSystemXmlApplicationContext; + +public class SMBasedTest { + + public ApplicationContext applicationContext; + + public SMBasedTest() { + applicationContext = new FileSystemXmlApplicationContext( + "test/spring-applicationContext-test.xml"); + } + +} diff --git a/test/com/platform/test/TestConnectOralce.java b/test/com/platform/test/TestConnectOralce.java new file mode 100644 index 00000000..ef3f7b0e --- /dev/null +++ b/test/com/platform/test/TestConnectOralce.java @@ -0,0 +1,29 @@ +package com.platform.test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import com.platform.utils.Configs; + +public class TestConnectOralce { + + public static void main(String[] args) { + // TODO Auto-generated method stub + try{ + Class.forName("oracle.jdbc.driver.OracleDriver"); + Configs.CONSOLE_LOGGER.info("Oracle驱动加载成功"); + }catch(Exception e){ + System.out.println(e); + } + String url = "jdbc:oracle:thin:@192.168.0.110:60758:orcl"; + try { + Connection conn = DriverManager.getConnection(url, "system", "oracle"); + System.out.println("连接成功"); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/test/com/platform/test/TestController.java b/test/com/platform/test/TestController.java new file mode 100644 index 00000000..94e8aaf0 --- /dev/null +++ b/test/com/platform/test/TestController.java @@ -0,0 +1,53 @@ +package com.platform.test; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.platform.entities.EncodedInfoEntity; +import com.platform.service.EncodeInfoService; + +@Controller +public class TestController { + // private static Logger logger = Logger.getLogger(TestController.class); + @Resource(name = "encodeInfoService") + private EncodeInfoService eis; + + public void setEis(EncodeInfoService eis) { + this.eis = eis; + } + + @RequestMapping("/hello") + @ResponseBody + public List hello(String name, HttpServletResponse res) { + System.out.println(name); + return eis.getAllEncodeInfo("system_info"); + } + + @RequestMapping("/json") + @ResponseBody + public List getJson(HttpServletRequest res, HttpServletResponse req) { + List list = new ArrayList(); + list.add(new User("lisi", 1, "男")); + list.add(new User("zhansan", 2, "男")); + return list; + } + + @RequestMapping("log") + public void testLog(HttpServletResponse res) { + System.out.println(eis.getEncodeNameByCode("1", "system_info")); + } + + @RequestMapping("/data111.json") + public void test(String name, HttpServletResponse res){ + + + } +} diff --git a/test/com/platform/test/TestEncodeInfoDao.java b/test/com/platform/test/TestEncodeInfoDao.java new file mode 100644 index 00000000..3ad7d492 --- /dev/null +++ b/test/com/platform/test/TestEncodeInfoDao.java @@ -0,0 +1,64 @@ +package com.platform.test; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.platform.dao.EncodeInfoDao; +import com.platform.entities.EncodedInfoEntity; + +public class TestEncodeInfoDao extends SMBasedTest { + + private EncodeInfoDao eiDao; + private String testTableName; + + @Before + public void initBeforeFunction() { + eiDao = (EncodeInfoDao) this.applicationContext + .getBean("encodeInfoDao"); + testTableName = "system_info"; + } + + @Test + public void testGetAllEntityInfo() { + List allEntities = eiDao + .getAllEntityInfo(testTableName); + System.out.println(allEntities); + Assert.assertTrue(allEntities.size() > 0); + } + + @Test + public void testGetEncodeNameByCode() { + String result = eiDao.getEncodeNameByCode("1", testTableName); + Assert.assertTrue(result.equals("预算执行系统")); + } + + @Test + public void testGetEncodeCodeByName() { + List result = eiDao + .getEncodeCodeByName("预算执行系统", testTableName); + Assert.assertTrue(result.size() > 0); + } + + @Test + public void testUpdateEncodeNameByCode() { + int result = eiDao + .updateEncodeNameByCode("3", "财政一体化平台", testTableName); + Assert.assertTrue(result > 0); + } + + @Test + public void testInsertEncodeEntity() { + int result = eiDao.insertEncodeEntity(new EncodedInfoEntity("非税收入系统", + "4"), testTableName); + Assert.assertTrue(result == 1); + } + + @Test + public void testDeleteEncodeByCode() { + int result = eiDao.deleteEncodeByCode("5", testTableName); + Assert.assertTrue(result >= 1); + } +} diff --git a/test/com/platform/test/TestEncodeService.java b/test/com/platform/test/TestEncodeService.java new file mode 100644 index 00000000..a790ebe4 --- /dev/null +++ b/test/com/platform/test/TestEncodeService.java @@ -0,0 +1,45 @@ +package com.platform.test; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.platform.entities.EncodedInfoEntity; +import com.platform.service.EncodeInfoService; + +public class TestEncodeService extends SMBasedTest { + + private EncodeInfoService eis; + private String testTableName; + + @Before + public void initBeforeFunction() { + eis = (EncodeInfoService) this.applicationContext + .getBean("encodeInfoService"); + testTableName = "system_info"; + } + + @Test + public void testGetEncodeNameByCode() { + String result = eis.getEncodeNameByCode("2", testTableName); + Assert.assertTrue(result.equals("部门预算")); + } + + /** + * 事务测试 + */ + @Test + public void testDeleteEncodeByCode() { + eis.deleteEncodeByCode("4", testTableName); + } + + @Test + public void testGetAllEncodeInfo() { + List allEntities = eis + .getAllEncodeInfo(testTableName); + System.out.println(allEntities); + Assert.assertTrue(allEntities.size() >= 1); + } +} diff --git a/test/com/platform/test/User.java b/test/com/platform/test/User.java new file mode 100644 index 00000000..e96fbc11 --- /dev/null +++ b/test/com/platform/test/User.java @@ -0,0 +1,42 @@ +package com.platform.test; + +public class User { + private String name; + private int id; + private String sex; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public User(String name, int id, String sex) { + super(); + this.name = name; + this.id = id; + this.sex = sex; + } + + public User(){ + + } +} diff --git a/test/com/platform/test/Volume.java b/test/com/platform/test/Volume.java new file mode 100644 index 00000000..5f6a4423 --- /dev/null +++ b/test/com/platform/test/Volume.java @@ -0,0 +1,64 @@ +package com.platform.test; + +import java.util.List; + +import com.platform.entities.FolderNode; + +public class Volume { + private String name; + private long totalSize; + private long usedSize; + private List bricks; + private List folderNode; + + public Volume(String volume, long totalSize, long usedSize, + List bricks, List folderNode) { + super(); + this.name = volume; + this.totalSize = totalSize; + this.usedSize = usedSize; + this.bricks = bricks; + this.folderNode = folderNode; + } + + public String getVolume() { + return name; + } + + public void setVolume(String name) { + this.name = name; + } + + public long getTotalSize() { + return totalSize; + } + + public void setTotalSize(long totalSize) { + this.totalSize = totalSize; + } + + public long getUsedSize() { + return usedSize; + } + + public void setUsedSize(long usedSize) { + this.usedSize = usedSize; + } + + public List getBricks() { + return bricks; + } + + public void setBricks(List bricks) { + this.bricks = bricks; + } + + public List getFolderNode() { + return folderNode; + } + + public void setFolderNode(List folderNode) { + this.folderNode = folderNode; + } + +} diff --git a/test/com/platform/test/testSystemInfoDao.java b/test/com/platform/test/testSystemInfoDao.java new file mode 100644 index 00000000..95be6ef6 --- /dev/null +++ b/test/com/platform/test/testSystemInfoDao.java @@ -0,0 +1,19 @@ +package com.platform.test; + +import org.junit.Before; + +import com.platform.dao.DataInfoDao; + +public class testSystemInfoDao extends SMBasedTest { + private DataInfoDao dfDao; + + @Before + public void initBeforeFunction() { + dfDao = (DataInfoDao) this.applicationContext.getBean("dataInfoDao"); + } + + // @Test @Test + public void test() { + //System.out.println(dfDao.getCount()); + } +} diff --git a/test/spring-applicationContext-test.xml b/test/spring-applicationContext-test.xml new file mode 100644 index 00000000..27b1248b --- /dev/null +++ b/test/spring-applicationContext-test.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file