1 19 20 package org.netbeans.test.j2ee.cmp; 21 22 import java.io.File ; 23 import java.io.FilenameFilter ; 24 import java.util.Set ; 25 import javax.swing.JComponent ; 26 import org.netbeans.api.progress.ProgressHandle; 27 import org.netbeans.api.progress.ProgressHandleFactory; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ProjectUtils; 30 import org.netbeans.api.project.SourceGroup; 31 import junit.framework.Test; 32 import junit.textui.TestRunner; 33 import org.netbeans.jmi.javamodel.JavaClass; 34 import org.netbeans.junit.NbTestSuite; 35 import org.netbeans.modules.dbschema.SchemaElement; 36 import org.netbeans.modules.dbschema.SchemaElementUtil; 37 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 38 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject; 39 import org.netbeans.modules.j2ee.earproject.ui.LogicalViewProvider; 40 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 41 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.DBSchemaTableProvider; 42 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.JavaPersistenceGenerator; 43 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.PersistenceGenerator; 44 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.ProgressPanel; 45 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.SelectedTables; 46 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.TableClosure; 47 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.TableProvider; 48 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 49 import org.netbeans.test.j2ee.multiview.Utils; 50 import org.netbeans.test.j2ee.multiview.DDTestCase; 51 import org.openide.actions.SaveAllAction; 52 import org.openide.cookies.EditCookie; 53 import org.openide.filesystems.FileObject; 54 import org.openide.loaders.DataObject; 55 import org.openide.nodes.Node; 56 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPHelper; 57 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard; 58 59 63 public class GenerateEntityClassesTest extends DDTestCase { 64 public static final String EJB_PROJECT_NAME = "TestGenerateEntity"; 65 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 66 67 68 69 70 public GenerateEntityClassesTest(String testName) { 71 super(testName); 72 } 73 74 75 76 77 protected void setUp() throws Exception { 78 super.setUp(); 79 System.out.println("######## "+getName()+" #######"); 80 } 81 82 protected void tearDown() throws Exception { 83 } 84 85 public static Test suite() { 86 NbTestSuite suite = new NbTestSuite(); 87 suite.addTest(new GenerateEntityClassesTest("testOpenProject")); 88 suite.addTest(new GenerateEntityClassesTest("testGenerateBeans")); 89 90 return suite; 91 } 92 93 94 public static void main(java.lang.String [] args) { 95 TestRunner.run(suite()); 97 } 98 99 103 public void testOpenProject() throws Exception { 104 File projectDir = new File (EJB_PROJECT_PATH); 105 project = (Project)J2eeProjectSupport.openProject(projectDir); 106 assertNotNull("Project is null.", project); 107 Thread.sleep(1000); 108 123 } 124 125 public void testGenerateBeans() throws Exception { 126 ProgressPanel progressPanel; 127 Thread.sleep(4000); 128 PersistenceGenerator generator = new JavaPersistenceGenerator(); 129 FileObject config=project.getProjectDirectory().getFileObject("/src/conf/"); 130 131 RelatedCMPHelper relatedCMPHelper=new RelatedCMPHelper(project, config, generator); 132 FileObject schemaFo=project.getProjectDirectory().getFileObject("/src/conf/testSchema.dbschema"); 133 SchemaElement se=SchemaElementUtil.forName(schemaFo); 134 135 relatedCMPHelper.setTableSource(se, schemaFo); 136 relatedCMPHelper.setPackageName("test"); 137 138 TableProvider tableProvider = new DBSchemaTableProvider(se, generator); 139 TableClosure tableClosure = new TableClosure(tableProvider); 140 tableClosure.setClosureEnabled(false); 141 tableClosure.addAllTables(); 142 Set selected = tableClosure.getSelectedTables(); 143 System.err.println("*** selected "+selected.size()); 144 145 Set available = tableClosure.getAvailableTables(); 146 System.err.println("*** available "+available.size()); 147 relatedCMPHelper.setTableClosure(tableClosure); 148 149 SourceGroup sourceGroup = ProjectUtils.getSources(project).getSourceGroups("java")[0]; 150 relatedCMPHelper.setLocation(sourceGroup); 151 SelectedTables selectedTables=new SelectedTables(generator, tableClosure, sourceGroup, "test"); 152 relatedCMPHelper.setSelectedTables(selectedTables); 153 154 ProgressHandle handle = ProgressHandleFactory.createHandle("test"); 155 progressPanel = new ProgressPanel(); 156 handle.start(); 157 relatedCMPHelper.buildBeans(); 158 generator.generateBeans(progressPanel, relatedCMPHelper, schemaFo, handle, false); 159 Set created = generator.createdObjects(); 160 System.err.println("*** created size: "+created.size()); 161 162 163 handle.finish(); 164 Thread.sleep(4000); 165 166 SaveAllAction a = (SaveAllAction)SaveAllAction.get(SaveAllAction.class); 168 a.performAction(); 169 170 171 org.netbeans.test.j2ee.lib.Utils utils = new org.netbeans.test.j2ee.lib.Utils(this); 172 173 File dbBeansDir = new File (EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "test"); 174 String beanFiles[] = dbBeansDir.list(new FilenameFilter () { 175 public boolean accept(File dir, String name) { 176 return name.endsWith(".java"); 177 } 178 }); 179 utils.assertFiles(dbBeansDir, beanFiles, getName()+"_"); 182 183 } 184 185 protected Node getEjbNode(JavaClass beanClass, String ejbName) { 186 Project[] allProjects = org.netbeans.modules.j2ee.ejbcore.Utils.getCallableEjbProjects(project); 187 for (int i = 0; i < allProjects.length; i++) { 188 LogicalViewProvider lvp = 189 (LogicalViewProvider) allProjects[i].getLookup().lookup(LogicalViewProvider.class); 190 Node projectView = lvp.createLogicalView(); 191 Node [] nodes = projectView.getChildren().getNodes(); 192 for (int j = 0; j < nodes.length; j++) { 193 if ("EJBS".equals(nodes[j].getName())) { 194 Node [] ejbs = nodes[j].getChildren().getNodes(); 195 for (int k = 0; k < ejbs.length; k++) { 196 System.out.println("*** "+ejbs[k].getName()); 197 if (ejbName.equals(ejbs[k].getName())) return ejbs[k]; 198 } 199 } 200 } 201 } 202 return null; 203 } 204 205 206 207 } 208 | Popular Tags |