Well, after litigating a bit, and browsing the source code (I know
that soon or later one have to :P ) I've found this solution that
works pretty well and is pretty immediate to use:

@BeforeSuite
    public void initSuite()
    {
        SymbolProvider provider = new
SingleKeySymbolProvider(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM,
this.getClass().getPackage().getName());

        TapestryAppInitializer initializer = new
TapestryAppInitializer(provider, "app", PageTesterModule.TEST_MODE);

        initializer.addModules(PageTesterModule.class);
        initializer.addModules(JFlyBusinessModule.class);

        theRegistry = initializer.getRegistry();
    }

Then I can test all service methods without any problem.

(I'm not sure if I really need to add the PageTesterModule class)

Hope that someone might find this useful.
Cheers,
kiuma



On Thu, Apr 2, 2009 at 10:53 AM, Tapestry Infodea <tapes...@infodea.it> wrote:
> I use Tapestry 5.0.18 and I can test Hibernate.
> The classes that I use for testing are as follows:
>
>
> //A Test Module in order to use a specific configuration on test environment
> @SubModule( { AppModule.class })
> public class AppTestModule {
>
>        public static void
> contributeApplicationDefaults(MappedConfiguration<String, String>
> configuration) {
>                configuration.add(HibernateConstants.DEFAULT_CONFIGURATION,
> "false");
>        }
>
>        public static void
> contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
> config) {
>                HibernateConfigurer conf = new HibernateConfigurer() {
>                        public void configure(Configuration configuration) {
>                                Configuration cfg = new Configuration();
>                                Properties properties = new Properties();
>                                try {
>
> properties.load(AppTestModule.class.getResourceAsStream("/hibernate.properties"));
>                                } catch (IOException e) {
>                                        e.printStackTrace();
>                                }
>                                cfg.setProperties(properties);
>                        }
>                };
>                config.add("Test", conf);
>        }
>
> }
>
> //A class of tests
> public class TestDataService extends Assert {
>
>        private Registry registry;
>
>        private DataService dataService;
>
>       �...@beforesuite
>        public void init() {
>                RegistryBuilder builder = new RegistryBuilder();
>                builder.add(HibernateModule.class);
>                builder.add(AppTestModule.class);
>                registry = builder.build();
>                registry.performRegistryStartup();
>                dataService = registry.getService(DataService.class);
>        }
>
>       �...@test
>        public void testHasUsersOnManageService() {
>                boolean test= dataService.findSomething();
>                assertTrue(test);
>        }
>
>       �...@aftersuite
>        void close() {
>                registry.shutdown();
>        }
>
> }
>
>
> Roberto.
>
> Juan E. Maya ha scritto:
>>
>> Hi Andrea, What version of tapestry are you working with?
>> As far as i know using tapestry 5.0 this is not possible (or at least
>> without a workaround) using tapestry 5.0.1 tapestry-hibernate-core now
>> support using tapestry-hibernate in standalone applications what makes it
>> possible to use in unit tests.
>>
>> On Wed, Apr 1, 2009 at 12:59 PM, Andrea Chiumenti <kium...@gmail.com>
>> wrote:
>>
>>> Hello I'm having problems understanding how to make tapestry-hibernate to
>>> work:
>>>
>>> I've created the following library module:
>>>
>>> public class JFlyBusinessModule
>>> {
>>>
>>>   public static void bind(ServiceBinder binder)
>>>   {
>>>       binder.bind(CAuditDAO.class, CAuditDAOImpl.class);
>>>       binder.bind(CClientDAO.class, CClientDAOImpl.class);
>>>       binder.bind(CUserDAO.class, CUserDAOImpl.class);
>>>       binder.bind(AuditService.class, AuditServiceImpl.class);
>>>   }
>>>
>>>   public static void
>>> contributeAuditService(MappedConfiguration<String, String>
>>> contributions)
>>>   {
>>>       contributions.add("log.level", IAuditType.TYPE_WARN);
>>>   }
>>>   public static void
>>> contributeHibernateEntityPackageManager(Configuration<String>
>>> configuration)
>>>   {
>>>       configuration.add("it.wingstech.jflymodel");
>>>   }
>>>
>>>   @Match(
>>>   {
>>>       "*DAO", "*Service"
>>>   })
>>>   public static <T> T
>>> decorateTransactionally(HibernateTransactionDecorator decorator,
>>> Class<T> serviceInterface,
>>>           T delegate,
>>>           String serviceId)
>>>   {
>>>       return decorator.build(serviceInterface, delegate, serviceId);
>>>   }
>>>
>>> }
>>>
>>> then my service constructor is:
>>> public AuditServiceImpl(Map<String, String> contributions, CAuditDAO
>>> auditDao, Session session, Logger logger)
>>>       {
>>>               super(session, logger);
>>>       this.auditDao = auditDao;
>>>       setLevel(CommonUtils.oneOf(contributions.get("log.level"),
>>> IAuditType.TYPE_INFO));
>>>
>>>       }
>>>
>>>
>>> when I try to start my tests I have the following message:
>>> java.lang.RuntimeException: Exception constructing service
>>> 'AuditService': Error invoking constructor
>>> it.wingstech.jflybusiness.services.AuditServiceImpl(Map, CAuditDAO,
>>> Session, Logger) (at AuditServiceImpl.java:39) via
>>> it.wingstech.jflybusiness.services.JFlyBusinessModule.bind(ServiceBinder)
>>> (at JFlyBusinessModule.java:34) (for service 'AuditService'): No
>>> service implements the interface org.hibernate.Session.
>>>
>>> I've seen into the sourcess that there is no service for
>>> org.hibernate.Session.
>>>
>>> So I'm wondering how my service is different from the one contained
>>> int tapestry-hibernate.
>>> I also wonder How could I have a Session per request, then.
>>>
>>> Please help me, 'cause I'm in a stale situation.
>>>
>>> Thanks in advance,
>>> kiuma
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

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

Reply via email to