1 19 20 package org.netbeans.modules.j2ee.persistence.entitygenerator; 21 22 import java.util.Arrays ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.modules.dbschema.SchemaElement; 28 import org.netbeans.modules.dbschema.SchemaElementUtil; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.URLMapper; 31 32 36 public class DbSchemaEjbGeneratorTest extends NbTestCase { 37 38 public DbSchemaEjbGeneratorTest(String testName) { 39 super(testName); 40 } 41 42 public void testIssue92031() throws Exception { 43 47 SchemaElement schema = SchemaElementUtil.forName(URLMapper.findFileObject(getClass().getResource("Issue92031.dbschema"))); 48 DbSchemaEjbGenerator generator = new DbSchemaEjbGenerator( 49 new GeneratedTablesImpl(new HashSet (Arrays.asList("PART1", "PART2"))), 50 schema); 51 52 EntityClass[] beans = generator.getBeans(); 53 EntityClass bean = getBeanByTableName(beans, "PART2"); 54 assertNotNull(getFieldByName(bean, "part1")); 55 RelationshipRole role = (RelationshipRole)bean.getRoles().iterator().next(); 56 assertEquals("part11", role.getFieldName()); 57 assertNotNull("Should have CMR mapping for field part11", bean.getCMPMapping().getCmrFieldMapping().get("part11")); 58 } 59 60 private static EntityMember getFieldByName(EntityClass bean, String fieldName) { 61 for (Iterator i = bean.getFields().iterator(); i.hasNext();) { 62 EntityMember member = ((EntityMember)i.next()); 63 if (fieldName.equals(member.getMemberName())) { 64 return member; 65 } 66 } 67 return null; 68 } 69 70 private static EntityClass getBeanByTableName(EntityClass[] beans, String tableName) { 71 for (int i = 0; i < beans.length; i++) { 72 if (tableName.equals(beans[i].getTableName())) { 73 return beans[i]; 74 } 75 } 76 return null; 77 } 78 79 private static final class GeneratedTablesImpl implements GeneratedTables { 80 81 private final Set <String > tableNames; 82 83 public GeneratedTablesImpl(Set <String > tableNames) { 84 this.tableNames = tableNames; 85 } 86 87 public Set <String > getTableNames() { 88 return tableNames; 89 } 90 91 public FileObject getRootFolder(String tableName) { 92 return null; 93 } 94 95 public String getPackageName(String tableName) { 96 return null; 97 } 98 99 public String getClassName(String tableName) { 100 return tableName; 101 } 102 } 103 } 104 | Popular Tags |