1 19 20 package org.netbeans.test.j2ee.multiview; 21 import java.awt.Frame ; 22 import java.io.File ; 23 import java.io.IOException ; 24 import javax.swing.JDialog ; 25 import javax.swing.JFrame ; 26 import javax.swing.SwingUtilities ; 27 import junit.framework.AssertionFailedError; 28 import junit.framework.Test; 29 import junit.textui.TestRunner; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.core.windows.view.ui.MainWindow; 32 import org.netbeans.jellytools.JellyTestCase; 33 import org.netbeans.junit.NbTestCase; 34 import org.netbeans.junit.NbTestSuite; 35 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 36 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 37 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 38 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 39 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 40 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbImplementationAndInterfacesNode; 41 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbImplementationAndInterfacesPanel; 42 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject; 43 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityOverviewNode; 44 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityOverviewPanel; 45 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 46 import org.netbeans.modules.xml.multiview.ui.SectionNodePanel; 47 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 48 import org.openide.cookies.EditCookie; 49 import org.openide.filesystems.FileObject; 50 import org.openide.filesystems.FileUtil; 51 import org.openide.loaders.DataObject; 52 import org.openide.nodes.Node; 53 54 58 public class EBGeneralAndClassPanelTest extends JellyTestCase { 59 60 private static Project project; 61 private static EjbJarMultiViewDataObject ddObj; 62 private static FileObject ddFo; 63 private static Entity bean; 64 private static EjbJar ejbJar; 65 66 public EBGeneralAndClassPanelTest(String testName) { 67 super(testName); 68 } 69 70 public static Test suite() { 71 NbTestSuite suite = new NbTestSuite(); 72 suite.addTest(new EBGeneralAndClassPanelTest("testOpenProject")); 74 suite.addTest(new EBGeneralAndClassPanelTest("testEntityNodeName")); 75 suite.addTest(new EBGeneralAndClassPanelTest("testEntityName")); 76 suite.addTest(new EBGeneralAndClassPanelTest("testEntityPersistanceType")); 77 suite.addTest(new EBGeneralAndClassPanelTest("testEntityAbstractName")); 78 suite.addTest(new EBGeneralAndClassPanelTest("testEntityPKField")); 79 suite.addTest(new EBGeneralAndClassPanelTest("testEntityPKClass")); 80 suite.addTest(new EBGeneralAndClassPanelTest("testChangeReentrant")); 81 suite.addTest(new EBGeneralAndClassPanelTest("testChangePKMultiple")); 82 suite.addTest(new EBGeneralAndClassPanelTest("testChangePK")); 83 suite.addTest(new EBGeneralAndClassPanelTest("testBeanClassName")); 85 suite.addTest(new EBGeneralAndClassPanelTest("testLocalInterfaceCheckBox")); 86 suite.addTest(new EBGeneralAndClassPanelTest("testLocalHomeIName")); 87 suite.addTest(new EBGeneralAndClassPanelTest("testLocalIName")); 88 suite.addTest(new EBGeneralAndClassPanelTest("testRemoteHomeIName")); 89 suite.addTest(new EBGeneralAndClassPanelTest("testRemoteIName")); 90 suite.addTest(new EBGeneralAndClassPanelTest("testRemoteInterfaceCheckBox")); 91 suite.addTest(new EBGeneralAndClassPanelTest("testEnableRemoteI")); 92 suite.addTest(new EBGeneralAndClassPanelTest("testDisableRemoteI")); 93 return suite; 94 } 95 96 97 public static void main(java.lang.String [] args) { 98 TestRunner.run(suite()); 100 } 101 102 protected void setUp() throws Exception { 103 super.setUp(); 104 } 105 106 protected void tearDown() throws Exception { 107 } 108 109 113 public void testOpenProject() throws Exception { 114 File projectDir = new File (Utils.EJB_PROJECT_PATH); 115 project = (Project)J2eeProjectSupport.openProject(projectDir); 116 assertNotNull("Project is null.", project); 117 Thread.sleep(1000); 118 119 EjbJarProject ejbJarProject = (EjbJarProject)project; 120 ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); assertNotNull("ejb-jar.xml FileObject is null.", ddFo); 122 123 ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); assertNotNull("MultiViewDO is null.",ddObj); 125 126 EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class); 127 edit.edit(); 128 Thread.sleep(1000); 129 130 EnterpriseBeans beans = DDProvider.getDefault().getDDRoot(ddFo).getEnterpriseBeans(); 132 bean = (Entity)beans.findBeanByName(EnterpriseBeans.ENTITY, 133 Ejb.EJB_NAME ,"CustomerBean"); 134 135 ddObj.showElement(bean); Utils.waitForAWTDispatchThread(); 137 } 138 139 141 public void testEntityNodeName() { 142 assertEquals("Entity node doesn't name CustomerEB", "CustomerEB", Utils.getEntityNode(ddObj).getDisplayName()); 143 } 144 145 public void testEntityName() { 146 assertEquals(bean.getEjbName(), getEntityGeneralPanel().getEjbNameTextField().getText()); 147 } 148 149 public void testEntityPersistanceType() { 150 assertEquals("Container (CMP)", getEntityGeneralPanel().getPersistenceTypeTextField().getText()); 151 } 152 153 public void testEntityAbstractName() { 154 assertEquals(bean.getAbstractSchemaName(), getEntityGeneralPanel().getAbstractSchemaNameTextField().getText()); 155 } 156 157 public void testEntityPKField() { 158 String pkField = (String )getEntityGeneralPanel().getPrimaryKeyFieldComboBox().getSelectedItem(); 159 assertEquals(bean.getPrimkeyField(), pkField); 160 } 161 162 public void testEntityPKClass(){ 163 String className = (String )getEntityGeneralPanel().getPrimaryKeyClassComboBox().getSelectedItem(); 164 assertEquals(bean.getPrimKeyClass(), className); 165 } 166 167 public void testChangeReentrant() throws Exception { 168 assertEquals(false, getEntityGeneralPanel().getReentrantCheckBox().isSelected()); 169 getEntityGeneralPanel().getReentrantCheckBox().doClick(); assertEquals(true,bean.isReentrant()); 171 Thread.sleep(1000); 172 Utils utils = new Utils(this); 173 utils.checkInXML(ddObj, "<reentrant>true</reentrant>"); 174 utils.save(ddObj); 175 assertFile(FileUtil.toFile(ddFo),getGoldenFile("testChangeReentrant_ejb-jar.xml"), new File (getWorkDir(), "testChangeReentrant.diff")); } 177 178 public void testChangePKMultiple() throws Exception { 179 assertNotNull("DDObject not found",ddObj); 180 getEntityGeneralPanel().getPrimaryKeyFieldComboBox().setSelectedIndex(0); getEntityGeneralPanel().getPrimaryKeyClassComboBox().setSelectedItem("cmp.CompoundClassTest"); 182 assertEquals("cmp.CompoundClassTest",bean.getPrimKeyClass()); 183 assertNull(bean.getPrimkeyField()); 184 Utils utils = new Utils(this); 185 utils.checkInXML(ddObj, "<prim-key-class>cmp.CompoundClassTest</prim-key-class>"); 186 utils.save(ddObj); 187 utils.checkFiles("testChangePKMultiple", new String []{ "ejb-jar.xml"}, new String []{ "CustomerBean.java", "CustomerLocalHome.java"}); 188 } 189 190 public void testChangePK() throws Exception { 191 assertNotNull("DDObject not found",ddObj); 192 getEntityGeneralPanel().getPrimaryKeyFieldComboBox().setSelectedItem("lastName"); 193 assertEquals("java.lang.String",bean.getPrimKeyClass()); 194 assertEquals("lastName", bean.getPrimkeyField()); 195 Utils utils = new Utils(this); 196 utils.checkInXML(ddObj, "<prim-key-class>java.lang.String</prim-key-class>"); 197 utils.checkInXML(ddObj, "<primkey-field>lastName</primkey-field>"); 198 utils.save(ddObj); 199 utils.checkFiles("testChangePK", new String []{ "ejb-jar.xml"}, new String []{ "CustomerBean.java", "CustomerLocalHome.java"}); 200 } 201 202 204 public void testBeanClassName(){ 205 assertEquals("cmp.CustomerBean", bean.getEjbClass()); 206 } 208 209 public void testLocalHomeIName(){ 210 assertEquals("cmp.CustomerLocalHome", bean.getLocalHome()); 211 } 213 214 public void testLocalIName(){ 215 assertEquals("cmp.CustomerLocal", bean.getLocal()); 216 } 218 219 public void testLocalInterfaceCheckBox(){ 220 assertEquals(true, getClassAndInterfacePanel().getLocalInterfaceCheckBox().isSelected()); 221 } 222 223 public void testRemoteHomeIName(){ 225 assertNull(bean.getHome()); 226 assertEquals("", getClassAndInterfacePanel().getRemoteHomeTextField().getText()); 227 } 228 229 public void testRemoteIName(){ 230 assertNull(bean.getRemote()); 231 assertEquals("", getClassAndInterfacePanel().getRemoteComponentTextField().getText()); 232 } 233 234 public void testRemoteInterfaceCheckBox(){ 235 assertEquals(false, getClassAndInterfacePanel().getRemoteInterfaceCheckBox().isSelected()); 236 } 237 238 public void testEnableRemoteI() throws Exception { 239 ddObj.getEntityHelper(bean).addInterfaces(false); Thread.sleep(1000); 242 assertEquals("cmp.CustomerRemote", bean.getRemote()); 243 assertEquals("cmp.CustomerRemote", getClassAndInterfacePanel().getRemoteComponentTextField().getText()); 244 assertEquals("cmp.CustomerRemoteHome", bean.getHome()); 245 assertEquals("cmp.CustomerRemoteHome", getClassAndInterfacePanel().getRemoteHomeTextField().getText()); 246 assertEquals(true, getClassAndInterfacePanel().getRemoteInterfaceCheckBox().isSelected()); 247 Utils utils = new Utils(this); 249 utils.checkInXML(ddObj, "<remote>cmp.CustomerRemote</remote>"); 250 utils.checkInXML(ddObj, "<home>cmp.CustomerRemoteHome</home>"); 251 utils.save(ddObj); 253 utils.checkFiles("testEnableRemoteI", new String []{ "ejb-jar.xml"}, 254 new String []{ "CustomerBean.java", "CustomerRemoteHome.java", "CustomerRemote.java"}); 255 } 256 257 public void testDisableRemoteI() throws Exception { 258 ddObj.getEntityHelper(bean).removeInterfaces(false); 259 Thread.sleep(1000); 260 assertNull(bean.getRemote()); 261 assertEquals("", getClassAndInterfacePanel().getRemoteComponentTextField().getText().trim()); 262 assertNull(bean.getHome()); 263 assertEquals("", getClassAndInterfacePanel().getRemoteHomeTextField().getText().trim()); 264 assertEquals(false, getClassAndInterfacePanel().getRemoteInterfaceCheckBox().isSelected()); 265 Utils utils = new Utils(this); 267 try{ 268 utils.checkInXML(ddObj, "<remote>cmp.CustomerRemote</remote>"); 269 utils.checkInXML(ddObj, "<home>cmp.CustomerRemoteHome</home>"); 270 fail("Remote elements are still displayd in text view."); 271 }catch(AssertionFailedError ex){ 272 } 274 utils.save(ddObj); 276 utils.checkFiles("testDisableRemoteI", new String []{ "ejb-jar.xml"}, 277 new String []{ "CustomerBean.java"}); 278 checkDeletedFiles("CustomerRemoteHome.java"); 280 checkDeletedFiles("CustomerRemote.java"); 281 checkDeletedFiles("CustomerRemoteBusiness.java"); 282 } 283 284 285 private void checkDeletedFiles(String fileName){ 286 if(new File (Utils.EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "cmp" + File.separator + fileName).exists()) 287 fail(fileName + " isn't deleted."); 288 } 289 290 private EntityOverviewPanel getEntityGeneralPanel(){ 291 Node[] nnChild = Utils.getChildrenNodes(Utils.getEntityNode(ddObj)); 292 for(int k = 0; k < nnChild.length; k++){ 293 if(nnChild[k] instanceof EntityOverviewNode){ 294 SectionNodePanel overviewPanel = ((EntityOverviewNode)nnChild[k]).getSectionNodePanel(); 295 overviewPanel.open(); 296 EntityOverviewPanel entityPanel = (EntityOverviewPanel)overviewPanel.getInnerPanel(); 297 return entityPanel; 298 } 299 } 300 return null; 301 } 302 303 private EjbImplementationAndInterfacesPanel getClassAndInterfacePanel(){ 304 assertNotNull(ddObj); 305 Node[] nnChild = Utils.getChildrenNodes(Utils.getEntityNode(ddObj)); 306 for(int k = 0; k < nnChild.length; k++){ 307 if(nnChild[k] instanceof EjbImplementationAndInterfacesNode){ 308 SectionNodePanel overviewPanel = ((EjbImplementationAndInterfacesNode)nnChild[k]).getSectionNodePanel(); 309 overviewPanel.open(); 310 return (EjbImplementationAndInterfacesPanel)overviewPanel.getInnerPanel(); 311 } 312 } 313 return null; 314 } 315 } | Popular Tags |