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.jellytools.JellyTestCase; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 30 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 31 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 32 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarDetailsNode; 33 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarDetailsPanel; 34 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject; 35 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 36 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement; 37 import org.netbeans.modules.xml.multiview.XmlMultiViewEditorSupport; 38 import org.netbeans.modules.xml.multiview.ui.SectionNodeView; 39 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 40 import org.openide.cookies.EditCookie; 41 import org.openide.cookies.EditorCookie; 42 import org.openide.cookies.SaveCookie; 43 import org.openide.filesystems.FileObject; 44 import org.openide.filesystems.FileUtil; 45 import org.openide.loaders.DataObject; 46 import org.openide.nodes.Children; 47 import org.openide.nodes.Node; 48 49 50 51 52 56 public class EjbModuleTest extends JellyTestCase { 57 public static final String EJB_PROJECT_NAME = "TestCMP"; 58 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 59 60 private static Project project; 61 private static EjbJarMultiViewDataObject ddObj; 62 private static FileObject ddFo; 63 private static Entity bean; 64 private EjbJar ejbJar; 65 66 public EjbModuleTest(String testName) { 67 super(testName); 68 } 69 70 protected void setUp() throws Exception { 71 super.setUp(); 72 } 73 74 protected void tearDown() throws Exception { 75 } 76 77 public static Test suite() { 78 NbTestSuite suite = new NbTestSuite(); 79 suite.addTest(new EjbModuleTest("testOpenProject")); 80 suite.addTest(new EjbModuleTest("testRenameDisplayName")); 81 suite.addTest(new EjbModuleTest("testChangeDescription")); 82 suite.addTest(new EjbModuleTest("testAddSmallIcon")); 83 suite.addTest(new EjbModuleTest("testAddLargeIcon")); 84 return suite; 85 } 86 87 88 public static void main(java.lang.String [] args) { 89 TestRunner.run(suite()); 91 } 92 93 97 public void testOpenProject() throws Exception { 98 File projectDir = new File (EJB_PROJECT_PATH); 99 project = (Project)J2eeProjectSupport.openProject(projectDir); 100 assertNotNull("Project is null.", project); 101 Thread.sleep(1000); 102 103 EjbJarProject ejbJarProject = (EjbJarProject)project; 104 ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); assertNotNull("ejb-jar.xml FileObject is null.", ddFo); 106 107 ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); assertNotNull("MultiViewDO is null.",ddObj); 109 110 EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class); 111 edit.edit(); 112 Thread.sleep(1000); 113 } 114 115 118 public void testRenameDisplayName() throws Exception { 119 String displayName = "testDisplayName"; 120 assertNotNull("DDObject not found",ddObj); 121 122 ddObj.showElement(ddObj.getEjbJar()); Utils.waitForAWTDispatchThread(); 124 getDetailPanel().getDisplayNameTextField().setText(displayName); 125 assertEquals("DD bean isn't updated", displayName,DDProvider.getDefault().getDDRoot(ddFo).getDisplayName(null)); 127 Thread.sleep(4000); 128 checkinXML("<display-name>" + displayName + "</display-name>"); 129 130 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 132 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 133 if(saveCookie != null) 134 saveCookie.save(); 135 assertFile(FileUtil.toFile(ddFo),getGoldenFile("testRenameDisplayName_ejb-jar.xml"), new File (getWorkDir(), "testRenameDisplayName.diff")); 137 } 138 139 public void testChangeDescription() throws Exception { 140 String descriptionName = "test New description"; 141 getDetailPanel().getDescriptionTextArea().setText(descriptionName); 142 assertEquals("DD bean isn't updated", descriptionName,DDProvider.getDefault().getDDRoot(ddFo).getDescription(null)); 144 145 checkinXML("<description>" + descriptionName + "</description>"); 146 147 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 149 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 150 if(saveCookie != null) 151 saveCookie.save(); 152 assertFile(FileUtil.toFile(ddFo),getGoldenFile("testChangeDescription_ejb-jar.xml"), new File (getWorkDir(), "testChangeDescription.diff")); 154 } 155 156 public void testAddSmallIcon() throws Exception { 157 String smallIcon = "/tmp/test/small"; 158 getDetailPanel().getSmallIconTextField().setText(smallIcon); 159 assertEquals("DD bean isn't updated", smallIcon,DDProvider.getDefault().getDDRoot(ddFo).getSmallIcon()); 161 162 checkinXML("<small-icon>" + smallIcon + "</small-icon>"); 163 164 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 166 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 167 if(saveCookie != null) 168 saveCookie.save(); 169 assertFile(FileUtil.toFile(ddFo),getGoldenFile("testAddSmallIcon_ejb-jar.xml"), new File (getWorkDir(), "testAddSmallIcon.diff")); 171 } 172 173 public void testAddLargeIcon() throws Exception { 174 String largeIcon = "/tmp/test/large"; 175 getDetailPanel().getLargeIconTextField().setText(largeIcon); 176 assertEquals("DD bean isn't updated", largeIcon,DDProvider.getDefault().getDDRoot(ddFo).getLargeIcon()); 178 179 checkinXML("<large-icon>" + largeIcon + "</large-icon>"); 180 181 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 183 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 184 if(saveCookie != null) 185 saveCookie.save(); 186 assertFile(FileUtil.toFile(ddFo),getGoldenFile("testAddLargeIcon_ejb-jar.xml"), new File (getWorkDir(), "testAddLargeIcon.diff")); 188 } 189 190 private void checkinXML(String findText)throws Exception { 191 Thread.sleep(3000); 192 XmlMultiViewEditorSupport editor = (XmlMultiViewEditorSupport)ddObj.getCookie(EditorCookie.class); 194 javax.swing.text.Document document = editor.getDocument(); 195 document.addDocumentListener(new TestDocumentListener(findText)); 196 } 197 198 private EjbJarDetailsPanel getDetailPanel(){ 199 ToolBarMultiViewElement toolBar = ddObj.getActiveMVElement(); 200 assertNotNull("ToolBarMultiViewElement is null",toolBar); 201 SectionNodeView sectionView = (SectionNodeView)toolBar.getSectionView(); 202 203 Children nodes = sectionView.getRootNode().getChildren(); 204 Node[] n = nodes.getNodes(); 205 if(n[0] instanceof EjbJarDetailsNode){ 206 EjbJarDetailsNode detailNode = (EjbJarDetailsNode)n[0]; 207 return (EjbJarDetailsPanel)detailNode.getSectionNodePanel().getInnerPanel(); 208 } 209 return null; 210 } 211 212 } | Popular Tags |