1 19 20 package org.netbeans.modules.j2ee.ejbcore.api.codegeneration; 21 22 import java.io.IOException ; 23 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 25 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 26 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 27 import org.netbeans.modules.j2ee.ejbcore.test.TestBase; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 31 35 public class EntityGeneratorTest extends TestBase { 36 37 public EntityGeneratorTest(String testName) { 38 super(testName); 39 } 40 41 public void testGenerateJavaEE14() throws IOException { 42 TestModule testModule = ejb14(); 43 FileObject sourceRoot = testModule.getSources()[0]; 44 FileObject packageFileObject = sourceRoot.getFileObject("testGenerateJavaEE14"); 45 if (packageFileObject != null) { 46 packageFileObject.delete(); 47 } 48 packageFileObject = sourceRoot.createFolder("testGenerateJavaEE14"); 49 50 52 EntityGenerator entityGenerator = EntityGenerator.create("TestCmp", packageFileObject, true, true, true, "java.lang.Long"); 53 entityGenerator.generate(); 54 EjbJar ejbJar = DDProvider.getDefault().getDDRoot(testModule.getDeploymentDescriptor()); 55 EnterpriseBeans enterpriseBeans = ejbJar.getEnterpriseBeans(); 56 Entity entity = (Entity) enterpriseBeans.findBeanByName(EnterpriseBeans.ENTITY, Entity.EJB_NAME, "TestCmpBean"); 57 58 assertNotNull(entity); 59 assertEquals("TestCmpEB", entity.getDefaultDisplayName()); 60 assertEquals("TestCmpBean", entity.getEjbName()); 61 assertEquals("testGenerateJavaEE14.TestCmpRemoteHome", entity.getHome()); 62 assertEquals("testGenerateJavaEE14.TestCmpRemote", entity.getRemote()); 63 assertEquals("testGenerateJavaEE14.TestCmpLocalHome", entity.getLocalHome()); 64 assertEquals("testGenerateJavaEE14.TestCmpLocal", entity.getLocal()); 65 assertEquals("testGenerateJavaEE14.TestCmpBean", entity.getEjbClass()); 66 assertEquals("Container", entity.getPersistenceType()); 67 assertEquals("java.lang.Long", entity.getPrimKeyClass()); 68 assertFalse(entity.isReentrant()); 69 assertEquals("TestCmp", entity.getAbstractSchemaName()); 70 assertEquals(1, entity.getCmpField().length); 71 assertEquals("key", entity.getCmpField()[0].getFieldName()); 72 assertEquals("key", entity.getPrimkeyField()); 73 assertFile( 74 FileUtil.toFile(packageFileObject.getFileObject("TestCmpBean.java")), 75 getGoldenFile("testGenerateJavaEE14/TestCmpBean.java"), 76 FileUtil.toFile(packageFileObject) 77 ); 78 assertFile( 79 FileUtil.toFile(packageFileObject.getFileObject("TestCmpLocal.java")), 80 getGoldenFile("testGenerateJavaEE14/TestCmpLocal.java"), 81 FileUtil.toFile(packageFileObject) 82 ); 83 assertFile( 84 FileUtil.toFile(packageFileObject.getFileObject("TestCmpLocalHome.java")), 85 getGoldenFile("testGenerateJavaEE14/TestCmpLocalHome.java"), 86 FileUtil.toFile(packageFileObject) 87 ); 88 assertFile( 89 FileUtil.toFile(packageFileObject.getFileObject("TestCmpRemote.java")), 90 getGoldenFile("testGenerateJavaEE14/TestCmpRemote.java"), 91 FileUtil.toFile(packageFileObject) 92 ); 93 assertFile( 94 FileUtil.toFile(packageFileObject.getFileObject("TestCmpRemoteHome.java")), 95 getGoldenFile("testGenerateJavaEE14/TestCmpRemoteHome.java"), 96 FileUtil.toFile(packageFileObject) 97 ); 98 99 101 entityGenerator = EntityGenerator.create("TestBmp", packageFileObject, false, true, false, "java.lang.Long"); 102 entityGenerator.generate(); 103 entity = (Entity) enterpriseBeans.findBeanByName(EnterpriseBeans.ENTITY, Entity.EJB_NAME, "TestBmpBean"); 104 105 assertNotNull(entity); 106 assertEquals("TestBmpEB", entity.getDefaultDisplayName()); 107 assertEquals("TestBmpBean", entity.getEjbName()); 108 assertNull(entity.getHome()); 109 assertNull(entity.getRemote()); 110 assertEquals("testGenerateJavaEE14.TestBmpLocalHome", entity.getLocalHome()); 111 assertEquals("testGenerateJavaEE14.TestBmpLocal", entity.getLocal()); 112 assertEquals("testGenerateJavaEE14.TestBmpBean", entity.getEjbClass()); 113 assertEquals("Bean", entity.getPersistenceType()); 114 assertEquals("java.lang.Long", entity.getPrimKeyClass()); 115 assertFalse(entity.isReentrant()); 116 assertFile( 117 FileUtil.toFile(packageFileObject.getFileObject("TestBmpBean.java")), 118 getGoldenFile("testGenerateJavaEE14/TestBmpBean.java"), 119 FileUtil.toFile(packageFileObject) 120 ); 121 assertFile( 122 FileUtil.toFile(packageFileObject.getFileObject("TestBmpLocal.java")), 123 getGoldenFile("testGenerateJavaEE14/TestBmpLocal.java"), 124 FileUtil.toFile(packageFileObject) 125 ); 126 assertFile( 127 FileUtil.toFile(packageFileObject.getFileObject("TestBmpLocalHome.java")), 128 getGoldenFile("testGenerateJavaEE14/TestBmpLocalHome.java"), 129 FileUtil.toFile(packageFileObject) 130 ); 131 assertNull(packageFileObject.getFileObject("TestBmpRemote.java")); 132 assertNull(packageFileObject.getFileObject("TestBmpRemoteHome.java")); 133 } 134 135 } 136 | Popular Tags |