KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.awt.Frame JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.swing.JDialog JavaDoc;
25 import javax.swing.JFrame JavaDoc;
26 import javax.swing.SwingUtilities JavaDoc;
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 /**
55  *
56  * @author blaha
57  */

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 JavaDoc testName) {
67         super(testName);
68     }
69     
70     public static Test suite() {
71         NbTestSuite suite = new NbTestSuite();
72         // general panel
73
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         //class and interface panel
84
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     /** Use for execution inside IDE */
97     public static void main(java.lang.String JavaDoc[] args) {
98         // run only selected test case
99
TestRunner.run(suite());
100     }
101     
102     protected void setUp() throws Exception JavaDoc {
103         super.setUp();
104     }
105     
106     protected void tearDown() throws Exception JavaDoc {
107     }
108     
109     /*
110      * Method open project
111      *
112      */

113     public void testOpenProject() throws Exception JavaDoc{
114         File JavaDoc projectDir = new File JavaDoc(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(); // deployment descriptor
121
assertNotNull("ejb-jar.xml FileObject is null.", ddFo);
122         
123         ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); //MultiView Editor
124
assertNotNull("MultiViewDO is null.",ddObj);
125         
126         EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class);
127         edit.edit();
128         Thread.sleep(1000);
129         
130         // select CustomerBean
131
EnterpriseBeans beans = DDProvider.getDefault().getDDRoot(ddFo).getEnterpriseBeans();
132         bean = (Entity)beans.findBeanByName(EnterpriseBeans.ENTITY,
133                 Ejb.EJB_NAME ,"CustomerBean");
134         
135         ddObj.showElement(bean); //open visual editor
136
Utils.waitForAWTDispatchThread();
137     }
138     
139     // General panel
140

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 JavaDoc pkField = (String JavaDoc)getEntityGeneralPanel().getPrimaryKeyFieldComboBox().getSelectedItem();
159         assertEquals(bean.getPrimkeyField(), pkField);
160     }
161     
162     public void testEntityPKClass(){
163         String JavaDoc className = (String JavaDoc)getEntityGeneralPanel().getPrimaryKeyClassComboBox().getSelectedItem();
164         assertEquals(bean.getPrimKeyClass(), className);
165     }
166     
167     public void testChangeReentrant() throws Exception JavaDoc{
168         assertEquals(false, getEntityGeneralPanel().getReentrantCheckBox().isSelected());
169         getEntityGeneralPanel().getReentrantCheckBox().doClick(); // change it
170
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 JavaDoc(getWorkDir(), "testChangeReentrant.diff")); //check file on disc
176
}
177     
178     public void testChangePKMultiple() throws Exception JavaDoc{
179         assertNotNull("DDObject not found",ddObj);
180         getEntityGeneralPanel().getPrimaryKeyFieldComboBox().setSelectedIndex(0); //select multiply PK
181
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 JavaDoc[]{ "ejb-jar.xml"}, new String JavaDoc[]{ "CustomerBean.java", "CustomerLocalHome.java"});
188     }
189     
190     public void testChangePK() throws Exception JavaDoc {
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 JavaDoc[]{ "ejb-jar.xml"}, new String JavaDoc[]{ "CustomerBean.java", "CustomerLocalHome.java"});
200     }
201     
202     // Interfaces and implementation classes panel
203

204     public void testBeanClassName(){
205         assertEquals("cmp.CustomerBean", bean.getEjbClass());
206         //assertEquals("cmp.CustomerBean", getClassAndInterfacePanel().getBeanClassTextField().getText());
207
}
208     
209     public void testLocalHomeIName(){
210         assertEquals("cmp.CustomerLocalHome", bean.getLocalHome());
211         //assertEquals("cmp.CustomerLocalHome", getClassAndInterfacePanel().getLocalHomeTextField().getText());
212
}
213     
214     public void testLocalIName(){
215         assertEquals("cmp.CustomerLocal", bean.getLocal());
216         //assertEquals("cmp.CustomerLocal", getClassAndInterfacePanel().getLocalComponentTextField().getText());
217
}
218     
219     public void testLocalInterfaceCheckBox(){
220         assertEquals(true, getClassAndInterfacePanel().getLocalInterfaceCheckBox().isSelected());
221     }
222     
223     // bean doesn't have remote interface
224
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 JavaDoc{
239         ddObj.getEntityHelper(bean).addInterfaces(false); // add remote interface
240
// check DD API
241
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         // check XML view
248
Utils utils = new Utils(this);
249         utils.checkInXML(ddObj, "<remote>cmp.CustomerRemote</remote>");
250         utils.checkInXML(ddObj, "<home>cmp.CustomerRemoteHome</home>");
251         // check files
252
utils.save(ddObj);
253         utils.checkFiles("testEnableRemoteI", new String JavaDoc[]{ "ejb-jar.xml"},
254                 new String JavaDoc[]{ "CustomerBean.java", "CustomerRemoteHome.java", "CustomerRemote.java"});
255     }
256     
257     public void testDisableRemoteI() throws Exception JavaDoc{
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         // check XML view
266
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             //it's OK
273
}
274         // check files
275
utils.save(ddObj);
276         utils.checkFiles("testDisableRemoteI", new String JavaDoc[]{ "ejb-jar.xml"},
277                 new String JavaDoc[]{ "CustomerBean.java"});
278         // check tha interface files are deleted
279
checkDeletedFiles("CustomerRemoteHome.java");
280         checkDeletedFiles("CustomerRemote.java");
281         checkDeletedFiles("CustomerRemoteBusiness.java");
282     }
283     
284     
285     private void checkDeletedFiles(String JavaDoc fileName){
286         if(new File JavaDoc(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