当前位置: 首页 > 工具软件 > Zeus XML > 使用案例 >

zeus持久层DAO单元测试

易研
2023-12-01

zeus代码测试正紧张进行中,但由于工作比较忙,但速度比较慢.现在已经完成读写分离单元测试了,现在把几种情况单元测试的例子发出来,希望有人能进出意见,让它走下去.

本文是zeus的dao单元测试:

1.单元测试直接上代码

 

package com.dengliang.zeus.webdemo.test;


import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dengliang.zeus.webdemo.dao.Dajc01DAO;
import com.dengliang.zeus.webdemo.vo.Dajc01VO;

/**
 * zeus持久层基本连接测试
 */
public class ZeusSimpledbTest {
	private static ApplicationContext context;
	/**
	 * 获取bean
	 * 
	 * @param id
	 * @return
	 */
	public static Object getBean(String id) {
		if (context == null) {
			synchronized (id) {
				context = new ClassPathXmlApplicationContext(
						"applicationContext-simpledb.xml",
						"applicationContext-dao.xml",
						"applicationContext-service.xml");
			}
		}
		return context.getBean(id);
	}
	@Test
	public void testDataSourceInterceptor() {
		// 只读测试
		Dajc01DAO service = (Dajc01DAO) ZeusSimpledbTest.getBean("dajc01DAO");
		try {
			Dajc01VO davo=service.findByPK("e09bb3c4d53c4663b86b427a2b83874a");
			System.out.println("aaaaaaaaaaaaaaaafdfdas"+davo.getCreateEmp()); 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}

 2,几个配置文件

 

applicationContext-simpledb.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx.xsd ">

	<context:property-placeholder location="classpath:*.properties" />
	<bean id="parentDataSource" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close">
		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="20" />
		<property name="minIdle" value="20" />
		<property name="maxIdle" value="30" />
		<property name="maxActive" value="50" />
		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="0" />
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />
		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<property name="removeAbandoned" value="false" />
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize"
			value="20" />
			<property name="filters" value ="stat,wall"></property>
	 </bean>
     
     <bean id="jlerp_db" parent="parentDataSource" destroy-method="close">
		<property name="url" value="jdbc:oracle:thin:@10.68.2.23:1521/erpdb" />
		<property name="username" value="jlerp_db" />
		<property name="password" value="jlerp_db" />
	</bean>	
	
	<!--daoSupport-->
	<bean id="zeusdaoSupport" class="com.dengliang.zeus.framework.dao.ZeusDaoSupport">
		<property name="dataSource" ref="jlerp_db"/>
	</bean>

</beans>

 

applicationContext-dao.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
		xmlns:p="http://www.springframework.org/schema/p" 
		xmlns:aop="http://www.springframework.org/schema/aop" 
		xmlns:tx="http://www.springframework.org/schema/tx"
		xmlns:context="http://www.springframework.org/schema/context"  
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
	<!-- DAO -->
	<bean id="dajc01DAO" class="com.dengliang.zeus.webdemo.dao.Dajc01DAO" parent="zeusdaoSupport"/>
</beans>

 applicationContext-service.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

	<!-- BIZ -->
	<bean id="dajc01Service" class="com.dengliang.zeus.webdemo.services.impl.Dajc01Service">
		<property name="dajc01DAO" ref="dajc01DAO" />
	</bean>
	
</beans>

 

 

zeus代码方式轻量级持久层架构,开发,调试简单,希望他能方便一些人

 类似资料: