Browse Source

新增单元测试,使用h2内存数据库作为测试数据库

周浩 9 years ago
parent
commit
1e83721f34

+ 15 - 0
hsweb-web-service-impl-common/src/test/java/org/hsweb/web/service/impl/AbstractTestCase.java

@@ -0,0 +1,15 @@
+package org.hsweb.web.service.impl;
+
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.SpringApplicationConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Created by zhouhao on 16-4-20.
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringApplicationConfiguration(classes = SpringApplication.class)
+public abstract class AbstractTestCase {
+
+
+}

+ 28 - 0
hsweb-web-service-impl-common/src/test/java/org/hsweb/web/service/impl/DataBaseAutoConfiguration.java

@@ -0,0 +1,28 @@
+package org.hsweb.web.service.impl;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.webbuilder.sql.DataBase;
+import org.webbuilder.sql.DataBaseMetaData;
+import org.webbuilder.sql.support.OracleDataBaseMetaData;
+import org.webbuilder.sql.support.common.CommonDataBase;
+import org.webbuilder.sql.support.executor.SqlExecutor;
+
+import javax.annotation.Resource;
+import java.sql.DatabaseMetaData;
+
+/**
+ * Created by zhouhao on 16-4-20.
+ */
+@Configuration
+public class DataBaseAutoConfiguration {
+    @Resource
+    private SqlExecutor sqlExecutor;
+
+    @Bean
+    public DataBase getDataBase() {
+        DataBaseMetaData dataBaseMetaData = new OracleDataBaseMetaData();
+        DataBase dataBase = new CommonDataBase(dataBaseMetaData, sqlExecutor);
+        return dataBase;
+    }
+}

+ 18 - 0
hsweb-web-service-impl-common/src/test/java/org/hsweb/web/service/impl/SpringApplication.java

@@ -0,0 +1,18 @@
+package org.hsweb.web.service.impl;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+/**
+ * Created by zhouhao on 16-4-20.
+ */
+@Configuration
+@EnableAutoConfiguration
+@ComponentScan(basePackages = {"org.hsweb.web"})
+@EnableTransactionManagement(proxyTargetClass = true)
+@MapperScan(basePackages = {"org.hsweb.web.dao"})
+public class SpringApplication {
+}

File diff suppressed because it is too large
+ 76 - 0
hsweb-web-service-impl-common/src/test/java/org/hsweb/web/service/impl/form/FormServiceImplTest.java