001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.test.j2ee.multiview;
043:
044: import java.io.File;
045: import junit.framework.AssertionFailedError;
046: import junit.framework.Test;
047: import junit.textui.TestRunner;
048: import org.netbeans.api.project.Project;
049: import org.netbeans.jellytools.JellyTestCase;
050: import org.netbeans.junit.NbTestSuite;
051: import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
052: import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
053: import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
054: import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
055: import org.netbeans.modules.j2ee.ddloaders.multiview.EjbImplementationAndInterfacesNode;
056: import org.netbeans.modules.j2ee.ddloaders.multiview.EjbImplementationAndInterfacesPanel;
057: import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject;
058: import org.netbeans.modules.j2ee.ddloaders.multiview.EntityOverviewNode;
059: import org.netbeans.modules.j2ee.ddloaders.multiview.EntityOverviewPanel;
060: import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject;
061: import org.netbeans.modules.xml.multiview.ui.SectionNodePanel;
062: import org.netbeans.test.j2ee.lib.J2eeProjectSupport;
063: import org.openide.cookies.EditCookie;
064: import org.openide.filesystems.FileObject;
065: import org.openide.filesystems.FileUtil;
066: import org.openide.loaders.DataObject;
067: import org.openide.nodes.Node;
068:
069: /**
070: *
071: * @author blaha
072: */
073: public class EBGeneralAndClassPanelTest extends JellyTestCase {
074:
075: private static Project project;
076: private static EjbJarMultiViewDataObject ddObj;
077: private static FileObject ddFo;
078: private static Entity bean;
079:
080: public EBGeneralAndClassPanelTest(String testName) {
081: super (testName);
082: }
083:
084: public static Test suite() {
085: NbTestSuite suite = new NbTestSuite();
086: // general panel
087: suite
088: .addTest(new EBGeneralAndClassPanelTest(
089: "testOpenProject"));
090: suite.addTest(new EBGeneralAndClassPanelTest(
091: "testEntityNodeName"));
092: suite.addTest(new EBGeneralAndClassPanelTest("testEntityName"));
093: suite.addTest(new EBGeneralAndClassPanelTest(
094: "testEntityPersistanceType"));
095: suite.addTest(new EBGeneralAndClassPanelTest(
096: "testEntityAbstractName"));
097: suite.addTest(new EBGeneralAndClassPanelTest(
098: "testEntityPKField"));
099: suite.addTest(new EBGeneralAndClassPanelTest(
100: "testEntityPKClass"));
101: suite.addTest(new EBGeneralAndClassPanelTest(
102: "testChangeReentrant"));
103: // need to be fixed
104: // suite.addTest(new EBGeneralAndClassPanelTest("testChangePKMultiple"));
105: // suite.addTest(new EBGeneralAndClassPanelTest("testChangePK"));
106: //class and interface panel
107: suite.addTest(new EBGeneralAndClassPanelTest(
108: "testBeanClassName"));
109: // need to be fixed
110: //suite.addTest(new EBGeneralAndClassPanelTest("testLocalInterfaceCheckBox"));
111: suite.addTest(new EBGeneralAndClassPanelTest(
112: "testLocalHomeIName"));
113: suite.addTest(new EBGeneralAndClassPanelTest("testLocalIName"));
114: suite.addTest(new EBGeneralAndClassPanelTest(
115: "testRemoteHomeIName"));
116: suite
117: .addTest(new EBGeneralAndClassPanelTest(
118: "testRemoteIName"));
119: // need to be fixed
120: //suite.addTest(new EBGeneralAndClassPanelTest("testRemoteInterfaceCheckBox"));
121: //suite.addTest(new EBGeneralAndClassPanelTest("testEnableRemoteI"));
122: //suite.addTest(new EBGeneralAndClassPanelTest("testDisableRemoteI"));
123: return suite;
124: }
125:
126: /** Use for execution inside IDE */
127: public static void main(java.lang.String[] args) {
128: // run only selected test case
129: TestRunner.run(suite());
130: }
131:
132: @Override
133: protected void setUp() throws Exception {
134: super .setUp();
135: System.out.println("############ " + getName()
136: + " ############");
137: }
138:
139: @Override
140: protected void tearDown() throws Exception {
141: }
142:
143: /*
144: * Method open project
145: *
146: */
147: public void testOpenProject() throws Exception {
148: File projectDir = new File(getDataDir(), "projects/"
149: + Utils.EJB_PROJECT_NAME);
150: project = (Project) J2eeProjectSupport.openProject(projectDir);
151: assertNotNull("Project is null.", project);
152: Thread.sleep(1000);
153:
154: EjbJarProject ejbJarProject = (EjbJarProject) project;
155: ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); // deployment descriptor
156: assertNotNull("ejb-jar.xml FileObject is null.", ddFo);
157:
158: ddObj = (EjbJarMultiViewDataObject) DataObject.find(ddFo); //MultiView Editor
159: assertNotNull("MultiViewDO is null.", ddObj);
160:
161: EditCookie edit = (EditCookie) ddObj
162: .getCookie(EditCookie.class);
163: edit.edit();
164: Thread.sleep(1000);
165:
166: // select CustomerBean
167: EnterpriseBeans beans = DDProvider.getDefault().getDDRoot(ddFo)
168: .getEnterpriseBeans();
169: bean = (Entity) beans.findBeanByName(EnterpriseBeans.ENTITY,
170: Ejb.EJB_NAME, "CustomerBean");
171:
172: ddObj.showElement(bean); //open visual editor
173: Utils.waitForAWTDispatchThread();
174: }
175:
176: // General panel
177:
178: public void testEntityNodeName() {
179: assertEquals("Entity node doesn't name CustomerEB",
180: "CustomerEB", Utils.getEntityNode(ddObj)
181: .getDisplayName());
182: }
183:
184: public void testEntityName() {
185: assertEquals(bean.getEjbName(), getEntityGeneralPanel()
186: .getEjbNameTextField().getText());
187: }
188:
189: public void testEntityPersistanceType() {
190: assertEquals("Container (CMP)", getEntityGeneralPanel()
191: .getPersistenceTypeTextField().getText());
192: }
193:
194: public void testEntityAbstractName() {
195: assertEquals(bean.getAbstractSchemaName(),
196: getEntityGeneralPanel()
197: .getAbstractSchemaNameTextField().getText());
198: }
199:
200: public void testEntityPKField() {
201: String pkField = (String) getEntityGeneralPanel()
202: .getPrimaryKeyFieldComboBox().getSelectedItem();
203: assertEquals(bean.getPrimkeyField(), pkField);
204: }
205:
206: public void testEntityPKClass() {
207: String className = (String) getEntityGeneralPanel()
208: .getPrimaryKeyClassComboBox().getSelectedItem();
209: assertEquals(bean.getPrimKeyClass(), className);
210: }
211:
212: public void testChangeReentrant() throws Exception {
213: assertEquals(false, getEntityGeneralPanel()
214: .getReentrantCheckBox().isSelected());
215: getEntityGeneralPanel().getReentrantCheckBox().doClick(); // change it
216: assertEquals(true, bean.isReentrant());
217: Thread.sleep(1000);
218: Utils utils = new Utils(this );
219: utils.checkInXML(ddObj, "<reentrant>true</reentrant>");
220: utils.save(ddObj);
221: assertFile(FileUtil.toFile(ddFo),
222: getGoldenFile("testChangeReentrant_ejb-jar.xml"),
223: new File(getWorkDir(), "testChangeReentrant.diff")); //check file on disc
224: }
225:
226: public void testChangePKMultiple() throws Exception {
227: assertNotNull("DDObject not found", ddObj);
228: getEntityGeneralPanel().getPrimaryKeyFieldComboBox()
229: .setSelectedIndex(0); //select multiply PK
230: getEntityGeneralPanel().getPrimaryKeyClassComboBox()
231: .setSelectedItem("cmp.CompoundClassTest");
232: assertEquals("cmp.CompoundClassTest", bean.getPrimKeyClass());
233: assertNull(bean.getPrimkeyField());
234: Utils utils = new Utils(this );
235: utils
236: .checkInXML(ddObj,
237: "<prim-key-class>cmp.CompoundClassTest</prim-key-class>");
238: utils.save(ddObj);
239: utils
240: .checkFiles("testChangePKMultiple",
241: new String[] { "ejb-jar.xml" }, new String[] {
242: "CustomerBean.java",
243: "CustomerLocalHome.java" });
244: }
245:
246: public void testChangePK() throws Exception {
247: assertNotNull("DDObject not found", ddObj);
248: getEntityGeneralPanel().getPrimaryKeyFieldComboBox()
249: .setSelectedItem("lastName");
250: assertEquals("java.lang.String", bean.getPrimKeyClass());
251: assertEquals("lastName", bean.getPrimkeyField());
252: Utils utils = new Utils(this );
253: utils.checkInXML(ddObj,
254: "<prim-key-class>java.lang.String</prim-key-class>");
255: utils.checkInXML(ddObj,
256: "<primkey-field>lastName</primkey-field>");
257: utils.save(ddObj);
258: utils
259: .checkFiles("testChangePK",
260: new String[] { "ejb-jar.xml" }, new String[] {
261: "CustomerBean.java",
262: "CustomerLocalHome.java" });
263: }
264:
265: // Interfaces and implementation classes panel
266:
267: public void testBeanClassName() {
268: assertEquals("cmp.CustomerBean", bean.getEjbClass());
269: //assertEquals("cmp.CustomerBean", getClassAndInterfacePanel().getBeanClassTextField().getText());
270: }
271:
272: public void testLocalHomeIName() {
273: assertEquals("cmp.CustomerLocalHome", bean.getLocalHome());
274: //assertEquals("cmp.CustomerLocalHome", getClassAndInterfacePanel().getLocalHomeTextField().getText());
275: }
276:
277: public void testLocalIName() {
278: assertEquals("cmp.CustomerLocal", bean.getLocal());
279: //assertEquals("cmp.CustomerLocal", getClassAndInterfacePanel().getLocalComponentTextField().getText());
280: }
281:
282: // Need to be fixed
283: public void testLocalInterfaceCheckBox() {
284: //assertEquals(true, getClassAndInterfacePanel().getLocalInterfaceCheckBox().isSelected());
285: }
286:
287: // bean doesn't have remote interface
288: public void testRemoteHomeIName() {
289: assertNull(bean.getHome());
290: assertEquals("", getClassAndInterfacePanel()
291: .getRemoteHomeTextField().getText());
292: }
293:
294: public void testRemoteIName() {
295: assertNull(bean.getRemote());
296: assertEquals("", getClassAndInterfacePanel()
297: .getRemoteComponentTextField().getText());
298: }
299:
300: // Need to be fixed
301: public void testRemoteInterfaceCheckBox() {
302: //assertEquals(false, getClassAndInterfacePanel().getRemoteInterfaceCheckBox().isSelected());
303: }
304:
305: // Need to be fixed
306: public void testEnableRemoteI() throws Exception {
307: ddObj.getEntityHelper(bean).addInterfaces(false); // add remote interface
308: // check DD API
309: Thread.sleep(1000);
310: assertEquals("cmp.CustomerRemote", bean.getRemote());
311: assertEquals("cmp.CustomerRemote", getClassAndInterfacePanel()
312: .getRemoteComponentTextField().getText());
313: assertEquals("cmp.CustomerRemoteHome", bean.getHome());
314: assertEquals("cmp.CustomerRemoteHome",
315: getClassAndInterfacePanel().getRemoteHomeTextField()
316: .getText());
317: //assertEquals(true, getClassAndInterfacePanel().getRemoteInterfaceCheckBox().isSelected());
318: // check XML view
319: Utils utils = new Utils(this );
320: utils.checkInXML(ddObj, "<remote>cmp.CustomerRemote</remote>");
321: utils.checkInXML(ddObj, "<home>cmp.CustomerRemoteHome</home>");
322: // check files
323: utils.save(ddObj);
324: utils.checkFiles("testEnableRemoteI",
325: new String[] { "ejb-jar.xml" }, new String[] {
326: "CustomerBean.java", "CustomerRemoteHome.java",
327: "CustomerRemote.java" });
328: }
329:
330: // Need to be fixed
331: public void testDisableRemoteI() throws Exception {
332: ddObj.getEntityHelper(bean).removeInterfaces(false);
333: Thread.sleep(1000);
334: assertNull(bean.getRemote());
335: assertEquals("", getClassAndInterfacePanel()
336: .getRemoteComponentTextField().getText().trim());
337: assertNull(bean.getHome());
338: assertEquals("", getClassAndInterfacePanel()
339: .getRemoteHomeTextField().getText().trim());
340: //assertEquals(false, getClassAndInterfacePanel().getRemoteInterfaceCheckBox().isSelected());
341: // check XML view
342: Utils utils = new Utils(this );
343: try {
344: utils.checkInXML(ddObj,
345: "<remote>cmp.CustomerRemote</remote>");
346: utils.checkInXML(ddObj,
347: "<home>cmp.CustomerRemoteHome</home>");
348: fail("Remote elements are still displayd in text view.");
349: } catch (AssertionFailedError ex) {
350: //it's OK
351: }
352: // check files
353: utils.save(ddObj);
354: utils.checkFiles("testDisableRemoteI",
355: new String[] { "ejb-jar.xml" },
356: new String[] { "CustomerBean.java" });
357: // check tha interface files are deleted
358: checkDeletedFiles("CustomerRemoteHome.java");
359: checkDeletedFiles("CustomerRemote.java");
360: checkDeletedFiles("CustomerRemoteBusiness.java");
361: }
362:
363: private void checkDeletedFiles(String fileName) {
364: if (new File(getDataDir(), "projects/" + Utils.EJB_PROJECT_NAME
365: + "src/java/cmp/" + fileName).exists()) {
366: fail(fileName + " isn't deleted.");
367: }
368: }
369:
370: private EntityOverviewPanel getEntityGeneralPanel() {
371: Node[] nnChild = Utils.getChildrenNodes(Utils
372: .getEntityNode(ddObj));
373: for (int k = 0; k < nnChild.length; k++) {
374: if (nnChild[k] instanceof EntityOverviewNode) {
375: SectionNodePanel overviewPanel = ((EntityOverviewNode) nnChild[k])
376: .getSectionNodePanel();
377: overviewPanel.open();
378: EntityOverviewPanel entityPanel = (EntityOverviewPanel) overviewPanel
379: .getInnerPanel();
380: return entityPanel;
381: }
382: }
383: return null;
384: }
385:
386: private EjbImplementationAndInterfacesPanel getClassAndInterfacePanel() {
387: assertNotNull(ddObj);
388: Node[] nnChild = Utils.getChildrenNodes(Utils
389: .getEntityNode(ddObj));
390: for (int k = 0; k < nnChild.length; k++) {
391: if (nnChild[k] instanceof EjbImplementationAndInterfacesNode) {
392: SectionNodePanel overviewPanel = ((EjbImplementationAndInterfacesNode) nnChild[k])
393: .getSectionNodePanel();
394: overviewPanel.open();
395: return (EjbImplementationAndInterfacesPanel) overviewPanel
396: .getInnerPanel();
397: }
398: }
399: return null;
400: }
401: }
|