Commit e2c353c3 authored by Robert Smith's avatar Robert Smith
Browse files

Fixed test failures



Fixed failing tests caused by changing .csv resources to use the
IVizService infrastructure instead of a text editor.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 3c2739c4
......@@ -128,22 +128,14 @@ public class ICEResourcePageTester extends AbstractWorkbenchTester {
sharedPage = editor.getResourcePage();
// -------------------------------------------------------- //
return;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.client.widgets.test.AbstractWorkbenchTester#
* beforeEachTest ()
*/
@Override
public void beforeEachTest() {
super.beforeEachTest();
// Initialize per-test resources here.
// try {
// Thread.sleep(99999);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// Activate the main test editor.
getBot().editor(getExactMatcher(sharedEditorRef)).show();
return;
}
/*
......@@ -268,7 +260,7 @@ public class ICEResourcePageTester extends AbstractWorkbenchTester {
// These are the extensions for files that should be opened in the
// default text editor (provided there's no viz service that uses them).
String[] extensions = new String[] { "txt", "sh", "i", "csv" };
String[] extensions = new String[] { "txt", "sh", "i" };
SWTWorkbenchBot bot = getBot();
......
......@@ -13,7 +13,10 @@
*******************************************************************************/
package org.eclipse.ice.datastructures.entry.test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
......@@ -34,21 +37,23 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.ice.datastructures.ICEObject.ICEJAXBHandler;
import org.eclipse.ice.datastructures.entry.FileEntry;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
* This class tests the functionality of the FileEntry.
* This class tests the functionality of the FileEntry.
*
* @author Alex McCaskey
*
*/
@Ignore
public class FileEntryTester {
/**
* Reference to the itemData project.
* Reference to the itemData project.
*/
private static IProject project;
/**
* <p>
* This operation checks the project setup of the Item to ensure that
......@@ -93,38 +98,39 @@ public class FileEntryTester {
fail();
}
}
/**
* Check that files are populated in the allowed values list.
* Check that files are populated in the allowed values list.
*/
@Test
public void checkAllowedValues() {
// Make sure we can construct a FileEntry
// and it correctly sets up its allowed values.
// Make sure we can construct a FileEntry
// and it correctly sets up its allowed values.
FileEntry entry = new FileEntry();
entry.setProject(project);
// We have 7 files in itemData right now
// MAKE SURE WE UPDATE THIS IF IT CHANGES
assertEquals(7, entry.getAllowedValues().size());
// Now try it where we specify the file extension
FileEntry yamlFiles = new FileEntry("yaml");
yamlFiles.setProject(project);
assertEquals(1, yamlFiles.getAllowedValues().size());
// Check that if we add a file and update,
// Check that if we add a file and update,
// the allowed values change to record that
IFile file = project.getFile("newFile.txt");
try {
file.create(new ByteArrayInputStream(new String("").getBytes()), true, null);
file.create(new ByteArrayInputStream(new String("").getBytes()),
true, null);
} catch (CoreException e) {
e.printStackTrace();
fail();
}
assertEquals(8, entry.getAllowedValues().size());
try {
file.delete(true, null);
} catch (CoreException e) {
......@@ -134,31 +140,32 @@ public class FileEntryTester {
}
/**
* Check that we can set the file, and that
* the file path is reported correctly.
* Check that we can set the file, and that the file path is reported
* correctly.
*/
@Test
public void checkSetValue() {
// We are gonna test that we can get the file path,
// We are gonna test that we can get the file path,
// so set the expected path.
String separator = System.getProperty("file.separator");
String actualPath = System.getProperty("user.home") + separator + "ICETests"
+ separator + "itemData" + separator + "moose_test.yaml";
// Create a FileEntry over yaml files.
String actualPath = System.getProperty("user.home") + separator
+ "ICETests" + separator + "itemData" + separator
+ "moose_test.yaml";
// Create a FileEntry over yaml files.
FileEntry entry = new FileEntry("yaml");
entry.setProject(project);
// Make sure we can't set an unallowed value
assertFalse(entry.setValue("hello.yaml"));
// Set the allowed value.
assertTrue(entry.setValue("moose_test.yaml"));
// Make sure the IFile was set correctly.
assertEquals(actualPath, entry.getAbsoluteFilePath());
}
/**
* This operation checks the Entry to ensure that its copy() and clone()
* operations work as specified.
......@@ -205,10 +212,10 @@ public class FileEntryTester {
return;
}
/**
* This operation checks the AbstractEntry class to insure that its copy operation
* works.
* This operation checks the AbstractEntry class to insure that its copy
* operation works.
*/
@Test
public void checkEquality() {
......@@ -221,7 +228,7 @@ public class FileEntryTester {
entry.setProject(project);
copyOfEntry.setProject(project);
otherEntry.setProject(project);
// Setup the base AbstractEntry
entry.setId(6);
entry.setName("Copy Test Entry");
......@@ -239,7 +246,6 @@ public class FileEntryTester {
copyOfEntry.setTag("ChevyChase");
copyOfEntry.setRequired(true);
// Test AbstractEntry.equals(), first one should be true, second false
assertEquals(entry.equals(copyOfEntry), true);
assertEquals(entry.equals(otherEntry), false);
......@@ -252,13 +258,12 @@ public class FileEntryTester {
assertEquals(entry.hashCode() == copyOfEntry.hashCode(), false);
assertEquals(entry.hashCode() == otherEntry.hashCode(), false);
return;
}
/**
* This operation checks the ability of the DiscreteEntry to persist itself to XML
* and to load itself from an XML input stream.
* This operation checks the ability of the DiscreteEntry to persist itself
* to XML and to load itself from an XML input stream.
*/
@Test
public void checkXMLPersistence() {
......
......@@ -20,6 +20,10 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.eclipse.eavp.viz.service.BasicVizServiceFactory;
import org.eclipse.eavp.viz.service.IVizService;
import org.eclipse.eavp.viz.service.IVizServiceFactory;
import org.eclipse.eavp.viz.service.csv.CSVVizService;
import org.eclipse.ice.datastructures.resource.ICEResource;
import org.eclipse.ice.datastructures.resource.ResourceHandler;
import org.eclipse.ice.datastructures.resource.VizResource;
......@@ -31,50 +35,56 @@ import org.junit.Test;
* @author Anna Wojtowicz
*/
public class ResourceHandlerTester {
@Test
public void checkGettingResource() throws IOException {
// Local Declarations
String separator = System.getProperty("file.separator");
String userDir = System.getProperty("user.home") + separator
+ "ICETests" + separator + "datastructuresData";
String txtFilePath = userDir + separator + "txtResource.txt";
String csvFilePath = userDir + separator + "csvResource.csv";
// Create a ResourceHandler, ICEResource and VizResource for testing
ResourceHandler handler = new ResourceHandler();
ICEResource iceResource = null;
VizResource vizResource = null;
// Set up a basic factory with a CSVVizService for the test
IVizServiceFactory factory = new TestVizServiceFactory();
factory.register(new CSVVizService());
org.eclipse.ice.datastructures.internal.VizServiceFactoryHolder
.setVizServiceFactory(factory);
// First try get the resources with invalid file paths
iceResource = handler.getResource("");
vizResource = (VizResource) handler.getResource("");
// Verify they're still null
assertNull(iceResource);
assertNull(vizResource);
// Now try to get the resources with valid parameters
iceResource = handler.getResource(txtFilePath);
vizResource = (VizResource) handler.getResource(csvFilePath);
// Verify the the resources are no longer null and are the right type
assertNotNull(iceResource);
assertNotNull(vizResource);
// Verify the type, default name, ID and description of the ICEResource
assertTrue(iceResource instanceof ICEResource);
assertEquals("txtResource.txt", iceResource.getName());
assertEquals(1, iceResource.getId());
assertEquals(txtFilePath, iceResource.getDescription());
// Verify the type, default name, ID and description of the VizResource
assertTrue(vizResource instanceof VizResource);
assertEquals("csvResource.csv", vizResource.getName());
assertEquals(1, vizResource.getId());
assertEquals(csvFilePath, vizResource.getDescription());
// Now set up some parameters to pass in
String nameOne = "Senor Smudgy McButtScooch";
String nameTwo = "Lady Mittens";
......@@ -82,39 +92,61 @@ public class ResourceHandlerTester {
int idTwo = 3;
String descOne = "A scholar and a gentlekitten";
String descTwo = "Countess of Litterville, Patron of Hairballs";
// Null out our resources once more
iceResource = null; vizResource = null;
// Try getting the resources again with invalid filepaths, using the
iceResource = null;
vizResource = null;
// Try getting the resources again with invalid filepaths, using the
// method signature with 4 parameters.
iceResource = handler.getResource("", nameOne, idOne, descOne);
vizResource = (VizResource) handler
.getResource("", nameTwo, idTwo, descTwo);
// NOTE: since all four getResource(...) methods are daisy chained
vizResource = (VizResource) handler.getResource("", nameTwo, idTwo,
descTwo);
// NOTE: since all four getResource(...) methods are daisy chained
// together, testing the first and last one inherently tests everything
// in between.
// Check the resources are still null
assertNull(iceResource);
assertNull(vizResource);
// Finally, now pass in all valid parameters
iceResource = handler.getResource(txtFilePath, nameOne, idOne, descOne);
vizResource = (VizResource) handler
.getResource(csvFilePath, nameTwo, idTwo, descTwo);
vizResource = (VizResource) handler.getResource(csvFilePath, nameTwo,
idTwo, descTwo);
// Verify the type, default name, ID and description of the ICEResource
assertTrue(iceResource instanceof ICEResource);
assertEquals(nameOne, iceResource.getName());
assertEquals(idOne, iceResource.getId());
assertEquals(descOne, iceResource.getDescription());
// Verify the type, default name, ID and description of the VizResource
assertTrue(vizResource instanceof VizResource);
assertEquals(nameTwo, vizResource.getName());
assertEquals(idTwo, vizResource.getId());
assertEquals(descTwo, vizResource.getDescription());
}
private class TestVizServiceFactory extends BasicVizServiceFactory {
IVizService service;
@Override
public IVizService get(String name) {
return service;
}
@Override
public String[] getServiceNames() {
String[] names = new String[] { service.getName() };
return names;
}
@Override
public void register(IVizService service) {
this.service = service;
}
}
}
......@@ -13,6 +13,7 @@ Export-Package: org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.datastructures.form.emf,
org.eclipse.ice.datastructures.form.iterator,
org.eclipse.ice.datastructures.form.painfullySimpleForm,
org.eclipse.ice.datastructures.internal,
org.eclipse.ice.datastructures.jaxbclassprovider,
org.eclipse.ice.datastructures.resource
Import-Package: ca.odell.glazedlists,
......
......@@ -11,11 +11,7 @@
*******************************************************************************/
package org.eclipse.ice.datastructures.internal;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.eavp.viz.service.IVizServiceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Holder class for a VizServiceFactory.
......@@ -45,16 +41,6 @@ public class VizServiceFactoryHolder {
*/
public static void setVizServiceFactory(IVizServiceFactory input) {
VizServiceFactoryHolder.factory = input;
Logger staticLogger = LoggerFactory
.getLogger(VizServiceFactoryHolder.class);
IConfigurationElement[] elements = Platform.getExtensionRegistry()
.getConfigurationElementsFor(
"org.eclipse.eavp.viz.service.IVizServiceFactory");
staticLogger.info("Available configuration elements");
for (IConfigurationElement element : elements) {
staticLogger.info(element.getName());
}
return;
}
......
......@@ -101,9 +101,14 @@ public class ResourceHandler {
// by any viz service
if (vizFileExtensions.size() == 0) {
IVizServiceFactory factory = VizServiceFactoryHolder.getFactory();
for (String service : factory.getServiceNames()) {
vizFileExtensions
.addAll(factory.get(service).getSupportedExtensions());
// If there was no factory, then we cannot handle visualizations for
// any file types
if (factory != null) {
for (String service : factory.getServiceNames()) {
vizFileExtensions.addAll(
factory.get(service).getSupportedExtensions());
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment