001 package nl.cwi.sen1.visplugin.table.model; 002 003 import junit.framework.TestCase; 004 import nl.cwi.sen1.relationstores.Factory; 005 import nl.cwi.sen1.relationstores.types.RElem; 006 import nl.cwi.sen1.relationstores.types.RElemElements; 007 import nl.cwi.sen1.relationstores.types.RTuple; 008 import nl.cwi.sen1.visplugin.VisualizationFactorySingleton; 009 010 /** 011 * JUnit Testcase used to test the TableVisualizationWindow class. 012 * 013 * @author Antoine Savelkoul 014 * @date 09-03-2007 015 */ 016 public class SortableTableModelTest extends TestCase { 017 018 private SortableTableModel m_model; 019 private Factory m_factory; 020 private RTuple m_testRTuple; 021 022 /** 023 * Set-up code for the tests. 024 * 025 * @author Antoine Savelkoul 026 * @author Anton Gerdessen 027 * @author Arend van Beelen 028 * @date 13-03-2007 029 */ 030 public void setUp() { 031 m_model = new SortableTableModel(); 032 m_factory = VisualizationFactorySingleton.getFactoryInstance(); 033 034 String relStrStr = "rtuple(\"STRING_TABLE\"," + "relation([str,str])," 035 + "set([" 036 + "tuple([str(\"Row 1\"),str(\"abc\")])," 037 + "tuple([str(\"Row 2\"),str(\"bcd\")])," 038 + "tuple([str(\"Row 3\"),str(\"abd\")])" 039 + "]))"; 040 m_testRTuple = m_factory.RTupleFromString(relStrStr); 041 } 042 043 /** 044 * Tests the getColumnCount() method to see if it's initialized properly by 045 * setRTupleData(). 046 * 047 * @author Anton Gerdessen 048 * @author Arend van Beelen 049 * @date 13-03-2007 050 */ 051 public void testGetColumnCount() { 052 m_model.setRTupleData(m_testRTuple); 053 assertEquals(2, m_model.getColumnCount()); 054 } 055 056 /** 057 * Tests the getColumnName() method to see if it's initialized properly by 058 * setRTupleData(). 059 * 060 * @author Anton Gerdessen 061 * @author Arend van Beelen 062 * @date 13-03-2007 063 */ 064 public void testGetColumnName() { 065 m_model.setRTupleData(m_testRTuple); 066 assertEquals("str [0]", m_model.getColumnName(0)); 067 } 068 069 /** 070 * Tests the getValueAt() method. 071 * 072 * @author Antoine Savelkoul 073 * @author Anton Gerdessen 074 * @author Arend van Beelen 075 * @date 09-03-2007 076 */ 077 public void testGetValueAt() { 078 m_model.setRTupleData(m_testRTuple); 079 assertEquals("abd", m_model.getValueAt(2, 1)); 080 } 081 082 /** 083 * Tests the getRTupleVariable() method. 084 * 085 * @author Anton Gerdessen 086 * @author Arend van Beelen 087 * @date 13-03-2007 088 */ 089 public void testGetRTupleVariable() { 090 m_model.setRTupleData(m_testRTuple); 091 assertEquals(m_testRTuple.getVariable(), m_model.getRTupleVariable()); 092 } 093 094 /** 095 * Tests the getRTupleRType() method. 096 * 097 * @author Anton Gerdessen 098 * @author Arend van Beelen 099 * @date 13-03-2007 100 */ 101 public void testGetRTupleRType() { 102 m_model.setRTupleData(m_testRTuple); 103 assertEquals(m_testRTuple.getRtype(), m_model.getRTupleRType()); 104 } 105 106 /** 107 * Tests the getRElemForRow() method. 108 * 109 * @author Anton Gerdessen 110 * @author Arend van Beelen 111 * @date 13-03-2007 112 */ 113 public void testGetRElemForRow() { 114 m_model.setRTupleData(m_testRTuple); 115 RElem value = m_testRTuple.getValue(); 116 RElemElements elements = value.getElements(); 117 assertEquals(elements.getRElemAt(2), m_model.getRElemForRow(2)); 118 } 119 120 /** 121 * Tests the getRElemForRow() method after sorting on second column. 122 * 123 * @author Anton Gerdessen 124 * @author Arend van Beelen 125 * @date 13-03-2007 126 */ 127 public void testGetRElemForRowWithSorting() { 128 m_model.setRTupleData(m_testRTuple); 129 m_model.sortByColumn(1, true); 130 RElem value = m_testRTuple.getValue(); 131 RElemElements elements = value.getElements(); 132 assertEquals(elements.getRElemAt(2), m_model.getRElemForRow(1)); 133 } 134 }