KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > multiview > EjbModuleTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.j2ee.multiview;
21
22 import java.io.File JavaDoc;
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 /**
53  *
54  * @author blaha
55  */

56 public class EjbModuleTest extends JellyTestCase {
57     public static final String JavaDoc EJB_PROJECT_NAME = "TestCMP";
58     public static final String JavaDoc 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 JavaDoc testName) {
67         super(testName);
68     }
69     
70     protected void setUp() throws Exception JavaDoc {
71         super.setUp();
72     }
73     
74     protected void tearDown() throws Exception JavaDoc {
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     /** Use for execution inside IDE */
88     public static void main(java.lang.String JavaDoc[] args) {
89         // run only selected test case
90
TestRunner.run(suite());
91     }
92     
93     /*
94      * Method open project
95      *
96      */

97     public void testOpenProject() throws Exception JavaDoc{
98         File JavaDoc projectDir = new File JavaDoc(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(); // deployment descriptor
105
assertNotNull("ejb-jar.xml FileObject is null.", ddFo);
106         
107         ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); //MultiView Editor
108
assertNotNull("MultiViewDO is null.",ddObj);
109         
110         EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class);
111         edit.edit();
112         Thread.sleep(1000);
113     }
114     
115     /*
116      * Rename Display name from UI, test DD, text in editor and then check file
117      */

118     public void testRenameDisplayName() throws Exception JavaDoc {
119         String JavaDoc displayName = "testDisplayName";
120         assertNotNull("DDObject not found",ddObj);
121         
122         ddObj.showElement(ddObj.getEjbJar()); //open visual editor
123
Utils.waitForAWTDispatchThread();
124         getDetailPanel().getDisplayNameTextField().setText(displayName);
125         // check DD beans
126
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         //save ejb-jar.xml editor
131
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         //check file on disc
136
assertFile(FileUtil.toFile(ddFo),getGoldenFile("testRenameDisplayName_ejb-jar.xml"), new File JavaDoc(getWorkDir(), "testRenameDisplayName.diff"));
137     }
138     
139     public void testChangeDescription() throws Exception JavaDoc {
140         String JavaDoc descriptionName = "test New description";
141         getDetailPanel().getDescriptionTextArea().setText(descriptionName);
142         // check DD beans
143
assertEquals("DD bean isn't updated", descriptionName,DDProvider.getDefault().getDDRoot(ddFo).getDescription(null));
144         
145         checkinXML("<description>" + descriptionName + "</description>");
146         
147         //save ejb-jar.xml editor
148
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         //check file on disc
153
assertFile(FileUtil.toFile(ddFo),getGoldenFile("testChangeDescription_ejb-jar.xml"), new File JavaDoc(getWorkDir(), "testChangeDescription.diff"));
154     }
155     
156     public void testAddSmallIcon() throws Exception JavaDoc {
157         String JavaDoc smallIcon = "/tmp/test/small";
158         getDetailPanel().getSmallIconTextField().setText(smallIcon);
159         // check DD beans
160
assertEquals("DD bean isn't updated", smallIcon,DDProvider.getDefault().getDDRoot(ddFo).getSmallIcon());
161         
162         checkinXML("<small-icon>" + smallIcon + "</small-icon>");
163         
164         //save ejb-jar.xml editor
165
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         //check file on disc
170
assertFile(FileUtil.toFile(ddFo),getGoldenFile("testAddSmallIcon_ejb-jar.xml"), new File JavaDoc(getWorkDir(), "testAddSmallIcon.diff"));
171     }
172     
173     public void testAddLargeIcon() throws Exception JavaDoc {
174         String JavaDoc largeIcon = "/tmp/test/large";
175         getDetailPanel().getLargeIconTextField().setText(largeIcon);
176         // check DD beans
177
assertEquals("DD bean isn't updated", largeIcon,DDProvider.getDefault().getDDRoot(ddFo).getLargeIcon());
178         
179         checkinXML("<large-icon>" + largeIcon + "</large-icon>");
180         
181         //save ejb-jar.xml editor
182
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         //check file on disc
187
assertFile(FileUtil.toFile(ddFo),getGoldenFile("testAddLargeIcon_ejb-jar.xml"), new File JavaDoc(getWorkDir(), "testAddLargeIcon.diff"));
188     }
189     
190     private void checkinXML(String JavaDoc findText)throws Exception JavaDoc{
191         Thread.sleep(3000);
192         //check editor in text node
193
XmlMultiViewEditorSupport editor = (XmlMultiViewEditorSupport)ddObj.getCookie(EditorCookie.class);
194         javax.swing.text.Document JavaDoc 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