KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
61  *
62  * @author jhorvath
63  */

64 public class CMPRelationshipsTest extends DDTestCase {
65     public static final String JavaDoc EJB_PROJECT_NAME = "TestCMPRelationships";
66     public static final String JavaDoc EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME;
67
68     
69     public CMPRelationshipsTest(String JavaDoc testName) {
70         super(testName);
71     }
72     
73     protected void setUp() throws Exception JavaDoc {
74         super.setUp();
75     }
76     
77     protected void tearDown() throws Exception JavaDoc {
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     /** Use for execution inside IDE */
90     public static void main(java.lang.String JavaDoc[] args) {
91         // run only selected test case
92
TestRunner.run(suite());
93     }
94     
95     /*
96      * Method open project
97      *
98      */

99     public void testOpenProject() throws Exception JavaDoc{
100         File JavaDoc projectDir = new File JavaDoc(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(); // deployment descriptor
107
assertNotNull("ejb-jar.xml FileObject is null.", ddFo);
108         
109         ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); //MultiView Editor
110
assertNotNull("MultiViewDO is null.",ddObj);
111         
112         EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class);
113         edit.edit();
114         Thread.sleep(1000);
115     }
116     
117     /*
118      * Add CMP Relationship
119      */

120     public void testAddRelationship() throws Exception JavaDoc {
121         String JavaDoc 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); //open visual editor
128
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         //save ejb-jar.xml editor
150
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         //check file on disc
155
assertFile("ejb-jar.xml");
156     }
157     
158     /*
159      * Modify CMP Relationship
160      */

161     public void testModifyRelationship() throws Exception JavaDoc {
162         String JavaDoc 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); //open visual editor
168
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         //save ejb-jar.xml editor
184
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         //check file on disc
189
//assertFile(FileUtil.toFile(ddFo),getGoldenFile("testModifyRelationship_ejb-jar.xml"), new File(getWorkDir(), "testModifyRelationship_ejb-jar.diff"));
190
assertFile("ejb-jar.xml");
191     }
192     
193     /*
194      * Remove CMP Relationship
195      */

196     public void testRemoveRelationship() throws Exception JavaDoc {
197         String JavaDoc 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); //open visual editor
203
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         //save ejb-jar.xml editor
213
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         //check file on disc
218
assertFile("ejb-jar.xml");
219     }
220     
221
222     
223    
224     
225 }
Popular Tags