1 19 20 21 package org.netbeans.modules.j2ee.persistence.unit; 22 23 import junit.framework.*; 24 import junit.textui.TestRunner; 25 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit; 26 27 31 public class PersistenceUnitDataObjectTest extends PersistenceEditorTestBase{ 32 33 public PersistenceUnitDataObjectTest(String testName) { 34 super(testName); 35 } 36 37 public static Test suite() { 38 TestSuite suite = new TestSuite(PersistenceUnitDataObjectTest.class); 39 return suite; 40 } 41 42 public void testAddPersistenceUnit() throws Exception { 43 PersistenceUnit persistenceUnit = new PersistenceUnit(); 44 persistenceUnit.setName("em3"); 45 persistenceUnit.setJtaDataSource("jdbc/__default"); 46 dataObject.addPersistenceUnit(persistenceUnit); 47 48 assertTrue(containsUnit(persistenceUnit)); 49 assertTrue(dataCacheContains("\"em3\"")); 50 assertTrue(dataCacheContains("<jta-data-source>jdbc/__default")); 51 } 52 53 public void testRemovePersistenceUnit()throws Exception { 54 int originalSize = dataObject.getPersistence().getPersistenceUnit().length; 55 PersistenceUnit toBeRemoved = dataObject.getPersistence().getPersistenceUnit(0); 56 String name = toBeRemoved.getName(); 57 dataObject.removePersistenceUnit(toBeRemoved); 58 assertFalse(containsUnit(toBeRemoved)); 59 assertTrue(dataObject.getPersistence().getPersistenceUnit().length == originalSize -1); 60 assertFalse(dataCacheContains("name=\"" + name + "\"")); 61 } 62 63 public void testChangeName() throws Exception { 64 PersistenceUnit persistenceUnit = dataObject.getPersistence().getPersistenceUnit(0); 65 String oldName = persistenceUnit.getName(); 66 String newName = "new name"; 67 persistenceUnit.setName(newName); 68 dataObject.modelUpdatedFromUI(); 69 assertTrue(dataCacheContains("\"" + newName + "\"")); 70 assertFalse(dataCacheContains("\"" + oldName + "\"")); 71 } 72 73 public void testChangeDatasource() throws Exception { 74 PersistenceUnit persistenceUnit = dataObject.getPersistence().getPersistenceUnit(0); 75 String newDatasource = "jdbc/new_datasource"; 76 persistenceUnit.setJtaDataSource(newDatasource); 77 dataObject.modelUpdatedFromUI(); 78 assertEquals(newDatasource, persistenceUnit.getJtaDataSource()); 79 assertTrue(dataCacheContains(newDatasource)); 80 } 81 82 public void testAddClass() throws Exception { 83 PersistenceUnit persistenceUnit = dataObject.getPersistence().getPersistenceUnit(0); 84 String clazz = "com.foo.bar.FooClass"; 85 dataObject.addClass(persistenceUnit, clazz); 86 assertTrue(dataCacheContains(clazz)); 87 } 88 89 public void testRemoveClass() throws Exception { 90 PersistenceUnit persistenceUnit = dataObject.getPersistence().getPersistenceUnit(0); 91 String clazz = "com.foo.bar.FooClass"; 92 dataObject.addClass(persistenceUnit, clazz); 93 assertTrue(dataCacheContains(clazz)); 94 dataObject.removeClass(persistenceUnit, clazz); 95 assertFalse(dataCacheContains(clazz)); 96 } 97 98 public void testAddMultipleClasses() throws Exception { 99 PersistenceUnit persistenceUnit = dataObject.getPersistence().getPersistenceUnit(0); 100 String clazz = "com.foo.bar.FooClass"; 101 String clazz2 = "com.foo.bar.FooClass2"; 102 String clazz3 = "com.foo.bar.FooClass3"; 103 dataObject.addClass(persistenceUnit, clazz); 104 dataObject.addClass(persistenceUnit, clazz2); 105 dataObject.addClass(persistenceUnit, clazz3); 106 assertTrue(dataCacheContains(clazz)); 107 assertTrue(dataCacheContains(clazz2)); 108 assertTrue(dataCacheContains(clazz3)); 109 } 110 111 public static void main(String [] args) { 112 TestRunner.run(suite()); 113 } 114 115 116 117 } 118 | Popular Tags |