View Javadoc

1   package net.sf.ehcache.hibernate;
2   
3   import static org.junit.Assert.assertNotNull;
4   import static org.junit.Assert.fail;
5   
6   import java.net.URL;
7   
8   import net.sf.ehcache.util.ClassLoaderUtil;
9   
10  import org.hibernate.HibernateException;
11  import org.hibernate.SessionFactory;
12  import org.hibernate.cfg.Configuration;
13  import org.junit.AfterClass;
14  import org.junit.BeforeClass;
15  import org.junit.Test;
16  
17  /***
18   * @author Alex Snaps
19   */
20  public class EhCacheRegionFactoryTest {
21  
22      private static Configuration config;
23  
24  
25      @BeforeClass
26      public static void setUp() throws Exception {
27          System.setProperty("derby.system.home", "target/derby");
28          config = new Configuration().configure("/hibernate-config/hibernate.cfg.xml");
29          config.setProperty("hibernate.hbm2ddl.auto", "create");
30      }
31  
32      @Test
33      public void testLoadingFromOutsideTheClasspath() {
34          URL resource = ClassLoaderUtil.getStandardClassLoader().getResource("hibernate-config/ehcache.xml");
35          config.setProperty("net.sf.ehcache.configurationResourceName", "file://" + resource.getFile());
36          SessionFactory sessionFactory = null;
37          try {
38              sessionFactory = config.buildSessionFactory();
39          } catch (HibernateException e) {
40              fail("This should have succeeded");
41          }
42          assertNotNull("Session factory should have been successfully created!", sessionFactory);
43          sessionFactory.close();
44      }
45  
46      @AfterClass
47      public static void tearDown() throws Exception {
48      }
49  }