KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > GenerateDTOTest


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;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import junit.textui.TestRunner;
25 import org.netbeans.jellytools.Bundle;
26 import org.netbeans.jellytools.EditorOperator;
27 import org.netbeans.jellytools.EditorWindowOperator;
28 import org.netbeans.jellytools.JellyTestCase;
29 import org.netbeans.jellytools.NbDialogOperator;
30 import org.netbeans.jellytools.ProjectsTabOperator;
31 import org.netbeans.jellytools.nodes.Node;
32 import org.netbeans.jemmy.TimeoutExpiredException;
33 import org.openide.filesystems.FileStateInvalidException;
34
35 /**
36  *
37  * @author blaha
38  */

39 public class GenerateDTOTest extends JellyTestCase {
40     private static String JavaDoc beanName = "TestingEntity";
41     private static String JavaDoc dtoName = beanName + "DTO";
42     
43     //
44
public static File JavaDoc getFile(String JavaDoc fileName) {
45         String JavaDoc result = EJBValidation.EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator
46                 + "test" + File.separator + fileName;
47         return new File JavaDoc(result);
48     }
49     
50     /** Creates a new instance of GenerateDTOTest */
51     public GenerateDTOTest(String JavaDoc name) {
52         super(name);
53     }
54     
55     /** Use for execution inside IDE */
56     public static void main(java.lang.String JavaDoc[] args) {
57         // run only selected test case
58
TestRunner.run(new GenerateDTOTest("testGenerateDTO"));
59         TestRunner.run(new GenerateDTOTest("testDeleteDTO"));
60     }
61     
62     public void testGenerateDTO() throws FileStateInvalidException, IOException JavaDoc {
63         Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.EJB_PROJECT_NAME),
64                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
65                 +"|"+beanName);
66         node.performPopupAction(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_GenerateDTOAction"));
67         deleteDateAndAuthor(); // delete date and author line
68

69         assertFile(getFile(dtoName + ".java"), getGoldenFile(), new File JavaDoc(getWorkDir(),"testGenerateDTO.diff"));
70     }
71     
72     
73     public void testDeleteDTO(){
74         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
75         Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.EJB_PROJECT_NAME),
76                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjarproject.Bundle", "NAME_src.dir") +
77                 "|" + "test" + "|" + dtoName + ".java");
78         node.performPopupAction(Bundle.getStringTrimmed("org.openide.actions.Bundle", "Delete"));
79         new NbDialogOperator(Bundle.getStringTrimmed("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle")).yes();
80         try{ // check node
81
node = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.EJB_PROJECT_PATH),
82                     Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjarproject.Bundle", "NAME_src.dir") +
83                     "|" + "test" + "|" + dtoName + ".java");
84             fail("Node wasn't deleted.");
85         }catch(TimeoutExpiredException ex){
86             // It's OK.
87
}
88         assertFalse("File " + dtoName + ".java isn't deleted.", getFile(dtoName + ".java").exists()); //check file
89
}
90     
91     private void deleteDateAndAuthor(){
92         final EditorOperator editor = new EditorWindowOperator().getEditor(dtoName);
93         new org.netbeans.jemmy.EventTool().waitNoEvent(3000);
94         editor.deleteLine(11); //author
95
editor.deleteLine(10); //date
96
editor.save();
97         editor.close();
98     }
99     
100 }
101
Popular Tags