001: package com.canoo.ant.table;
002:
003: import com.canoo.ant.filter.AllEqualsFilter;
004: import com.canoo.ant.filter.AllFilter;
005: import com.canoo.ant.filter.FirstEqualsFilter;
006: import com.canoo.ant.table.test.InMemoryPropertyTable;
007: import junit.framework.TestCase;
008:
009: import java.io.File;
010: import java.util.List;
011: import java.util.Properties;
012:
013: public class PropertyTableTest extends TestCase {
014: private InMemoryPropertyTable fTable;
015: private static final String TABLE = "mytable";
016: private static final String FOREIGN_TABLE = "myForeignTable";
017:
018: public PropertyTableTest(String name) {
019: super (name);
020: }
021:
022: protected void setUp() throws Exception {
023: fTable = new InMemoryPropertyTable();
024: InMemoryPropertyTable.reset();
025: fTable.setTable(TABLE);
026: fTable.setContainer(new File("mycontainer"));
027: }
028:
029: public void testEmptyNoExpansion() {
030: assertEquals(0, fTable.getRawTable().size());
031: assertTrue("All Filter is default",
032: fTable.getFilter() instanceof AllFilter);
033: assertEquals(0, fTable.getPropertiesList(null, null).size());
034: }
035:
036: public void testOneEntryNoExpansion() {
037: InMemoryPropertyTable.addTo(TABLE, new String[] { "myname" });
038: InMemoryPropertyTable.addTo(TABLE, new String[] { "myvalue" });
039:
040: List rawTable = fTable.getRawTable();
041: List propertiesList = fTable.getPropertiesList(null, null);
042: // list is new, but entries are equal, nothing is said about identity of entries
043: assertCopy(rawTable, propertiesList);
044: }
045:
046: public void testSimplePrefixNoExpansion() {
047: InMemoryPropertyTable.addTo(TABLE, new String[] { "myname" });
048: InMemoryPropertyTable.addTo(TABLE, new String[] { "myvalue" });
049: List propertiesList = fTable.getPropertiesList(null, "prefix");
050: assertEquals("myvalue", ((Properties) propertiesList.get(0))
051: .getProperty("prefix.myname"));
052: }
053:
054: public void testSimpleFilter() {
055: InMemoryPropertyTable.addTo(TABLE, new String[] { "myname" });
056: InMemoryPropertyTable.addTo(TABLE, new String[] { "myvalue" });
057: InMemoryPropertyTable.addTo(TABLE,
058: new String[] { "othervalue" });
059: fTable.setFilter(new FirstEqualsFilter("myname"));
060: List rawTable = fTable.getRawTable();
061: List propertiesList = fTable.getPropertiesList("othervalue",
062: null);
063: assertEquals(2, rawTable.size());
064: assertEquals(1, propertiesList.size());
065: assertEquals(rawTable.get(1), propertiesList.get(0));
066: }
067:
068: public void testColumnExpansion() {
069: InMemoryPropertyTable.addTo(TABLE, new String[] { "myname" });
070: InMemoryPropertyTable.addTo(TABLE, new String[] { "myvalue" });
071:
072: InMemoryPropertyTable.addTo(FOREIGN_TABLE, new String[] {
073: "myForeignName", "othername" });
074: InMemoryPropertyTable.addTo(FOREIGN_TABLE, new String[] {
075: "myvalue", "othervalue" });
076:
077: InMemoryPropertyTable.addTo(APropertyTable.KEY_JOIN,
078: new String[] { TableFactory.KEY_TABLE,
079: TableFactory.KEY_NAME,
080: TableFactory.KEY_FOREIGN_TABLE,
081: TableFactory.KEY_FOREIGN_NAME });
082: InMemoryPropertyTable.addTo(APropertyTable.KEY_JOIN,
083: new String[] { TABLE, "myname", FOREIGN_TABLE,
084: "myForeignName" });
085:
086: List rawTable = fTable.getRawTable();
087: List propertiesList = fTable.getPropertiesList(null, null);
088: assertEquals(1, rawTable.size());
089: assertEquals(1, propertiesList.size());
090: Properties prop = (Properties) propertiesList.get(0);
091: assertEquals("1 :" + prop, "myvalue", prop
092: .getProperty("myname"));
093: assertEquals("2 :" + prop, "myvalue", prop
094: .getProperty("myForeignName"));
095: assertEquals("3 :" + prop, "othervalue", prop
096: .getProperty("othername"));
097: }
098:
099: public void testEndlessRecursion() {
100: InMemoryPropertyTable.addTo(TABLE, new String[] { "myname" });
101: InMemoryPropertyTable.addTo(TABLE, new String[] { "myvalue" });
102:
103: InMemoryPropertyTable.addTo(APropertyTable.KEY_JOIN,
104: new String[] { TableFactory.KEY_TABLE,
105: TableFactory.KEY_NAME,
106: TableFactory.KEY_FOREIGN_TABLE,
107: TableFactory.KEY_FOREIGN_NAME });
108: InMemoryPropertyTable.addTo(APropertyTable.KEY_JOIN,
109: new String[] { TABLE, "myname", TABLE, "myname" });
110:
111: List rawTable = fTable.getRawTable();
112: List propertiesList = fTable.getPropertiesList(null, null);
113: assertEquals(1, rawTable.size());
114: assertEquals(1, propertiesList.size());
115: Properties prop = (Properties) propertiesList.get(0);
116: assertEquals("1 :" + prop, "myvalue", prop
117: .getProperty("myname"));
118: }
119:
120: public void testTwoDimensionalExpansion() {
121: InMemoryPropertyTable.addTo(TABLE, new String[] { "myname" });
122: InMemoryPropertyTable.addTo(TABLE, new String[] { "myvalue" });
123:
124: InMemoryPropertyTable.addTo(FOREIGN_TABLE, new String[] {
125: "myForeignName", "othername" });
126: InMemoryPropertyTable.addTo(FOREIGN_TABLE, new String[] {
127: "myvalue", "othervalue" });
128: InMemoryPropertyTable.addTo(FOREIGN_TABLE, new String[] {
129: "myvalue", "thirdvalue" });
130:
131: InMemoryPropertyTable.addTo(APropertyTable.KEY_JOIN,
132: new String[] { TableFactory.KEY_TABLE,
133: TableFactory.KEY_NAME,
134: TableFactory.KEY_FOREIGN_TABLE,
135: TableFactory.KEY_FOREIGN_NAME,
136: TableFactory.KEY_FILTER_CLASS, });
137: InMemoryPropertyTable.addTo(APropertyTable.KEY_JOIN,
138: new String[] { TABLE, "myname", FOREIGN_TABLE,
139: "myForeignName",
140: AllEqualsFilter.class.getName() });
141:
142: List rawTable = fTable.getRawTable();
143: List propertiesList = fTable.getPropertiesList(null, null);
144: assertEquals(1, rawTable.size());
145: assertEquals(2, propertiesList.size());
146:
147: Properties prop = (Properties) propertiesList.get(0);
148: assertEquals("myvalue", prop.getProperty("myname"));
149: assertEquals("myvalue", prop.getProperty("myForeignName"));
150: assertEquals("othervalue", prop.getProperty("othername"));
151:
152: prop = (Properties) propertiesList.get(1);
153: assertEquals("myvalue", prop.getProperty("myname"));
154: assertEquals("myvalue", prop.getProperty("myForeignName"));
155: assertEquals("thirdvalue", prop.getProperty("othername"));
156:
157: }
158:
159: private void assertCopy(List rawTable, List propertiesList) {
160: assertNotSame(rawTable, propertiesList);
161: assertEquals(rawTable, propertiesList);
162: }
163:
164: }
|