| 1 9 package org.jboss.portal.test.core; 10 11 import java.util.Properties ; 12 13 import junit.framework.TestCase; 14 15 import org.jboss.portal.common.FQN; 16 import org.jboss.portal.common.value.BooleanValues; 17 import org.jboss.portal.common.value.IntegerValues; 18 import org.jboss.portal.common.value.StringValues; 19 import org.jboss.portal.core.impl.preferences.MappedPreferenceSet; 20 import org.jboss.portal.core.impl.preferences.MappedPreferenceStore; 21 import org.jboss.portal.server.plugins.preferences.PreferenceSet; 22 import org.hibernate.SessionFactory; 23 import org.hibernate.Session; 24 import org.hibernate.Transaction; 25 import org.hibernate.tool.hbm2ddl.SchemaExport; 26 import org.hibernate.cfg.Configuration; 27 28 32 public class PropertyMappingTestCase extends TestCase 33 { 34 35 public PropertyMappingTestCase(String name) 36 { 37 super(name); 38 } 39 40 private SessionFactory factory; 41 42 public void setUp() throws Exception  43 { 44 Configuration cfg = new Configuration(); 45 46 cfg.addResource("org/jboss/portal/core/impl/preferences/MappedPreferenceSet.hbm.xml", Thread.currentThread().getContextClassLoader()); 47 cfg.addResource("org/jboss/portal/core/impl/preferences/MappedPreference.hbm.xml", Thread.currentThread().getContextClassLoader()); 48 49 Properties props = new Properties (); 50 props.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.HSQLDialect"); 51 props.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); 52 props.setProperty("hibernate.connection.url", "jdbc:hsqldb:test"); 53 props.setProperty("hibernate.connection.username", "sa"); 54 props.setProperty("hibernate.connection.password", ""); 55 props.setProperty("hibernate.connection.pool_size", "1"); 56 props.setProperty("hibernate.cache.provider_class", "net.sf.hibernate.cache.TreeCacheProvider"); 57 cfg.setProperties(props); 58 59 SchemaExport export = new SchemaExport(cfg); 61 export.create(false, true); 62 63 factory = cfg.buildSessionFactory(); 64 } 65 66 protected void tearDown() throws Exception  67 { 68 factory.close(); 69 } 70 71 public void testBasic() throws Exception  72 { 73 final MappedPreferenceSet root = new MappedPreferenceSet("root"); 74 MappedPreferenceStore store = new MappedPreferenceStore() 75 { 76 protected MappedPreferenceSet getRoot() 77 { 78 return root; 79 } 80 }; 81 82 FQN _a = new FQN(new String []{"a"}); 83 FQN _b = new FQN(new String []{"a","b"}); 84 FQN _c = new FQN(new String []{"a","b","c"}); 85 86 StringValues va = new StringValues(new String []{"abc",null,"def",null}); 87 IntegerValues vb = new IntegerValues(new int[]{3,1,4}); 88 BooleanValues vc = new BooleanValues(new boolean[]{true,true,false,true}); 89 90 Session session = factory.openSession(); 91 Transaction tx = session.beginTransaction(); 92 session.save(root); 93 PreferenceSet a = store.get(_a); 94 PreferenceSet b = store.get(_b); 95 PreferenceSet c = store.get(_c); 96 a.setValue("prop_s", va); 97 b.setValue("prop_i", vb); 98 c.setValue("prop_b", vc); 99 tx.commit(); 100 session.close(); 101 102 session = factory.openSession(); 103 tx = session.beginTransaction(); 104 a = store.get(_a); 105 b = store.get(_b); 106 c = store.get(_c); 107 assertEquals(va, a.getValue("prop_s")); 108 assertEquals(vb, b.getValue("prop_i")); 109 assertEquals(vc, c.getValue("prop_b")); 110 tx.commit(); 111 session.close(); 112 } 113 } 114 | Popular Tags |