Unit test environment

Source: Internet
Author: User

1. Create a new Loadpropertis class with the following contents:

Import Org.springframework.context.support.ClassPathXmlApplicationContext;

Import Junit.framework.TestCase;

public class Loadpropertis extends testcase{
private static classpathxmlapplicationcontext context= null;
private static String allproperties[] = {
"Applicationcontext-channel-test.xml", "Applicationcontext-common-test.xml"
};
protected void SetUp () throws exception{
Super.setup ();
if (context==null) {
context = new Classpathxmlapplicationcontext (allproperties);
}
}
protected void TearDown () throws exception{
Super.teardown ();
}
Protected Object Getbean (String beanname) {
if (Beanname = = null) {
throw new IllegalArgumentException (Beanname + "is null");
}
Return Context.getbean (Beanname);
}
}

2. NEW: Test01 class, the contents are as follows:

public class Test01 extends Loadpropertis {

Private Izybcorebs Zybcorebs;

protected void SetUp () throws exception{
Super.setup ();
Zybcorebs = (izybcorebs) this.getbean ("Zybcorebs");
}

protected void TearDown () throws exception{
Super.teardown ();
}

public void test01 () {

Curraccoinvo curraccoinvo = new Curraccoinvo ();

try {
Zybcorebs.curraccoquery (CURRACCOINVO);
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("failure");
}

}

}

3. Configuration file: The contents of the Application-channel-test.xml file are as follows:

<?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= "Zybcorebs" class= "Com.tansun.scf.zyb.intf.core.service.impl.ZybCoreBSImpl" >
<property name= "Busscommonbs" >
<ref bean= "Busscommonbs"/>
</property>
</bean>

<bean id= "Zybcmsbs" class= "Com.tansun.scf.zyb.intf.cms.service.impl.ZybCmsBSImpl" >
<property name= "Busscommonbs" >
<ref bean= "Busscommonbs"/>
</property>
</bean>

<bean id= "Busscommonbs" class= "Com.tansun.scf.common.service.impl.BussCommonBSImpl" >
<property name= "Sysparambs" >
<ref bean= "Sysparambs"/>
</property>
</bean>

</beans>

4. The configuration file Applicationcontext-common-test.xml content is as follows:

<?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= "Jndidatasource"
class= "Org.springframework.jndi.JndiObjectFactoryBean" >
<property name= "Jndiname" >
<value>OracleDataSource</value>
</property>
</bean>

<bean id= "Lobhandler"
class= "Org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init= "true"/>

</beans>

Where Applicationcontext-common-test.xml is the database configuration file and the database table XML file directory,

Applicationcontext-channel-test.xml is a method that calls the Java class's bean configuration information.

Unit test environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.