here is my work out with upping idea:
1.make my hibernate configurer:

public class T5TestHibernateConfigurer implements HibernateConfigurer{
        private final boolean defaultConfiguration;
        private String configFile; // add configuration filepath on classpath
    public T5TestHibernateConfigurer(
            @Symbol(HibernateSymbols.DEFAULT_CONFIGURATION)
            boolean defaultConfiguration,
            String configFile)
    {
        this.defaultConfiguration = defaultConfiguration;
        this.configFile=configFile;
    }

    public void configure(Configuration configuration)
    {
        if (defaultConfiguration)
                configuration.configure();
        else
                configuration.configure(configFile);
    }
}

2.new one hibernate config file with hsqldb:hibernate-test.cfg.xml

3.make up hibernate core module by extending original hibernateCoreModule:
public class T5HBCoreModule extends HibernateCoreModule
{
    public static void bind(ServiceBinder binder)
    {
        binder.bind(HibernateTransactionDecorator.class,
HibernateTransactionDecoratorImpl.class);
        binder.bind(HibernateTransactionAdvisor.class,
HibernateTransactionAdvisorImpl.class);
    }

    public static T5TestHibernateConfigurer
buildT5TestHibernateConfigurer(final Logger log){
        log.info("buildT5TestHibernateConfigurer");
        return new T5TestHibernateConfigurer(false, "hibernate-test.cfg.xml");
    }

    public static void
contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
config,
                                                        @Local

HibernateConfigurer t5TestHibernateConfigurer)
    {
        config.add("t5HBConfig", t5TestHibernateConfigurer);
        config.addInstance("PackageName", PackageNameHibernateConfigurer.class);
    }
}
3.change my DAOTestCase code by using new HibernateCoreModule(T5HBCoreModule):
public class T5DAOTestCase<T extends GenericDAO> extends TestCase {
        protected RegistryBuilder builder;
        protected Registry reg;
        protected T dao;
        protected Logger log;

        protected void setUp(){
                builder=new RegistryBuilder();
                builder.add(TapestryIOCModule.class);
            builder.add(T5HBCoreModule.class);
            builder.add(MiniAppModule.class);
        
            reg= builder.build();
            reg.performRegistryStartup();
        
            //get daos and log service
            Class<T> daoClass  = (Class<T>) ((ParameterizedType) getClass()
                                
.getGenericSuperclass()).getActualTypeArguments()[0];
            dao= reg.getService(daoClass);
            log= reg.getService(Logger.class);
        }
        
        protected void tearDown(){
                //for operations done from this thread
               reg.cleanupThread();
               //call this to allow services clean shutdown
               reg.shutdown();
        }
}

5.using DAOTestCase:
public class TestMyDAO extends T5DAOTestCase<MyDAO> {
...
}

Enjoy this~

On Sat, Aug 7, 2010 at 4:34 AM, cleverpig <greatclever...@gmail.com> wrote:
> I checked out T5-hibernate-core source code,there's possible to make a
> test module for hibernate-core module.
> in HibernateCoreModule:
>
> public class HibernateCoreModule
> {
>    public static void bind(ServiceBinder binder)
>    {
>        binder.bind(HibernateTransactionDecorator.class,
> HibernateTransactionDecoratorImpl.class);
>        binder.bind(HibernateTransactionAdvisor.class,
> HibernateTransactionAdvisorImpl.class);
>        binder.bind(HibernateConfigurer.class,
> DefaultHibernateConfigurer.class).withId("DefaultHibernateConfigurer");
>    }
>    ...
>    public static void
> contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
> config,
>
>                                                       �...@local
>
> HibernateConfigurer defaultHibernateConfigurer)
>    {
>        config.add("Default", defaultHibernateConfigurer);
>        config.addInstance("PackageName", 
> PackageNameHibernateConfigurer.class);
>    }
> }
>
> It's my idea:
> 1.create a test-usage configurer like defaultConfigurer,but use hsqldb
> or sqlite.
> 2.contribute this configurer to HibernateSessionSource service in test
> module that will orverride the function above.
> 3.load this test module to build services,and then run unit test and
> integration test.
>
> It's a straw,let me try~
>
> On Fri, Aug 6, 2010 at 1:54 AM, based2 <ba...@free.fr> wrote:
>>
>> http://maven.apache.org/guides/mini/guide-building-for-different-environments.html
>> http://maven.apache.org/guides/introduction/introduction-to-profiles.html
>>
>> ==
>> http://tapestry.apache.org/tapestry5/tapestry-test/
>> http://tapestry.formos.com/projects/tapestry-testify/
>>
>> ref: http://wiki.apache.org/tapestry/Tapestry5ModuleRegistry
>>
>>
>> cleverpig-2 wrote:
>>>
>>> JMockit allows developers to write unit and integration tests without
>>> the testability issues typically found with other mocking tools.
>>> It support hibernate mock too.
>>>
>>> Sounds like very well fit with tapestry.
>>> T5 has test ability with inject dependency itself: it can load
>>> RegistryBuilder from test appModule to get DAO and service injections.
>>> such as :
>>> protected void setUp(){
>>>     builder=new RegistryBuilder();
>>>     builder.add(TapestryIOCModule.class);
>>>     builder.add(HibernateCoreModule.class);
>>>     builder.add(MiniAppModule.class); //MiniAppModule is my test app
>>> module
>>>     reg= builder.build();
>>>     reg.performRegistryStartup();
>>>     ...
>>> }
>>>
>>> Do you know how to make db related test on jmockit or dbunit?
>>>
>>> One simplest way: change hibernate to use hsqlDB in memory for test
>>> environment,but how can do that to change another hibernate
>>> configure,instead of product or development environment?
>>> --
>>> cleverpig(Dan)
>>> Location: Beijing
>>> Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
>>> Zipcode: 100031
>>> MSN: great_liu...@hotmail.com
>>> QQ: 149291732
>>> Skype: cleverpigatmatrix
>>> Facebook ID:cleverpig
>>> Blog: cleverpig.name/dan/
>>> Tags: del.icio.us/cleverpig
>>> Twitter: twitter.com/cleverpig
>>> 新浪微博: t.sina.com.cn/cleverpig
>>> Organization: www.beijing-open-party.org
>>> or...@facebook: http://www.facebook.com/group.php?gid=8159558294
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context: 
>> http://old.nabble.com/How-to-using-jmockit-or-dbunit-to-test-DAO-%28hibernate%29-in-tapestry--tp29343465p29356377.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>
>
>
> --
> cleverpig(Dan)
> Location: Beijing
> Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
> Zipcode: 100031
> MSN: great_liu...@hotmail.com
> QQ: 149291732
> Skype: cleverpigatmatrix
> Facebook ID:cleverpig
> Blog: cleverpig.name/dan/
> Tags: del.icio.us/cleverpig
> Twitter: twitter.com/cleverpig
> 新浪微博: t.sina.com.cn/cleverpig
> Organization: www.beijing-open-party.org
> or...@facebook: http://www.facebook.com/group.php?gid=8159558294
>



-- 
cleverpig(Dan)
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
MSN: great_liu...@hotmail.com
QQ: 149291732
Skype: cleverpigatmatrix
Facebook ID:cleverpig
Blog: cleverpig.name/dan/
Tags: del.icio.us/cleverpig
Twitter: twitter.com/cleverpig
新浪微博: t.sina.com.cn/cleverpig
Organization: www.beijing-open-party.org
or...@facebook: http://www.facebook.com/group.php?gid=8159558294

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to