Exemple #1
0
 @Test
 public void testOverwritesCacheManager() throws NoSuchFieldException, IllegalAccessException {
   URL resource =
       ClassLoaderUtil.getStandardClassLoader().getResource("hibernate-config/ehcache.xml");
   config.setProperty("net.sf.ehcache.configurationResourceName", "file://" + resource.getFile());
   config.setProperty("net.sf.ehcache.cacheManagerName", "overwrittenCacheManagerName");
   SessionFactory sessionFactory = config.buildSessionFactory();
   final Field cache_managers_map = CacheManager.class.getDeclaredField("CACHE_MANAGERS_MAP");
   cache_managers_map.setAccessible(true);
   assertThat(((Map) cache_managers_map.get(null)).get("tc"), nullValue());
   assertThat(
       ((Map) cache_managers_map.get(null)).get("overwrittenCacheManagerName"), notNullValue());
   sessionFactory.close();
 }
Exemple #2
0
 @Test
 public void testLoadingFromOutsideTheClasspath() {
   URL resource =
       ClassLoaderUtil.getStandardClassLoader().getResource("hibernate-config/ehcache.xml");
   config.setProperty("net.sf.ehcache.configurationResourceName", "file://" + resource.getFile());
   SessionFactory sessionFactory = null;
   try {
     sessionFactory = config.buildSessionFactory();
   } catch (HibernateException e) {
     e.printStackTrace();
     fail("This should have succeeded");
   }
   assertNotNull("Session factory should have been successfully created!", sessionFactory);
   sessionFactory.close();
 }