1 19 20 package org.netbeans.test.j2ee.multiview; 21 22 import java.io.File ; 23 import junit.framework.Test; 24 import junit.textui.TestRunner; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.junit.NbTestSuite; 28 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 29 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 30 import org.netbeans.modules.j2ee.dd.api.ejb.EjbRelation; 31 import org.netbeans.modules.j2ee.dd.api.ejb.EjbRelationshipRole; 32 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 33 import org.netbeans.modules.j2ee.dd.api.ejb.RelationshipRoleSource; 34 import org.netbeans.modules.j2ee.dd.api.ejb.Relationships; 35 import org.netbeans.modules.j2ee.ddloaders.multiview.CmpRelationShipsNode; 36 import org.netbeans.modules.j2ee.ddloaders.multiview.CmpRelationshipsDialogHelper; 37 import org.netbeans.modules.j2ee.ddloaders.multiview.CmpRelationshipsTableModel; 38 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarDetailsNode; 39 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarDetailsPanel; 40 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject; 41 import org.netbeans.modules.j2ee.ddloaders.multiview.InnerTablePanel; 42 import org.netbeans.modules.j2ee.ddloaders.multiview.RelationshipHelper; 43 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 44 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement; 45 import org.netbeans.modules.xml.multiview.XmlMultiViewEditorSupport; 46 import org.netbeans.modules.xml.multiview.ui.SectionNodeView; 47 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 48 import org.openide.cookies.EditCookie; 49 import org.openide.cookies.EditorCookie; 50 import org.openide.cookies.SaveCookie; 51 import org.openide.filesystems.FileObject; 52 import org.openide.filesystems.FileUtil; 53 import org.openide.loaders.DataObject; 54 import org.openide.nodes.Children; 55 import org.openide.nodes.Node; 56 57 58 59 60 64 public class CMPRelationshipsTest extends DDTestCase { 65 public static final String EJB_PROJECT_NAME = "TestCMPRelationships"; 66 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 67 68 69 public CMPRelationshipsTest(String testName) { 70 super(testName); 71 } 72 73 protected void setUp() throws Exception { 74 super.setUp(); 75 } 76 77 protected void tearDown() throws Exception { 78 } 79 80 public static Test suite() { 81 NbTestSuite suite = new NbTestSuite(); 82 suite.addTest(new CMPRelationshipsTest("testOpenProject")); 83 suite.addTest(new CMPRelationshipsTest("testAddRelationship")); 84 suite.addTest(new CMPRelationshipsTest("testModifyRelationship")); 85 suite.addTest(new CMPRelationshipsTest("testRemoveRelationship")); 86 return suite; 87 } 88 89 90 public static void main(java.lang.String [] args) { 91 TestRunner.run(suite()); 93 } 94 95 99 public void testOpenProject() throws Exception { 100 File projectDir = new File (EJB_PROJECT_PATH); 101 project = (Project)J2eeProjectSupport.openProject(projectDir); 102 assertNotNull("Project is null.", project); 103 Thread.sleep(1000); 104 105 EjbJarProject ejbJarProject = (EjbJarProject)project; 106 ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); assertNotNull("ejb-jar.xml FileObject is null.", ddFo); 108 109 ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); assertNotNull("MultiViewDO is null.",ddObj); 111 112 EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class); 113 edit.edit(); 114 Thread.sleep(1000); 115 } 116 117 120 public void testAddRelationship() throws Exception { 121 String displayName = "testAddRelationship"; 122 assertNotNull("DDObject not found",ddObj); 123 EjbJar ejbJar=ddObj.getEjbJar(); 124 Relationships relationships=ejbJar.getSingleRelationships(); 125 if (relationships==null) relationships=ddObj.getEjbJar().newRelationships(); 126 ejbJar.setRelationships(relationships); 127 ddObj.showElement(relationships); Utils.waitForAWTDispatchThread(); 129 130 CmpRelationshipsTableModel tableModel=(CmpRelationshipsTableModel) getDetailPanel().getTable().getModel(); 131 132 RelationshipHelper relationshipHelper=new RelationshipHelper(relationships); 133 134 relationshipHelper.setRelationName("test"); 135 relationshipHelper.setDescription("test description"); 136 relationshipHelper.roleA.setRoleName("role A"); 137 relationshipHelper.roleA.setEjbName("EntityABean"); 138 relationshipHelper.roleA.setMultiple(false); 139 relationshipHelper.roleA.setCascadeDelete(false); 140 relationshipHelper.roleB.setRoleName("role B"); 141 relationshipHelper.roleB.setEjbName("EntityBBean"); 142 relationshipHelper.roleB.setMultiple(false); 143 relationshipHelper.roleB.setCascadeDelete(false); 144 ddObj.getModelSynchronizer().requestUpdateData(); 145 146 Thread.sleep(4000); 147 Utils.waitForAWTDispatchThread(); 148 149 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 151 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 152 if(saveCookie != null) 153 saveCookie.save(); 154 assertFile("ejb-jar.xml"); 156 } 157 158 161 public void testModifyRelationship() throws Exception { 162 String displayName = "testModifyRelationship"; 163 assertNotNull("DDObject not found",ddObj); 164 EjbJar ejbJar=ddObj.getEjbJar(); 165 Relationships relationships=ejbJar.getSingleRelationships(); 166 if (relationships==null) fail("Relationships == null"); 167 ddObj.showElement(relationships); Utils.waitForAWTDispatchThread(); 169 170 CmpRelationshipsTableModel tableModel=(CmpRelationshipsTableModel) getDetailPanel().getTable().getModel(); 171 172 EjbRelation ejbRelation = ejbJar.getSingleRelationships().getEjbRelation(0); 173 RelationshipHelper relationshipHelper=new RelationshipHelper(ejbRelation); 174 175 relationshipHelper.roleA.setMultiple(true); 176 relationshipHelper.roleA.setCascadeDelete(false); 177 relationshipHelper.roleB.setMultiple(true); 178 relationshipHelper.roleB.setCascadeDelete(false); 179 ddObj.getModelSynchronizer().requestUpdateData(); 180 181 Thread.sleep(4000); 182 Utils.waitForAWTDispatchThread(); 183 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 185 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 186 if(saveCookie != null) 187 saveCookie.save(); 188 assertFile("ejb-jar.xml"); 191 } 192 193 196 public void testRemoveRelationship() throws Exception { 197 String displayName = "testRemoveRelationship"; 198 assertNotNull("DDObject not found",ddObj); 199 EjbJar ejbJar=ddObj.getEjbJar(); 200 Relationships relationships=ejbJar.getSingleRelationships(); 201 if (relationships==null) fail("Relationships == null"); 202 ddObj.showElement(relationships); Utils.waitForAWTDispatchThread(); 204 205 relationships.removeEjbRelation(relationships.getEjbRelation(0)); 206 ejbJar.setRelationships(null); 207 ddObj.getModelSynchronizer().requestUpdateData(); 208 209 Thread.sleep(4000); 210 Utils.waitForAWTDispatchThread(); 211 212 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 214 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 215 if(saveCookie != null) 216 saveCookie.save(); 217 assertFile("ejb-jar.xml"); 219 } 220 221 222 223 224 225 } | Popular Tags |