1 19 20 package org.netbeans.modules.j2ee.persistence.wizard.fromdb; 21 22 import java.util.Arrays ; 23 import java.util.Collections ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.Map ; 27 import java.util.Set ; 28 import junit.framework.TestCase; 29 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.Table.DisabledReason; 30 31 35 public class TableClosureDisabledTest extends TestCase { 36 37 private TableProviderImpl provider; 38 private TableClosure closure; 39 40 public TableClosureDisabledTest(String testName) { 41 super(testName); 42 } 43 44 public void setUp() { 45 Map <String , Set <String >> tablesAndRefs = new HashMap <String , Set <String >>(); 46 Map <String , DisabledReason> disabledReasons = new HashMap <String , DisabledReason>(); 47 Set <String > empty = Collections.emptySet(); 48 49 tablesAndRefs.put("ROOM", empty); 50 tablesAndRefs.put("STUDENT", empty); 51 tablesAndRefs.put("TEACHER", empty); 52 tablesAndRefs.put("STUDENT_TEACHER", new HashSet (Arrays.asList(new String [] { "TEACHER", "STUDENT" }))); 53 tablesAndRefs.put("ZOO1", empty); 54 tablesAndRefs.put("ZOO2", empty); 55 tablesAndRefs.put("ZOO1_ZOO2", new HashSet (Arrays.asList(new String [] { "ZOO1", "ZOO2" }))); 56 57 disabledReasons.put("ROOM", new DisabledReason("Disabled", "Description")); 58 disabledReasons.put("STUDENT", new DisabledReason("Disabled", "Description")); 59 disabledReasons.put("ZOO1_ZOO2", new DisabledReason("Disabled", "Description")); 60 61 provider = new TableProviderImpl(tablesAndRefs, disabledReasons); 62 closure = new TableClosure(provider); 63 } 64 65 public void tearDown() { 66 closure = null; 67 } 68 69 public void testAddAllWithClosureEnabledDoesntAddDisabledTables() { 70 closure.addAllTables(); 71 72 73 assertTables(new String [] { "STUDENT_TEACHER", "TEACHER", "ZOO1", "ZOO2" }, closure.getWantedTables()); 74 assertTables(new String [] { "TEACHER" }, closure.getReferencedTables()); 75 assertTables(new String [] { "STUDENT_TEACHER", "TEACHER", "ZOO1", "ZOO2" }, closure.getSelectedTables()); 76 assertTables(new String [] { "ROOM", "STUDENT", "ZOO1_ZOO2" }, closure.getAvailableTables()); 77 } 78 79 public void testAddAllWithClosureDisabledDoesntAddDisabledTables() { 80 closure.setClosureEnabled(false); 81 closure.addAllTables(); 82 83 assertTables(new String [] { "STUDENT_TEACHER", "TEACHER", "ZOO1", "ZOO2" }, closure.getWantedTables()); 84 assertTables(new String [] { }, closure.getReferencedTables()); 85 assertTables(new String [] { "STUDENT_TEACHER", "TEACHER", "ZOO1", "ZOO2" }, closure.getSelectedTables()); 86 assertTables(new String [] { "ROOM", "STUDENT", "ZOO1_ZOO2" }, closure.getAvailableTables()); 87 } 88 89 public void testCannotAddDisabledReferencedTable() { 90 closure.addTables(Collections.singleton(provider.getTableByName("STUDENT_TEACHER"))); 91 92 assertTables(new String [] { "STUDENT_TEACHER" }, closure.getWantedTables()); 94 assertTables(new String [] { "TEACHER" }, closure.getReferencedTables()); 95 assertTables(new String [] { "STUDENT_TEACHER", "TEACHER" }, closure.getSelectedTables()); 96 assertTables(new String [] { "ROOM", "STUDENT", "ZOO1", "ZOO2", "ZOO1_ZOO2" }, closure.getAvailableTables()); 97 } 98 99 public void testCannotAddDisabledJoinTable() { 100 closure.addTables(Collections.singleton(provider.getTableByName("ZOO1"))); 101 closure.addTables(Collections.singleton(provider.getTableByName("ZOO2"))); 102 103 assertTables(new String [] { "ZOO1", "ZOO2" }, closure.getWantedTables()); 105 assertTables(new String [] { }, closure.getReferencedTables()); 106 assertTables(new String [] { "ZOO1", "ZOO2" }, closure.getSelectedTables()); 107 assertTables(new String [] { "ROOM", "STUDENT", "STUDENT_TEACHER", "TEACHER", "ZOO1_ZOO2" }, closure.getAvailableTables()); 108 } 109 110 private void assertTables(String [] expected, Set <Table> actual) { 111 assertEquals(expected.length, actual.size()); 112 for (String tableName : expected) { 113 assertNotNull(actual.contains(tableName)); 114 } 115 } 116 } 117 | Popular Tags |