1 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 ; 27 import java.io.IOException ; 28 import java.util.Set ; 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 49 public class EjbFacadeWizardIteratorTest extends SourceTestSupport { 50 51 public EjbFacadeWizardIteratorTest(String testName) { 52 super(testName); 53 } 54 55 56 public void setUp() throws Exception { 57 super.setUp(); 58 } 59 60 61 62 public void testInstantiate() throws Exception { 63 fail("Test not implemented"); 64 } 65 66 public void testCreateInterface() throws Exception { 67 68 final String name = "Test"; 69 final String annotationType = "javax.ejb.Remote"; 70 EjbFacadeWizardIterator wizardIterator = new EjbFacadeWizardIterator(); 71 72 String 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 { 81 File testFile = new File (getWorkDir(), "Test.java"); 82 String 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 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 { 105 File testFile = new File (getWorkDir(), "Test.java"); 106 107 EjbFacadeWizardIterator wizardIterator = new EjbFacadeWizardIterator(); 108 String result = wizardIterator.getUniqueClassName("Test", FileUtil.toFileObject(getWorkDir())); 109 System.out.println("Result: " + result); 110 assertEquals("Test2", result); 111 112 File testFile2 = new File (getWorkDir(), "Test2.java"); 113 wizardIterator.getUniqueClassName("Test", FileUtil.toFileObject(getWorkDir())); 114 assertEquals("Test3", result); 115 } 116 117 public void testGenerate() throws Exception { 118 File testFile = new File (getWorkDir(), "Test.java"); 119 String 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 <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 |