KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > dao > EjbFacadeWizardIteratorTest


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.modules.j2ee.persistence.wizard.dao;
21
22 import com.sun.source.tree.ClassTree;
23 import com.sun.source.tree.Tree;
24 import com.sun.source.util.TreePath;
25 import com.sun.source.util.TreePathScanner;
26 import java.io.File JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.Set JavaDoc;
29 import javax.lang.model.element.AnnotationMirror;
30 import javax.lang.model.element.Element;
31 import javax.lang.model.element.TypeElement;
32 import org.netbeans.api.java.source.CancellableTask;
33 import org.netbeans.api.java.source.CompilationController;
34 import org.netbeans.api.java.source.CompilationInfo;
35 import org.netbeans.api.java.source.JavaSource;
36 import org.netbeans.api.java.source.JavaSource.Phase;
37 import org.netbeans.jackpot.test.TestUtilities;
38 import org.netbeans.modules.j2ee.persistence.sourcetestsupport.RepositoryImpl;
39 import org.netbeans.modules.j2ee.persistence.sourcetestsupport.SourceTestSupport;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileUtil;
42 import org.openide.filesystems.Repository;
43
44 /**
45  * Tests for <code>EjbFacadeWizardIterator</code>.
46  *
47  * @author Erno Mononen
48  */

49 public class EjbFacadeWizardIteratorTest extends SourceTestSupport {
50     
51     public EjbFacadeWizardIteratorTest(String JavaDoc testName) {
52         super(testName);
53     }
54     
55     
56     public void setUp() throws Exception JavaDoc{
57         super.setUp();
58     }
59     
60     
61     
62     public void testInstantiate() throws Exception JavaDoc {
63         fail("Test not implemented");
64     }
65     
66     public void testCreateInterface() throws Exception JavaDoc {
67         
68         final String JavaDoc name = "Test";
69         final String JavaDoc annotationType = "javax.ejb.Remote";
70         EjbFacadeWizardIterator wizardIterator = new EjbFacadeWizardIterator();
71         
72         String JavaDoc golden =
73                 "@" + annotationType + "\n" +
74                 "public interface " + name + " {\n" +
75                 "}\n";
76         FileObject result = wizardIterator.createInterface(name, annotationType, FileUtil.toFileObject(getWorkDir()));
77         assertEquals(golden, TestUtilities.copyFileToString(FileUtil.toFile(result)));
78     }
79     
80     public void testAddMethodToInterface() throws Exception JavaDoc {
81         File JavaDoc testFile = new File JavaDoc(getWorkDir(), "Test.java");
82         String JavaDoc originalContent =
83                 "package org.netbeans.test;\n\n" +
84                 "import java.util.*;\n\n" +
85                 "public interface Test {\n" +
86                 "}";
87         
88         TestUtilities.copyStringToFile(testFile, originalContent);
89         
90         String JavaDoc golden =
91                 "package org.netbeans.test;\n\n" +
92                 "import java.util.*;\n\n" +
93                 "public interface Test {\n\n" +
94                 "void testMethod(Object entity) ;\n" +
95                 "}";
96         
97         EjbFacadeWizardIterator wizardIterator = new EjbFacadeWizardIterator();
98         wizardIterator.addMethodToInterface("testMethod", "void", "entity", "Object", FileUtil.toFileObject(testFile));
99         
100         assertEquals(golden, TestUtilities.copyFileToString(testFile));
101         
102     }
103     
104     public void testGetUniqueClassName() throws IOException JavaDoc{
105         File JavaDoc testFile = new File JavaDoc(getWorkDir(), "Test.java");
106         
107         EjbFacadeWizardIterator wizardIterator = new EjbFacadeWizardIterator();
108         String JavaDoc result = wizardIterator.getUniqueClassName("Test", FileUtil.toFileObject(getWorkDir()));
109         System.out.println("Result: " + result);
110         assertEquals("Test2", result);
111         
112         File JavaDoc testFile2 = new File JavaDoc(getWorkDir(), "Test2.java");
113         wizardIterator.getUniqueClassName("Test", FileUtil.toFileObject(getWorkDir()));
114         assertEquals("Test3", result);
115     }
116     
117     public void testGenerate() throws Exception JavaDoc {
118         File JavaDoc testFile = new File JavaDoc(getWorkDir(), "Test.java");
119         String JavaDoc originalContent =
120                 "package org.netbeans.test;\n\n" +
121                 "import java.util.*;\n\n" +
122                 "@javax.persistence.Entity\n" +
123                 "public class Test {\n" +
124                 "}";
125         
126         TestUtilities.copyStringToFile(testFile, originalContent);
127         EjbFacadeWizardIterator wizardIterator = new EjbFacadeWizardIterator();
128         Set JavaDoc<FileObject> result =
129                 wizardIterator.generate(FileUtil.toFileObject(testFile), FileUtil.toFileObject(getWorkDir()), "Test", "org.netbeans.test", true, true);
130         
131         
132         assertEquals(3, result.size());
133         
134         for (FileObject each : result){
135             assertFile(FileUtil.toFile(each), getGoldenFile(each.getNameExt()));
136         }
137         
138         fail("Test is not complete");
139         
140     }
141     
142 }
143
Popular Tags