public void testLocalSessionFactoryBeanWithDataSourceAndMappingJarLocations() throws Exception { final DriverManagerDataSource ds = new DriverManagerDataSource(); final Set invocations = new HashSet(); LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() { protected Configuration newConfiguration() { return new Configuration() { public Configuration addJar(File file) { invocations.add("addResource " + file.getPath()); return this; } }; } protected SessionFactory newSessionFactory(Configuration config) { assertEquals( LocalDataSourceConnectionProvider.class.getName(), config.getProperty(Environment.CONNECTION_PROVIDER)); assertEquals(ds, LocalSessionFactoryBean.getConfigTimeDataSource()); invocations.add("newSessionFactory"); return null; } }; sfb.setMappingJarLocations( new Resource[] { new FileSystemResource("mapping.hbm.jar"), new FileSystemResource("mapping2.hbm.jar") }); sfb.setDataSource(ds); sfb.afterPropertiesSet(); assertTrue(sfb.getConfiguration() != null); assertTrue(invocations.contains("addResource mapping.hbm.jar")); assertTrue(invocations.contains("addResource mapping2.hbm.jar")); assertTrue(invocations.contains("newSessionFactory")); }
/** * Used by the module testing framework to set the dependent modules in the hibernate session * factory * * @see * org.springframework.orm.hibernate3.LocalSessionFactoryBean#setMappingJarLocations(org.springframework.core.io.Resource[]) */ @Override public void setMappingJarLocations(Resource[] mappingJarLocations) { super.setMappingJarLocations(mappingJarLocations); }