001 package nl.cwi.sen1.visbase.factbrowser;
002
003 import javax.swing.tree.DefaultMutableTreeNode;
004
005 import junit.framework.TestCase;
006 import nl.cwi.sen1.relationstores.Factory;
007 import nl.cwi.sen1.visbase.factbrowser.data.FactBrowserDataManager;
008 import nl.cwi.sen1.visbase.factbrowser.data.RStore;
009 import nl.cwi.sen1.visbase.factbrowser.data.RStoreFact;
010 import nl.cwi.sen1.visbase.factbrowser.data.RStoreFactType;
011 import nl.cwi.sen1.visbase.factbrowser.data.VisualisationPlugin;
012 import aterm.pure.PureFactory;
013
014 /**
015 * This is the class which tests the toolbus interfaces as far as is possible.
016 *
017 * <br>
018 * <b>Classes not tested</b> FactBrowserDemo - This class was not tested
019 * because it only contains visual items FactBrowserTif - This class was not
020 * tested because toolbus generated file FactBrowserTool - This class was not
021 * tested because toolbus generated file FactBrowserBridge - This class was not
022 * tested because toolbus generated file
023 *
024 * <br>
025 * <b>methods not tested</b> FactBrowser.fbShowRstoreFacts - Not tested because
026 * of complex RStoreFacts which must be composed FactBrowser.recAckEvent - This
027 * is a blank method simply for toolbus compatibility FactBrowser.recTerminate -
028 * This is a method which is called when the toolbus is terminating
029 * FactBrowser.initStudioPlugin - Can only be tested when connected to the
030 * MetaStudio FactBrowser.initFactBrowserLayout - This is a visual method so can
031 * only be tested with a visual environment FactBrowser.openRstore - Can only be
032 * tested when connected to the MetaStudio FactBrowser.connectPanelWithMenu -
033 * Can only be tested when connected to the MetaStudio
034 *
035 * @author Renze de Vries
036 * @date 22-02-2007
037 *
038 */
039 public class FactBrowserTest extends TestCase {
040 private PureFactory pureFactory = null;
041
042 private Factory factory = null;
043
044 private FactBrowser factBrowser = null;
045
046 /**
047 * This method sets up the Unit Test so the nessecary factory instances are
048 * present.
049 *
050 * @author Renze de Vries
051 * @date 22-02-2007
052 */
053 protected void setUp() {
054 pureFactory = FactBrowserFactorySingleton.getPureFactoryInstance();
055 factory = FactBrowserFactorySingleton.getFactoryInstance();
056 factBrowser = new FactBrowser();
057 }
058
059 /**
060 * Test if the correct toolname is given for the FactBrowser
061 *
062 * @author Renze de Vries
063 * @date 22-02-2007
064 */
065 public void testToolName() {
066 assertEquals("This is not the correct toolname", "factbrowser",
067 factBrowser.getName());
068 }
069
070 /**
071 * This method tests is the initialisations in the "SetUp" are working as
072 * should be.
073 *
074 * @author Renze de Vries
075 * @date 12-03-2007
076 */
077 public void testFactory() {
078 assertNotNull("The factory should not be null", factory);
079
080 assertNotNull("The FactBrowser should not be null", factBrowser);
081
082 assertNotNull("The pureFactory should not be null", pureFactory);
083 }
084
085 /**
086 * This method tests if it is possible to add a visualisation plugin to the
087 * FactBrowser
088 *
089 * @author Renze de Vries
090 * @date 22-02-2007
091 */
092 public void testAddVisualisation() {
093 factBrowser.fbAddVisualizationPlugin(pureFactory.make("<str>",
094 "<str>,<str>"), 1, "Visualisatie Test Plugin");
095
096 RStoreFactType factType = FactBrowserDataManager.getInstance()
097 .addFactType("\"<str>,<str>\"");
098
099 RStoreFactType factTypeCompare = FactBrowserDataManager.getInstance()
100 .addFactType("<str>,<str>");
101
102 assertNotSame("The two given factTypes should not be the same",
103 factType, factTypeCompare);
104
105 assertEquals("There should be a added visualisation plugin", 1,
106 factType.getVisualisationPlugins().size());
107 }
108
109 /**
110 * Test it the visualisationWindow will create
111 *
112 * @author Renze de Vries
113 * @date 07-03-2007
114 */
115 public void testVisualisationWindow() {
116 FactBrowserWindow factBrowserWindow = new FactBrowserWindow();
117
118 assertNotNull("Visualisation Windows not created", factBrowserWindow);
119 }
120
121 /**
122 * This test checks if the retrieval of data is succesfull when a double
123 * click should happen. It cannot simulate the mouseclick itself but does do
124 * the same interanlly as the mouseClicked method.
125 *
126 * @author Renze de Vries
127 * @date 11-03-2007
128 */
129 public void testMouseClicked() {
130 FactBrowserDataManager dataManager = FactBrowserDataManager
131 .getInstance();
132
133 RStore rstore = new RStore("rstore1", 4);
134
135 DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("root");
136 DefaultMutableTreeNode rstoreNode = new DefaultMutableTreeNode(rstore);
137 rootNode.add(rstoreNode);
138
139 RStoreFact rstoreFact = new RStoreFact("fact1", 5, dataManager
140 .addFactType("<str,bool>"));
141 rstoreNode.add(rstoreFact);
142
143 VisualisationPlugin visPlugin = new VisualisationPlugin("plugin1", 2);
144 dataManager.createVisualisation(visPlugin, dataManager
145 .addFactType("<str,bool>"));
146
147 assertEquals("This node should be the visualisationPlugin", "plugin1",
148 rstoreFact.getFirstLeaf().toString());
149
150 DefaultMutableTreeNode selectedNode = rstoreFact.getFirstLeaf();
151
152 assertEquals("The selectedNode should be a valid visualisationPlugin",
153 true, dataManager.checkValidVisualisationPlugin(selectedNode));
154
155 assertEquals("The visualisationPlugin identifier should be 2", 2,
156 dataManager.getVisPluginID(selectedNode));
157
158 assertEquals("The RstoreFact identifier should be 5", 5, dataManager
159 .getFactID(selectedNode));
160
161 assertEquals("The RStore identifier should be 4", 4, dataManager
162 .getRStoreID(selectedNode));
163
164 assertEquals("This TreeNode should not be an RStoreFact", false,
165 dataManager.checkValidRStoreFact(selectedNode));
166
167 assertEquals("This TreeNode should be a RStoreFact", true, dataManager
168 .checkValidRStoreFact(rstoreFact));
169 }
170 }