001 package nl.cwi.sen1.visbase.factbrowser.data; 002 003 import junit.framework.TestCase; 004 005 /** 006 * This is the class for JUnit testing of the FactBrowser system. It tests the 007 * in memory data structure and also tests the creation of the visualisation 008 * component; 009 * 010 * @author Renze de Vries 011 * @date 14-02-2007 012 * 013 */ 014 public class FactBrowserDataTest extends TestCase { 015 private FactBrowserDataManager dataManager; 016 017 public FactBrowserDataTest() { 018 dataManager = FactBrowserDataManager.getInstance(); 019 } 020 021 /** 022 * For the FactBrowser testing it is very important to test if the 023 * datamanger which manages the in memory data tree is present and will 024 * initialize. 025 * 026 * @author Renze de Vries 027 * @date 14-02-2007 028 */ 029 public void testDataManager() { 030 assertNotNull("DataManager is NULL", dataManager); 031 } 032 033 /** 034 * This method is here pure for testing of the RStore creation 035 * 036 * @author Renze de Vries 037 * @date 14-02-2007 038 */ 039 public void testCreateRStore() { 040 RStore rstoreNode1 = new RStore("Rstore1", 1); 041 042 assertNotNull("The created RStoreNode1 is NULL", rstoreNode1); 043 assertEquals("The RStoreId should be 1", 1, rstoreNode1.getRstoreId()); 044 assertEquals("The RStoreName should be Rstore1", "Rstore1", rstoreNode1 045 .toString()); 046 assertEquals("The FactNode ArrayList should be empty", 0, rstoreNode1 047 .getFactNodes().size()); 048 049 RStore rstoreNode2 = new RStore("Rstore2", 2); 050 assertNotNull("This Rstore should not be null", rstoreNode2); 051 } 052 053 /** 054 * This method will test if the RStoreFactType registration is working and 055 * it will test for different type of scenarios from nullpointers to string 056 * equality and testing the size of the initial plugin container 057 * 058 * @author Renze de Vries 059 * @date 14-02-2007 060 */ 061 public void testFactTypes() { 062 RStoreFactType factType1 = dataManager.addFactType("<str, str>"); 063 RStoreFactType factType2 = dataManager.addFactType("<str, bool>"); 064 RStoreFactType factType3 = dataManager.addFactType("<str, str, int>"); 065 RStoreFactType factType4 = dataManager.addFactType("<int, int>"); 066 067 assertNotNull("The created FactType is NULL", factType1); 068 assertEquals("The FactType should be <str, str>", "<str, str>", 069 factType1.getFactType()); 070 assertEquals("The number of visualisations should be 0", 0, factType1 071 .getVisualisationPlugins().size()); 072 073 assertNotSame("FactTypes should be different object instants", 074 factType1, factType4); 075 076 RStoreFactType factType5 = dataManager.addFactType("<str, str>"); 077 assertEquals( 078 "The factTypes <str, str> and <str, str> should provide the same object", 079 factType1, factType5); 080 assertNotSame( 081 "The factTypes <str, str, int> should give a different object than <str, str>", 082 factType1, factType3); 083 assertSame( 084 "The factType <str, bool> should be the same as <str, bool>", 085 factType2, dataManager.addFactType("<str, bool>")); 086 087 RStoreFactType emptyFactType = new RStoreFactType(); 088 assertNotNull("This instance should not be null", emptyFactType); 089 } 090 091 /** 092 * This method tests the creation of a fact node and the coupling of this 093 * fact node to the RStore parent. It will test the basic properties of the 094 * FactNode and if the RStore registers the FactNode properly. 095 * 096 * @author Renze de Vries 097 * @date 14-02-2007 098 */ 099 public void testFactNode() { 100 RStore rstoreNode1 = new RStore("Rstore1", 1); 101 102 RStoreFactType rstoreFactType = dataManager.addFactType("<str, str>"); 103 104 RStoreFact factNode1 = new RStoreFact("Fact1", 1, rstoreFactType); 105 assertNotNull("The created Fact1 is NULL", factNode1); 106 assertEquals("The FactId should be 1", 1, factNode1.getFactId()); 107 assertEquals("The FactName should be Fact1(<str, str>)", 108 "Fact1(<str, str>)", factNode1.toString()); 109 110 rstoreNode1.addFactNode(factNode1); 111 112 assertEquals("The FactNode ArrayList should be 1", 1, rstoreNode1 113 .getFactNodes().size()); 114 115 assertEquals("These factTypes should be the same instance", 116 rstoreFactType, factNode1.getFactType()); 117 } 118 119 /** 120 * This tests the constructor checking if the factname and factype are 121 * correctly initialized 122 * 123 * @author Raymond Bergen 124 * @date 21-02-2007 125 */ 126 public void testFactNodeConstructor() { 127 RStoreFact factnode = new RStoreFact(); 128 assertEquals("The factname should be empty ", factnode.getFactName(), 129 ""); 130 } 131 132 /** 133 * This node tests the registration of the VisualisationPlugins. It is 134 * basicly a test of all combined tests in this class. If this works all the 135 * tests should work in this class. 136 * 137 * @author Renze de Vries 138 * @date 14-02-2007 139 */ 140 public void testVisualisations() { 141 RStoreFactType factType1 = dataManager.addFactType("<str, str>"); 142 RStoreFactType factType2 = dataManager.addFactType("<str, bool>"); 143 RStoreFactType factType3 = dataManager.addFactType("<str, str, int>"); 144 RStoreFactType factType4 = dataManager.addFactType("<int, int>"); 145 146 RStore rstoreNode1 = new RStore("Rstore1", 1); 147 148 RStoreFact factNode1 = new RStoreFact("Fact1", 1, factType1); 149 RStoreFact factNode2 = new RStoreFact("Fact2", 2, factType2); 150 rstoreNode1.addFactNode(factNode1); 151 rstoreNode1.addFactNode(factNode2); 152 153 RStore rstoreNode2 = new RStore("Rstore2", 2); 154 RStoreFact factNode3 = new RStoreFact("Fact3", 3, factType3); 155 RStoreFact factNode4 = new RStoreFact("Fact4", 4, factType4); 156 rstoreNode2.addFactNode(factNode3); 157 rstoreNode2.addFactNode(factNode4); 158 159 VisualisationPlugin visPlugin1 = new VisualisationPlugin("BarChart", 1); 160 VisualisationPlugin visPlugin2 = new VisualisationPlugin("GraphChart", 161 2); 162 VisualisationPlugin visPlugin3 = new VisualisationPlugin("TreeView", 3); 163 VisualisationPlugin visPlugin4 = new VisualisationPlugin("BarChart", 1); 164 165 assertNotNull("The created visPlugin1 is NULL", visPlugin1); 166 assertEquals("The name of the visPlugin1 should be BarChart", 167 "BarChart", visPlugin1.toString()); 168 assertEquals("The Id of the visPlugin1 should be 1", 1, visPlugin1 169 .getPluginId()); 170 171 assertEquals("The FactType should be the same according to cache", 172 factType1, dataManager.addFactType("<str, str>")); 173 assertEquals("The FactType should be the same according to cache", 174 factType2, dataManager.addFactType("<str, bool>")); 175 assertEquals("The FactType should be the same according to cache", 176 factType3, dataManager.addFactType("<str, str, int>")); 177 assertEquals("The FactType should be the same according to cache", 178 factType4, dataManager.addFactType("<int, int>")); 179 180 assertEquals("The number of visualisations of factType1 should be 0", 181 0, factType1.getVisualisationPlugins().size()); 182 assertEquals("The number of visualisations of factType2 should be 0", 183 0, factType2.getVisualisationPlugins().size()); 184 assertEquals("The number of visualisations of factType3 should be 0", 185 0, factType3.getVisualisationPlugins().size()); 186 assertEquals("The number of visualisations of factType4 should be 0", 187 0, factType4.getVisualisationPlugins().size()); 188 189 dataManager.createVisualisation(visPlugin1, factType1); 190 191 assertEquals("The number of visualisations of factType1 should be 1", 192 1, factType1.getVisualisationPlugins().size()); 193 194 dataManager.createVisualisation(visPlugin2, dataManager 195 .addFactType("<str, str, int>")); 196 197 assertEquals("The number of visualisations of factType3 should be 1", 198 1, factType3.getVisualisationPlugins().size()); 199 200 dataManager.createVisualisation(visPlugin3, dataManager 201 .addFactType("<str, bool>")); 202 203 assertEquals("The number of visualisations of factType2 should be 1", 204 1, factType2.getVisualisationPlugins().size()); 205 206 dataManager.createVisualisation(visPlugin4, dataManager 207 .addFactType("<str, bool>")); 208 209 assertEquals("The number of visualisations of factType2 should be 2", 210 2, factType2.getVisualisationPlugins().size()); 211 212 VisualisationPlugin emptyVisPlugin = new VisualisationPlugin(); 213 assertNotNull("The visualisationPlugin should not be null", emptyVisPlugin); 214 215 } 216 217 /** 218 * This test checks if the reset of the dataManager works and checks it 219 * 220 * @author Renze de Vries 221 * @date 12-03-2007 222 */ 223 public void testResetDataManager() { 224 RStoreFactType rstoreFactType = dataManager 225 .addFactType("<str, str, int>"); 226 227 dataManager.resetDataManager(); 228 229 RStoreFactType rstoreFactType2 = dataManager 230 .addFactType("<str, str, int>"); 231 232 assertNotSame("These instances should be different", rstoreFactType, 233 rstoreFactType2); 234 } 235 }