From aa3a5d66ae09ebe85619d33b94f368d038bfde9b Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 3 Aug 2015 22:42:16 -0400 Subject: [PATCH] Fixed several tests and removed old, now unnecessary test classes. --- .../service/widgets/PlotGridComposite.java | 9 +- .../test/ConnectionPlotRenderTester.java | 30 -- .../test/ConnectionPlotTester.java | 1 - .../test/ConnectionVizServiceTester.java | 58 ++- .../connections/test/FakeConnectionPlot.java | 65 --- .../test/FakeConnectionPlotRender.java | 74 --- .../test/FakeConnectionVizService.java | 105 ----- .../service/csv/test/CSVVizServiceTester.java | 6 +- .../ice/viz/service/test/FakePlot.java | 15 +- .../widgets/test/PlotGridCompositeTester.java | 441 ++++++++++-------- 10 files changed, 307 insertions(+), 497 deletions(-) delete mode 100644 tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotRenderTester.java delete mode 100644 tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlot.java delete mode 100644 tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlotRender.java delete mode 100644 tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionVizService.java diff --git a/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/widgets/PlotGridComposite.java b/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/widgets/PlotGridComposite.java index e731e703a..2e0665738 100644 --- a/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/widgets/PlotGridComposite.java +++ b/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/widgets/PlotGridComposite.java @@ -231,7 +231,7 @@ public void widgetDisposed(DisposeEvent e) { * An exception is thrown if the {@link IPlot} implementation * cannot be rendered. */ - public int addPlot(URI uri) throws Exception { + public int addPlot(URI uri) { int index = -1; // Try to create a plot if there is space available. @@ -243,7 +243,10 @@ public int addPlot(URI uri) throws Exception { if (provider.openDialog(getShell(), uri) == Window.OK) { plot = provider.getSelectedPlot(); } + } else { + System.err.println("Rejecting plot because not enough space"); } + // If a plot could be created, try to draw it. if (plot != null) { @@ -256,11 +259,13 @@ public int addPlot(URI uri) throws Exception { logger.warn(getClass().getName() + " Exception! " + "Error while attempting to draw a plot for the file \"" + uri.getPath() + "\".", e); + System.err.println("Exception while drawing plot"); return index; } // Add the plot to the list. index = plots.size(); + System.err.println("Drawing plot with index " + index); plots.add(plot); plotComposites.add(plotComposite); @@ -274,6 +279,8 @@ public int addPlot(URI uri) throws Exception { // Since a new plot was added, refresh the grid layout. refreshLayout(); + } else { + System.err.println("Rejecting plot because is null"); } return index; diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotRenderTester.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotRenderTester.java deleted file mode 100644 index ff8f2ad65..000000000 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotRenderTester.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015- UT-Battelle, LLC. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Initial API and implementation and/or initial documentation - - * Jordan Deyton - *******************************************************************************/ -package org.eclipse.ice.viz.service.connections.test; - -import org.eclipse.ice.viz.service.connections.ConnectionPlotRender; -import org.junit.Ignore; - -/** - * This class checks the {@link ConnectionPlotRender}'s default widgets and that - * the sub-class is called for further decoration of plot widgets at the - * appropriate times. - * - * @author Jordan Deyton - * - */ -@Ignore -public class ConnectionPlotRenderTester { - - // TODO Figure out how to test this class... - -} diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotTester.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotTester.java index 12c9b9308..bc0984a5f 100644 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotTester.java +++ b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionPlotTester.java @@ -12,7 +12,6 @@ package org.eclipse.ice.viz.service.connections.test; import org.eclipse.ice.viz.service.connections.ConnectionPlot; -import org.eclipse.ice.viz.service.connections.ConnectionPlotRender; import org.eclipse.ice.viz.service.connections.IVizConnection; import org.junit.Ignore; import org.junit.Test; diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionVizServiceTester.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionVizServiceTester.java index 4ff6bbf33..f55a73540 100644 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionVizServiceTester.java +++ b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/ConnectionVizServiceTester.java @@ -17,12 +17,19 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashSet; +import java.util.Set; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.ice.viz.service.IPlot; import org.eclipse.ice.viz.service.connections.ConnectionPlot; +import org.eclipse.ice.viz.service.connections.ConnectionPlotComposite; import org.eclipse.ice.viz.service.connections.ConnectionVizService; +import org.eclipse.ice.viz.service.connections.IVizConnectionManager; +import org.eclipse.ice.viz.service.connections.VizConnection; +import org.eclipse.ice.viz.service.connections.VizConnectionManager; import org.eclipse.ice.viz.service.preferences.CustomScopedPreferenceStore; +import org.eclipse.swt.widgets.Composite; import org.junit.Before; import org.junit.Test; @@ -45,11 +52,6 @@ public class ConnectionVizServiceTester { * The viz service that will be tested. */ private ConnectionVizService service; - /** - * A handle to the viz service that will be tested, but cast to its actual - * type. - */ - private FakeConnectionVizService fakeService; /** * A string containing the characters "localhost". @@ -86,22 +88,54 @@ public void beforeEachTest() { path = ""; node.put(name, host + "," + port + "," + path); - // Create the fake viz service. - fakeService = new FakeConnectionVizService() { + // Create a connection viz service. + service = new ConnectionVizService() { + + @Override + public String getName() { + return "Fake Connection Viz Service"; + } + + @Override + public String getVersion() { + return "0.0"; + } + + @Override + protected IVizConnectionManager createConnectionManager() { + return new VizConnectionManager() { + @Override + protected VizConnection createConnection( + String name, String preferences) { + return new FakeVizConnection(); + } + }; + } + @Override protected ConnectionPlot createConnectionPlot() { - FakeConnectionPlot plot = (FakeConnectionPlot) super.createConnectionPlot(); - plot.plotTypes.put("track", new String[] { "1", "2" }); - return plot; + return new ConnectionPlot() { + @Override + protected ConnectionPlotComposite createPlotComposite( + Composite parent) { + // This shouldn't be called. + return null; + } + }; } @Override protected String getConnectionPreferencesNodeId() { return NODE_ID; } + + @Override + protected Set findSupportedExtensions() { + Set extensions = new HashSet(); + extensions.add("csv"); + return extensions; + } }; - fakeService.supportedExtensions.add("csv"); - service = fakeService; // Add a remote connection after creating the service. name = "magic sword"; diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlot.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlot.java deleted file mode 100644 index 00f45d62e..000000000 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlot.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 UT-Battelle, LLC. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jordan Deyton - Initial API and implementation and/or initial documentation - * - *******************************************************************************/ -package org.eclipse.ice.viz.service.connections.test; - -import java.io.IOException; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.ice.viz.service.IVizService; -import org.eclipse.ice.viz.service.connections.ConnectionPlot; -import org.eclipse.ice.viz.service.connections.ConnectionPlotRender; -import org.eclipse.swt.widgets.Composite; - -/** - * This class provides a fake {@link ConnectionPlot}. - * - * @author Jordan Deyton - * - */ -public class FakeConnectionPlot extends ConnectionPlot { - - /** - * The plot types to use for this fake plot. Defaults to an empty map. - */ - public final Map plotTypes = new HashMap(); - - /** - * The default constructor. - * - * @param vizService - * The visualization service responsible for this plot. - */ - public FakeConnectionPlot(IVizService vizService) { - super(vizService); - } - - /* - * Implements an abstract method from ConnectionPlot. - */ - @Override - protected ConnectionPlotRender createConnectionPlotRender( - Composite parent) { - return new FakeConnectionPlotRender(parent, this); - } - - /* - * Implements an abstract method from ConnectionPlot. - */ - @Override - protected Map findPlotTypes(URI file) - throws IOException, Exception { - return plotTypes; - } - -} diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlotRender.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlotRender.java deleted file mode 100644 index 71836b7b2..000000000 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionPlotRender.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 UT-Battelle, LLC. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jordan Deyton - Initial API and implementation and/or initial documentation - * - *******************************************************************************/ -package org.eclipse.ice.viz.service.connections.test; - -import org.eclipse.ice.viz.service.connections.ConnectionPlot; -import org.eclipse.ice.viz.service.connections.ConnectionPlotRender; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; - -/** - * This class provides a fake {@link ConnectionPlotRender}. - * - * @author Jordan Deyton - * - */ -public class FakeConnectionPlotRender extends ConnectionPlotRender { - - /** - * The default constructor. - * - * @param parent - * The parent {@code Composite} that contains the plot render. - * @param plot - * The rendered {@code ConnectionPlot}. This cannot be changed. - */ - public FakeConnectionPlotRender(Composite parent, - ConnectionPlot plot) { - super(parent, plot); - } - - /* - * Implements an abstract method from ConnectionPlotRender. - */ - @Override - protected String getPreferenceNodeID() { - return "org.eclipse.ice.viz.service.connections.test"; - } - - /* - * Implements an abstract method from ConnectionPlotRender. - */ - @Override - protected Composite createPlotComposite(Composite parent, int style, - FakeClient connection) throws Exception { - return new Composite(parent, SWT.NONE); - } - - /* - * Implements an abstract method from ConnectionPlotRender. - */ - @Override - protected void updatePlotComposite(Composite plotComposite, - FakeClient connection) throws Exception { - // Nothing to do. - } - - /* - * Implements an abstract method from PlotRender. - */ - @Override - protected void clearCache() { - // Nothing to do. - } - -} diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionVizService.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionVizService.java deleted file mode 100644 index ca52b4e15..000000000 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/connections/test/FakeConnectionVizService.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 UT-Battelle, LLC. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jordan Deyton - Initial API and implementation and/or initial documentation - * - *******************************************************************************/ -package org.eclipse.ice.viz.service.connections.test; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.ice.viz.service.connections.ConnectionPlot; -import org.eclipse.ice.viz.service.connections.ConnectionVizService; -import org.eclipse.ice.viz.service.connections.IVizConnectionManager; -import org.eclipse.ice.viz.service.connections.VizConnection; -import org.eclipse.ice.viz.service.connections.VizConnectionManager; - -/** - * This class provides a fake concrete class for testing - * {@link ConnectionVizService}. - * - * @author Jordan Deyton - * - */ -public class FakeConnectionVizService extends ConnectionVizService { - - /** - * The name of the service. Defaults to "Fake Connection Viz Service". - */ - public String name = "Fake Connection Viz Service"; - /** - * The version of the service. Defaults to "pi". - */ - public String version = "pi"; - /** - * The set of supported extensions. Empty by default. - */ - public final Set supportedExtensions = new HashSet(); - - /** - * Whether or not {@link #createConnectionPlot()} was called. - */ - public final AtomicBoolean plotCreated = new AtomicBoolean(); - - /* - * Implements a method from IVizService. - */ - @Override - public String getName() { - return name; - } - - /* - * Implements a method from IVizService. - */ - @Override - public String getVersion() { - return version; - } - - /* - * Implements an abstract method from ConnectionVizService. - */ - @Override - protected IVizConnectionManager createConnectionManager() { - return new VizConnectionManager() { - @Override - protected VizConnection createConnection(String name, - String preferences) { - return new FakeVizConnection(); - } - }; - } - - /* - * Implements an abstract method from ConnectionVizService. - */ - @Override - protected ConnectionPlot createConnectionPlot() { - return new FakeConnectionPlot(this); - } - - /* - * Implements an abstract method from ConnectionVizService. - */ - @Override - protected String getConnectionPreferencesNodeId() { - return "org.eclipse.ice.viz.service.connections.test.connections"; - } - - /* - * Implements an abstract method from AbstractVizService. - */ - @Override - protected Set findSupportedExtensions() { - return supportedExtensions; - } - -} diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/csv/test/CSVVizServiceTester.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/csv/test/CSVVizServiceTester.java index 139f45795..3ba381c1e 100644 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/csv/test/CSVVizServiceTester.java +++ b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/csv/test/CSVVizServiceTester.java @@ -25,6 +25,7 @@ import org.eclipse.ice.viz.service.IPlot; import org.eclipse.ice.viz.service.IVizService; import org.eclipse.ice.viz.service.csv.CSVPlot; +import org.eclipse.ice.viz.service.csv.CSVProxyPlot; import org.eclipse.ice.viz.service.csv.CSVVizService; import org.junit.Test; @@ -75,9 +76,8 @@ public void testCreatePlot() { assertNotNull(plot); assertEquals(file.toURI(), plot.getDataSource()); - // It should actually return a CSVPlot, although that *could* change in - // the future. - assertTrue(plot instanceof CSVPlot); + // It should return a proxy to a CSVPlot. + assertTrue(plot instanceof CSVProxyPlot); // Passing a null URI should throw an exception. URI uri = null; diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/test/FakePlot.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/test/FakePlot.java index 43d853626..1451fd523 100644 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/test/FakePlot.java +++ b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/test/FakePlot.java @@ -40,7 +40,7 @@ public class FakePlot implements IPlot { * A list of all child composites created when * {@link #draw(String, String, Composite)} is called. */ - public final List children = new ArrayList(); + public Composite child; /** * The map of dependent series. This will not be populated with anything by @@ -48,6 +48,8 @@ public class FakePlot implements IPlot { */ public final Map> depSeries = new HashMap>(); + private int drawCount; + /** * The independent series for this plot. This is a plain new series by * default. @@ -59,6 +61,10 @@ public class FakePlot implements IPlot { */ public String name = ""; + public FakePlot() { + drawCount = 0; + } + /** * Adds the specified series to this plot under the given category * @@ -80,8 +86,9 @@ public void addDependentSeries(String catagory, ISeries seriesToAdd) { */ @Override public Composite draw(Composite parent) throws Exception { - Composite child = new Composite(parent, SWT.NONE); - children.add(child); + System.err.println("Drawing fake plot... " + drawCount); + drawCount++; + child = new Composite(parent, SWT.NONE); child.setMenu(parent.getMenu()); return child; } @@ -114,7 +121,7 @@ public List getDependentSeries(String category) { * Gets the number of times that {@link #draw(Composite)} was called. */ public int getDrawCount() { - return children.size(); + return drawCount; } /* diff --git a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/widgets/test/PlotGridCompositeTester.java b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/widgets/test/PlotGridCompositeTester.java index b840b641c..e818b2bf4 100644 --- a/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/widgets/test/PlotGridCompositeTester.java +++ b/tests/org.eclipse.ice.viz.service.test/src/org/eclipse/ice/viz/service/widgets/test/PlotGridCompositeTester.java @@ -11,15 +11,28 @@ *******************************************************************************/ package org.eclipse.ice.viz.service.widgets.test; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.eclipse.ice.viz.service.widgets.PlotGridComposite; -import org.eclipse.ice.client.widgets.test.FakePlot; import org.eclipse.ice.client.widgets.test.utils.AbstractSWTTester; +import org.eclipse.ice.viz.service.AbstractVizService; +import org.eclipse.ice.viz.service.BasicVizServiceFactory; import org.eclipse.ice.viz.service.IPlot; +import org.eclipse.ice.viz.service.ISeries; +import org.eclipse.ice.viz.service.IVizService; +import org.eclipse.ice.viz.service.IVizServiceFactory; import org.eclipse.ice.viz.service.csv.CSVSeries; +import org.eclipse.ice.viz.service.internal.VizServiceFactoryHolder; +import org.eclipse.ice.viz.service.test.FakePlot; +import org.eclipse.ice.viz.service.test.FakeSeries; +import org.eclipse.ice.viz.service.widgets.PlotGridComposite; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -46,11 +59,31 @@ public class PlotGridCompositeTester extends AbstractSWTTester { */ private static PlotGridComposite composite; + /** + * A reference to the viz service factory. + */ + private static IVizServiceFactory factory; + + /** + * The current fake plot that will be created by the fake viz service. + */ + private FakePlot fakePlot; + + /** + * A simple URI that can be used to create a plot. + */ + private URI simpleURI; + /** * A non-static, non-shared {@link PlotGridComposite} for testing. */ private PlotGridComposite testComposite; + /** + * The viz service responsible for creating fake plots. + */ + private IVizService vizService; + /* * (non-Javadoc) * @@ -71,6 +104,11 @@ public void run() { } }); + // Add the fake viz service to the factory used by the + // PlotGridComposite. + factory = new BasicVizServiceFactory(); + VizServiceFactoryHolder.setVizServiceFactory(factory); + return; } @@ -85,6 +123,37 @@ public void beforeEachTest() { super.beforeEachTest(); // Initialize per-test resources here. + + simpleURI = createValidURI("simpleFile"); + + // Create a fake viz service that creates fake plots. + vizService = new AbstractVizService() { + + @Override + public IPlot createPlot(URI uri) throws Exception { + return fakePlot; + } + + @Override + public String getName() { + return "Fake Viz Service"; + } + + @Override + public String getVersion() { + return "0.0"; + } + + @Override + protected Set findSupportedExtensions() { + Set extensions = new HashSet(); + extensions.add("ext"); + return extensions; + } + }; + factory.register(vizService); + + return; } /* @@ -95,6 +164,7 @@ public void beforeEachTest() { @Override public void afterEachTest() { // Dispose per-test resources here. + factory.unregister(vizService); // Proceed with the default post-test cleanup. super.afterEachTest(); @@ -207,28 +277,21 @@ public void run() { @Test public void checkAddPlot() { - // Makes the grid 1x3, and tries to add 4 valid plots. The 4th plot - // cannot be added because the grid is full. + // Makes the grid 1x1 and try to add 2 plots. The second plot cannot be + // added because there's not enough space. - FakePlot fakePlot; - FakePlot fakePlot2; - IPlot plot; int index = -1; int expectedIndex = -1; // Make the grid 1x3. getRowSpinner().setSelection(1); - getColumnSpinner().setSelection(3); - - // Create a plot to test adding to the composite. - fakePlot = createValidPlot(); - fakePlot2 = createValidPlot(); - plot = fakePlot; + getColumnSpinner().setSelection(1); // Add a plot. It should get the index 0. expectedIndex = 0; + fakePlot = createValidPlot(simpleURI); try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); @@ -236,44 +299,20 @@ public void checkAddPlot() { assertEquals(expectedIndex, index); // Make sure its child composite exists. assertEquals(1, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(0), composite)); - - // Add another plot. It should get the index 1. - expectedIndex = 1; - try { - index = addPlot(plot); - } catch (Exception e) { - fail("PlotGridCompositeTester error: " - + "An exception was thrown when adding a valid plot."); - } - assertEquals(expectedIndex, index); - // Make sure its child composite exists. - assertEquals(2, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(1), composite)); - - // Try to add another plot. - expectedIndex = 2; - try { - index = addPlot(fakePlot2); - } catch (Exception e) { - fail("PlotGridCompositeTester error: " - + "An exception was thrown when adding a valid plot."); - } - assertEquals(expectedIndex, index); - assertEquals(1, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(0), composite)); + assertTrue(childOfComposite(fakePlot.child, composite)); // Try to add another plot. It shouldn't be added. expectedIndex = -1; + fakePlot = createValidPlot(simpleURI); try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); - // Make sure its child composite does not exists. - assertEquals(2, fakePlot.getDrawCount()); + // It should not be drawn. + assertEquals(0, fakePlot.getDrawCount()); // Clear the plots. clearPlots(); @@ -286,41 +325,22 @@ public void checkAddPlot() { * {@link PlotGridComposite#addPlot(IPlot)}. */ @Test - public void checkAddPlotExceptions() { + public void checkAddPlotFailures() { // addPlot(null) should return -1. - // addPlot(...) when getPlotTypes() is null should return -1. - // addPlot(...) when getPlotTypes() is empty should return -1. - // addPlot(...) should throw getPlotTypes()'s exceptions. - // addPlot(...) should throw draw(...)'s exceptions. - - FakePlot fakePlot; - IPlot plot; - final IPlot nullPlot = null; + // addPlot(...) should return -1 if draw(...) throws exceptions. + final AtomicReference eRef = new AtomicReference(); // Check addPlot(null). - plot = nullPlot; + fakePlot = null; try { - assertEquals(-1, addPlot(plot)); + assertEquals(-1, addPlot(simpleURI)); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "Exception thrown when adding null plot. " + "Should just return -1."); } - // Check addPlot(...) when getPlotTypes() is empty. - fakePlot = new FakePlot(); - plot = fakePlot; - try { - assertEquals(-1, addPlot(plot)); - } catch (Exception e) { - fail("PlotGridCompositeTester error: " - + "Exception thrown when adding plot with empty plot type map. " - + "Should just return -1."); - } - // Make sure the plot's draw(...) method wasn't called. - assertEquals(0, fakePlot.getDrawCount()); - // Check addPlot(...) when draw(...) throws an exception. fakePlot = new FakePlot() { @Override @@ -332,25 +352,19 @@ public Composite draw(Composite parent) throws Exception { eRef.set(e); throw e; } - }; - // The plot needs to have some types... - fakePlot.addDependentSeries("preferred", getSeries("katana")); - fakePlot.addDependentSeries("preferred", getSeries("sai")); - fakePlot.addDependentSeries("preferred", getSeries("bo staff")); - fakePlot.addDependentSeries("preferred", getSeries("nunchaku")); - plot = fakePlot; + @Override + public ISeries getIndependentSeries() { + return new FakeSeries("fake"); + } + }; try { - addPlot(plot); - fail("PlotGridCompositeTester error: " - + "Exception from draw(...) was not relayed when adding plot."); + assertEquals(-1, addPlot(simpleURI)); } catch (Exception e) { assertSame(eRef.get(), e); + fail("PlotGridCompositeTester error: " + + "Exception from draw(...) was not relayed when adding plot."); } - // Make sure the plot's draw(...) method was called, but its child is - // disposed by addPlot(...). - assertEquals(1, fakePlot.getDrawCount()); - assertTrue(fakePlot.children.get(0).isDisposed()); return; } @@ -362,32 +376,28 @@ public Composite draw(Composite parent) throws Exception { @Test public void checkRemovePlot() { - // Make the grid 1x3. - // Add 3 plots (two from the same IPlot) so that no more can be added. - // Remove one of the two plots from the same IPlot. - // We can now add another plot. + // Make the grid 1x2. + // Add 2 plots. + // Remove the first plot. + // We can now add another plot. Test by adding a third one. // Remove all plots by index. - FakePlot fakePlot; - FakePlot fakePlot2; - IPlot plot; + List plots = new ArrayList(); + int index = -1; int expectedIndex = -1; // Make the grid 1x3. getRowSpinner().setSelection(1); - getColumnSpinner().setSelection(3); - - // Create a plot to test adding to the composite. - fakePlot = createValidPlot(); - fakePlot2 = createValidPlot(); - plot = fakePlot; + getColumnSpinner().setSelection(2); // ---- Add the three plots. ---- // // Add a plot. It should get the index 0. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 0; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); @@ -395,66 +405,68 @@ public void checkRemovePlot() { assertEquals(expectedIndex, index); // Make sure its child composite exists. assertEquals(1, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(0), composite)); + assertTrue(childOfComposite(fakePlot.child, composite)); // Add another plot. It should get the index 1. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 1; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); // Make sure its child composite exists. - assertEquals(2, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(1), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); + + // No more plots can be added. // Try to add another plot. - expectedIndex = 2; + fakePlot = createValidPlot(simpleURI); + expectedIndex = -1; try { - index = addPlot(fakePlot2); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); - assertEquals(1, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(0), composite)); - - // No more plots can be added. + // It was not drawn + assertEquals(0, fakePlot.getDrawCount()); // ------------------------------ // // ---- Remove one of the two plots with the shared IPlot. ---- // - // Remove the middle plot and make sure its drawn child is disposed. - removePlot(1); - assertTrue(fakePlot.children.get(1).isDisposed()); + // Remove the first plot and make sure its drawn child is disposed. + removePlot(0); + assertTrue(plots.remove(0).child.isDisposed()); // ------------------------------------------------------------ // // ---- Add another plot. ---- // // Try to add another plot. - expectedIndex = 2; + // We can use the existing fake plot. + plots.add(fakePlot); + expectedIndex = 1; try { - index = addPlot(fakePlot2); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); - assertEquals(2, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(1), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // --------------------------- // // ---- Remove all plots by index. ---- // // Remove the last one first, - removePlot(2); - assertTrue(fakePlot2.children.get(1).isDisposed()); + removePlot(1); + assertTrue(plots.remove(1).child.isDisposed()); // Then remove the first one. removePlot(0); - assertTrue(fakePlot.children.get(0).isDisposed()); - // THen remove the "middle" one (now the only one left). - removePlot(0); - assertTrue(fakePlot2.children.get(0).isDisposed()); + assertTrue(plots.remove(0).child.isDisposed()); // ------------------------------------ // // Trying to remove any more should do nothing. @@ -472,31 +484,26 @@ public void checkRemovePlot() { public void checkRemovePlots() { // Make the grid 1x3. - // Add 3 plots (two from the same IPlot) so that no more can be added. - // Remove the two plots from the same IPlot. - // Remove all plots by IPlot. + // Add 3 plots (two from the same URI) so that no more can be added. + // Remove the two plots from the same URI. + + List plots = new ArrayList(); - FakePlot fakePlot; - FakePlot fakePlot2; - IPlot plot; int index = -1; int expectedIndex = -1; - final IPlot nullPlot = null; // Make the grid 1x3. getRowSpinner().setSelection(1); getColumnSpinner().setSelection(3); - // Create a plot to test adding to the composite. - fakePlot = createValidPlot(); - fakePlot2 = createValidPlot(); - plot = fakePlot; - // ---- Add the three plots. ---- // // Add a plot. It should get the index 0. + fakePlot = createValidPlot(simpleURI); + System.err.println(System.identityHashCode(fakePlot)); + plots.add(fakePlot); expectedIndex = 0; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { e.printStackTrace(); fail("PlotGridCompositeTester error: " @@ -504,52 +511,57 @@ public void checkRemovePlots() { } assertEquals(expectedIndex, index); // Make sure its child composite exists. + System.err.println(System.identityHashCode(fakePlot)); assertEquals(1, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(0), composite)); + assertTrue(childOfComposite(fakePlot.child, composite)); // Add another plot. It should get the index 1. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 1; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); // Make sure its child composite exists. - assertEquals(2, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(1), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // Try to add another plot. + fakePlot = createValidPlot(createValidURI("different")); + plots.add(fakePlot); expectedIndex = 2; try { - index = addPlot(fakePlot2); + index = addPlot(fakePlot.getDataSource()); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); - assertEquals(1, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(0), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // No more plots can be added. // ------------------------------ // - // ---- Remove the two plots with the shared IPlot. ---- // - removePlots(plot); - assertTrue(fakePlot.children.get(0).isDisposed()); - assertTrue(fakePlot.children.get(1).isDisposed()); - // ----------------------------------------------------- // + // ---- Remove the two plots with the shared URI. ---- // + removePlots(simpleURI); + assertTrue(plots.remove(1).child.isDisposed()); + assertTrue(plots.remove(0).child.isDisposed()); + // ---------------------------------------------------- // // ---- Remove the remaining plots. ---- // - removePlots(fakePlot2); - assertTrue(fakePlot.children.get(0).isDisposed()); + removePlots(fakePlot.getDataSource()); + assertTrue(fakePlot.child.isDisposed()); // ------------------------------------- // // Trying to remove any more should do nothing. - removePlots(plot); - removePlots(fakePlot2); - removePlots(nullPlot); + removePlots(simpleURI); + removePlots(fakePlot.getDataSource()); + removePlots(null); return; } @@ -562,9 +574,8 @@ public void checkClearPlots() { // Add a couple of plots, then clear. Make sure the plots were disposed. - FakePlot fakePlot; - FakePlot fakePlot2; - IPlot plot; + List plots = new ArrayList(); + int index = -1; int expectedIndex = -1; @@ -572,20 +583,17 @@ public void checkClearPlots() { getRowSpinner().setSelection(1); getColumnSpinner().setSelection(3); - // Create some test plots. - fakePlot = createValidPlot(); - fakePlot2 = createValidPlot(); - plot = fakePlot; - // Reset the rows and columns to 2x2. getRowSpinner().setSelection(2); getColumnSpinner().setSelection(2); // ---- Add two plots. ---- // // Add a plot. It should get the index 0. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 0; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); @@ -593,28 +601,30 @@ public void checkClearPlots() { assertEquals(expectedIndex, index); // Make sure its child composite exists. assertEquals(1, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(0), composite)); + assertTrue(childOfComposite(fakePlot.child, composite)); // Add another plot. It should get the index 1. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 1; try { - index = addPlot(fakePlot2); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); // Make sure its child composite exists. - assertEquals(1, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(0), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // ------------------------ // // Clear the plots. clearPlots(); // Make sure the children are disposed. - assertTrue(fakePlot.children.get(0).isDisposed()); - assertTrue(fakePlot2.children.get(0).isDisposed()); + assertTrue(plots.remove(0).child.isDisposed()); + assertTrue(plots.remove(0).child.isDisposed()); return; } @@ -625,11 +635,8 @@ public void checkClearPlots() { @Test public void checkClearPlotsButton() { - // Add a couple of plots, then clear. Make sure the plots were disposed. + List plots = new ArrayList(); - FakePlot fakePlot; - FakePlot fakePlot2; - IPlot plot; int index = -1; int expectedIndex = -1; @@ -637,20 +644,17 @@ public void checkClearPlotsButton() { getRowSpinner().setSelection(1); getColumnSpinner().setSelection(3); - // Create some test plots. - fakePlot = createValidPlot(); - fakePlot2 = createValidPlot(); - plot = fakePlot; - // Reset the rows and columns to 2x2. getRowSpinner().setSelection(2); getColumnSpinner().setSelection(2); // ---- Add two plots. ---- // // Add a plot. It should get the index 0. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 0; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); @@ -658,28 +662,33 @@ public void checkClearPlotsButton() { assertEquals(expectedIndex, index); // Make sure its child composite exists. assertEquals(1, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(0), composite)); + assertTrue(childOfComposite(fakePlot.child, composite)); // Add another plot. It should get the index 1. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 1; try { - index = addPlot(fakePlot2); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); // Make sure its child composite exists. - assertEquals(1, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(0), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // ------------------------ // + // Clear the plots. + clearPlots(); + // Clear the plots by clicking to ToolBar button. getBot().toolbarButton("Clear").click(); // Make sure the children are disposed. - assertTrue(fakePlot.children.get(0).isDisposed()); - assertTrue(fakePlot2.children.get(0).isDisposed()); + assertTrue(plots.remove(0).child.isDisposed()); + assertTrue(plots.remove(0).child.isDisposed()); return; } @@ -694,9 +703,8 @@ public void checkTrimmingPlots() { // Add 3 plots. // Make the grid 2x1. The third plot should be disposed. - FakePlot fakePlot; - FakePlot fakePlot2; - IPlot plot; + List plots = new ArrayList(); + int index = -1; int expectedIndex = -1; @@ -705,15 +713,13 @@ public void checkTrimmingPlots() { getColumnSpinner().setSelection(1); // ---- Add 3 plots to fill the grid. ---- // - // Create the plots. - fakePlot = createValidPlot(); - fakePlot2 = createValidPlot(); - plot = fakePlot; // Add a plot. It should get the index 0. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 0; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); @@ -721,39 +727,44 @@ public void checkTrimmingPlots() { assertEquals(expectedIndex, index); // Make sure its child composite exists. assertEquals(1, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(0), composite)); + assertTrue(childOfComposite(fakePlot.child, composite)); // Add another plot. It should get the index 1. + fakePlot = createValidPlot(simpleURI); + plots.add(fakePlot); expectedIndex = 1; try { - index = addPlot(plot); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); // Make sure its child composite exists. - assertEquals(2, fakePlot.getDrawCount()); - assertTrue(childOfComposite(fakePlot.children.get(1), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // Try to add another plot. + fakePlot = createValidPlot(simpleURI); expectedIndex = 2; try { - index = addPlot(fakePlot2); + index = addPlot(simpleURI); } catch (Exception e) { fail("PlotGridCompositeTester error: " + "An exception was thrown when adding a valid plot."); } assertEquals(expectedIndex, index); - assertEquals(1, fakePlot2.getDrawCount()); - assertTrue(childOfComposite(fakePlot2.children.get(0), composite)); + assertEquals(1, fakePlot.getDrawCount()); + assertTrue(childOfComposite(fakePlot.child, composite)); // --------------------------------------- // // Make the grid 2x1. getRowSpinner().setSelection(2); // The third plot should have been disposed. - assertTrue(fakePlot2.children.get(0).isDisposed()); + assertTrue(fakePlot.child.isDisposed()); + assertFalse(plots.get(0).child.isDisposed()); + assertFalse(plots.get(1).child.isDisposed()); // Clear the plots. clearPlots(); @@ -796,14 +807,14 @@ public void checkCloseButton() { * This catches the Exception (if one occurs) on the UI thread * and throws it on the test thread. */ - private int addPlot(final IPlot plot) throws Exception { + private int addPlot(final URI uri) throws Exception { final AtomicInteger index = new AtomicInteger(); final AtomicReference eRef = new AtomicReference(); getDisplay().syncExec(new Runnable() { @Override public void run() { try { - int i = composite.addPlot(plot); + int i = composite.addPlot(uri); index.set(i); } catch (Exception e) { eRef.set(e); @@ -847,11 +858,11 @@ public void run() { * A wrapper around {@link PlotGridComposite#removePlots(IPlot))} that uses * {@code syncExec(...)} to perform the operation on the UI thread. */ - private void removePlots(final IPlot plot) { + private void removePlots(final URI uri) { getDisplay().syncExec(new Runnable() { @Override public void run() { - composite.removePlots(plot); + composite.removePlots(uri); } }); } @@ -864,7 +875,7 @@ private void clearPlots() { getDisplay().syncExec(new Runnable() { @Override public void run() { - composite.clearPlots(); + composite.removeAllPlots(); } }); } @@ -891,9 +902,18 @@ public void run() { /** * Creates a FakePlot that will draw something and has a set of plot types. + * + * @param The + * URI for the fake plot. */ - private FakePlot createValidPlot() { - FakePlot plot = new FakePlot(); + private FakePlot createValidPlot(URI uri) { + final URI uriRef = uri; + FakePlot plot = new FakePlot() { + @Override + public URI getDataSource() { + return uriRef; + } + }; // Add some random series with different categories to the plot plot.addDependentSeries("tmnt", getSeries("leo")); plot.addDependentSeries("tmnt", getSeries("donnie")); @@ -968,4 +988,21 @@ private SWTBotSpinner getRowSpinner() { private SWTBotSpinner getColumnSpinner() { return getBot().spinner(1); } + + /** + * Used to create a URI with an extension supported by the fake viz service. + * + * @param filename + * The name of the file, excluding the extension. + * @return A valid (albeit completely fabricated) URI. + */ + private URI createValidURI(String filename) { + URI uri = null; + try { + uri = new URI("file:///some/path/to/" + filename + ".ext"); + } catch (URISyntaxException e) { + fail("Bad URI. This should not happen."); + } + return uri; + } } \ No newline at end of file