1 19 20 package org.netbeans.test.j2ee.cmp; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import junit.framework.Test; 25 import junit.textui.TestRunner; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 30 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField; 31 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 32 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 33 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 34 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 35 import org.netbeans.modules.j2ee.ddloaders.multiview.CmpFieldHelper; 36 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject; 37 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityHelper; 38 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 39 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 40 import org.netbeans.test.j2ee.lib.Utils; 41 import org.netbeans.test.j2ee.refactoring.Utility; 42 import org.openide.filesystems.FileObject; 43 import org.openide.loaders.DataObject; 44 import org.openide.cookies.EditorCookie; 45 46 import javax.swing.*; 47 48 49 53 public class EjbCMPRefactorTest extends NbTestCase { 54 public static final String EJB_PROJECT_NAME = "TestCMP"; 55 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 56 57 private static Project project; 58 private static EjbJarMultiViewDataObject ddo; 59 private static Entity bean; 60 61 public EjbCMPRefactorTest(String testName) { 62 super(testName); 63 } 64 65 protected void setUp() throws Exception { 66 super.setUp(); 67 } 68 69 protected void tearDown() throws Exception { 70 } 71 72 public static Test suite() { 73 NbTestSuite suite = new NbTestSuite(EjbCMPRefactorTest.class); 74 return suite; 75 } 76 77 78 public static void main(java.lang.String [] args) { 79 TestRunner.run(suite()); 81 } 82 83 public void testOpenProject() throws Exception { 84 File projectDir = new File (EJB_PROJECT_PATH); 85 project = (Project)J2eeProjectSupport.openProject(projectDir); 86 87 EjbJarProject ejbJarProject = (EjbJarProject)project; 88 EjbJar ejb = ejbJarProject.getAPIEjbJar(); 89 FileObject ddFo = ejb.getDeploymentDescriptor(); 90 ddo = (EjbJarMultiViewDataObject)DataObject.find(ddFo); 91 EditorCookie editorCookie = (EditorCookie) ddo.getCookie(EditorCookie.class); 92 assertNotNull(editorCookie); 93 editorCookie.open(); 94 95 EnterpriseBeans beans = DDProvider.getDefault(). 97 getDDRoot(ddFo).getEnterpriseBeans(); 98 bean = (Entity)beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_NAME, "CustomerBean"); 99 } 100 101 104 public void testRenameCMPFromHelper() throws Exception { 105 CmpField cmpField = null; 106 107 CmpField[] cmpFieldsArray = bean.getCmpField(); 109 for(int i = 0; i < cmpFieldsArray.length; i++){ 110 if(cmpFieldsArray[i].getFieldName().equals("id")) 111 cmpField = cmpFieldsArray[i]; 112 } 113 EntityHelper entityHelper = new EntityHelper((EjbJarMultiViewDataObject)ddo, bean); 114 CmpFieldHelper cmpHelper = new CmpFieldHelper(entityHelper, cmpField); 115 cmpHelper.setFieldName("newId"); Utility.waitForAWTDispatchThread(); 117 assertTrue(Utility.saveDD(ddo)); 118 checkFiles(getName()); 119 } 120 121 124 public void testChangeCMPTypeFromHelper() throws Exception { 125 CmpField cmpField = null; 126 127 CmpField[] cmpFieldsArray = bean.getCmpField(); 129 for(int i = 0; i < cmpFieldsArray.length; i++){ 130 if(cmpFieldsArray[i].getFieldName().equals("newId")) 131 cmpField = cmpFieldsArray[i]; 132 } 133 134 EntityHelper entityHelper = new EntityHelper((EjbJarMultiViewDataObject)ddo, bean); 135 CmpFieldHelper cmpHelper = new CmpFieldHelper(entityHelper, cmpField); 136 cmpHelper.setType("java.lang.String"); Utility.waitForAWTDispatchThread(); 138 assertTrue(Utility.saveDD(ddo)); 139 checkFiles(getName()); 140 } 141 142 private void checkFiles(String methodName) throws IOException { 143 Utils utils = new Utils(this); 144 String ddNames[] = { "ejb-jar.xml", "sun-cmp-mappings.xml"}; 145 utils.assertFiles(new File (EJB_PROJECT_PATH + File.separator + "src" + File.separator + "conf"), ddNames, methodName+"_"); 146 147 String classNames[] = { "CustomerBean.java", "CustomerLocalBusiness.java"}; 148 utils.assertFiles(new File (EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "cmp"), classNames, methodName+"_"); 149 } 150 } 151 | Popular Tags |