Commit 176e8c1d authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Fixed test errors.



The bug fixes from last week caused several test failures because of the
way services were refactored. This commit fixes that and also repairs
some extensions. The tests will not yet work in the build because of
some class circularity issues.
Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 80c70c7d
......@@ -10,6 +10,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
......
......@@ -30,10 +30,8 @@ import org.junit.Before;
import org.junit.Test;
/**
* <p>
* ClientTester checks the behavior and functionality of Client. It checks for
* proper location setting and file system querying from Core.
* </p>
*
* @author Jay Jay Billings
*/
......@@ -48,11 +46,6 @@ public class ClientTester {
*/
private FakeCore fakeCore;
/**
* A string for storing locations on the file system.
*/
private String location;
/**
* The fake widget factory used in the test
*/
......@@ -83,8 +76,7 @@ public class ClientTester {
this.iCEClient.setCoreService(fakeCore);
this.iCEClient.setUIWidgetFactory(fakeUIWidgetFactory);
// Set the Location's Path
location = System.getProperty("user.home");
return;
}
/**
......@@ -104,25 +96,25 @@ public class ClientTester {
// Check loading more than once
for (int i = 1; i < 5; i++) {
// Load an Item
this.iCEClient.loadItem(i);
iCEClient.loadItem(i);
// Check the Factory to make sure it was called
assertTrue(this.fakeUIWidgetFactory.widgetRequested());
assertTrue(fakeUIWidgetFactory.widgetRequested());
// Make sure the FormWidget was displayed
testFormWidget = this.fakeUIWidgetFactory.getLastFormWidget();
testFormWidget = fakeUIWidgetFactory.getLastFormWidget();
assertTrue(testFormWidget.widgetDisplayed());
}
// Reset the Factory
this.fakeUIWidgetFactory.reset();
fakeUIWidgetFactory.reset();
// Check that trying to load invalid widgets fails
for (int i = -10; i < -5; i++) {
// Load an Item
this.iCEClient.loadItem(i);
iCEClient.loadItem(i);
// Check the Factory to make sure it was called
assertTrue(this.fakeUIWidgetFactory.widgetRequested());
assertTrue(fakeUIWidgetFactory.widgetRequested());
// Make sure an ErrorBoxWidget was displayed
textErrorWidget = this.fakeUIWidgetFactory.getLastErrorBoxWidget();
textErrorWidget = fakeUIWidgetFactory.getLastErrorBoxWidget();
if (textErrorWidget instanceof FakeErrorBoxWidget) {
assertTrue(textErrorWidget.widgetDisplayed());
}
......@@ -132,24 +124,21 @@ public class ClientTester {
}
/**
* <p>
* This operation checks the Client by making sure that errors can be
* dispatched to the UI system to be displayed to the user.
* </p>
*
*/
@Test
public void checkThrowingErrors() {
// Reset the Factory
this.fakeUIWidgetFactory.reset();
fakeUIWidgetFactory.reset();
// Check loading more than once
for (int i = 1; i < 5; i++) {
// Load an Item
this.iCEClient.throwSimpleError("Throw error " + i + "!");
iCEClient.throwSimpleError("Throw error " + i + "!");
// Check the Factory to make sure it was called
assertTrue(this.fakeUIWidgetFactory.widgetRequested());
assertTrue(fakeUIWidgetFactory.widgetRequested());
// Make sure the Widget was displayed
FakeErrorBoxWidget testWidget = fakeUIWidgetFactory
.getLastErrorBoxWidget();
......@@ -162,12 +151,10 @@ public class ClientTester {
}
/**
* <p>
* This operation checks the Client by creating an Item. It makes sure that
* the Client uses the UIWidgetFactory, uses a UIWidget and registers a
* UIWidgetListener with the UIWidget. Fakes are used for the
* UIWidgetFactory and UIWidget.
* </p>
* <p>
* This operation also checks that getAvailableItemTypes returns the same
* list of available Item types as that in FakeCore: Red, Orange, Yellow,
......@@ -183,7 +170,7 @@ public class ClientTester {
ArrayList<String> types = new ArrayList<String>();
// Check the list of available Item types
types = this.iCEClient.getAvailableItemTypes();
types = iCEClient.getAvailableItemTypes();
assertTrue(types.contains("Red"));
assertTrue(types.contains("Orange"));
assertTrue(types.contains("Yellow"));
......@@ -197,38 +184,38 @@ public class ClientTester {
assertTrue(itemId > 0);
// Make sure that the Factory was called to get the Widget
assertTrue(this.fakeUIWidgetFactory.widgetRequested());
assertTrue(fakeUIWidgetFactory.widgetRequested());
// Get the FormWidget back since this one is a valid request
this.fakeFormWidget = fakeUIWidgetFactory.getLastFormWidget();
fakeFormWidget = fakeUIWidgetFactory.getLastFormWidget();
// Make sure that the FormWidget was called, has a registered listener
// and was displayed.
assertNotNull(this.fakeFormWidget);
assertTrue(this.fakeFormWidget.formRegistered());
assertTrue(this.fakeFormWidget.listenerRegistered());
assertTrue(this.fakeFormWidget.widgetDisplayed());
assertNotNull(fakeFormWidget);
assertTrue(fakeFormWidget.formRegistered());
assertTrue(fakeFormWidget.listenerRegistered());
assertTrue(fakeFormWidget.widgetDisplayed());
// Create another Item - make sure it is something that can't be
// created!
itemId = this.iCEClient.createItem("Spray Starch");
itemId = iCEClient.createItem("Spray Starch");
// Check the Item id
assertTrue(itemId < 0);
// Make sure that the Factory was called to get a widget
assertTrue(this.fakeUIWidgetFactory.widgetRequested());
assertTrue(fakeUIWidgetFactory.widgetRequested());
// Get the ErrorBoxWidget since this was not valid and an error should
// have been displayed
this.fakeErrorBoxWidget = fakeUIWidgetFactory.getLastErrorBoxWidget();
fakeErrorBoxWidget = fakeUIWidgetFactory.getLastErrorBoxWidget();
// Make sure that the FormWidget was called, has a registered listener
// and was displayed.
assertNotNull(this.fakeErrorBoxWidget);
assertNotNull(fakeErrorBoxWidget);
// FIXME - Should test for exact string
assertNotNull(this.fakeErrorBoxWidget.getErrorString());
assertTrue(this.fakeErrorBoxWidget.widgetDisplayed());
assertNotNull(fakeErrorBoxWidget.getErrorString());
assertTrue(fakeErrorBoxWidget.widgetDisplayed());
// Get the list of ICEObjects that represents the Items that have been
// created and check it. The FakeCore cheats and sends back an ICEObject
......@@ -248,17 +235,13 @@ public class ClientTester {
+ iCEClient.getItems().size());
return;
}
/**
* <p>
* This operation checks the Client by insuring that Items and Forms can be
* updated. It calls through the IUpdateWidgetListener interface. Review the
* documentation on the FakeCore class to determine the proper Form ids to
* use for the test.
* </p>
*
*/
@Test
public void checkItemUpdates() {
......@@ -309,12 +292,9 @@ public class ClientTester {
}
/**
* <p>
* This operation checks the ability of the client to correctly handle calls
* through the IProcessEventListener interface and by directly calling
* IClient.processItem().
* </p>
*
*/
@Test
public void checkItemProcessing() {
......@@ -443,12 +423,9 @@ public class ClientTester {
}
/**
* <p>
* This operation checks the ability of the Client to load Resources when
* signaled to do so by FormWidgets and other classes to which it may
* subscribe.
* </p>
*
*/
@Test
public void checkResourceLoading() {
......@@ -473,11 +450,8 @@ public class ClientTester {
}
/**
* <p>
* This operation checks the Client to make sure that if the connectToCore()
* operation is called that the Client tries to load an ExtraInfoWidget.
* </p>
*
*/
@Test
public void checkRemoteConnection() {
......@@ -508,11 +482,8 @@ public class ClientTester {
}
/**
* <p>
* This operation checks that the client can import a file and that it calls
* the Core to do so.
* </p>
*
*/
@Test
public void checkFileImport() {
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
#Mon Aug 22 11:54:35 EDT 2011
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
......@@ -4,9 +4,11 @@ Bundle-Name: CoreTest
Bundle-SymbolicName: org.eclipse.ice.core.test
Bundle-Version: 2.1.7.20150825
Fragment-Host: org.eclipse.ice.core;bundle-version="2.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.item
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.eclipse.ice.core.iCore,
org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.item,
org.eclipse.ice.persistence.xml
Require-Bundle: org.junit;bundle-version="4.8.1",
org.eclipse.ice.item
Bundle-Vendor: Oak Ridge National Laboratory
/*******************************************************************************
* Copyright (c) 2013, 2014- 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 -
* Jay Jay Billings
*******************************************************************************/
package org.eclipse.ice.core.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ice.core.iCore.IPersistenceProvider;
import org.eclipse.ice.persistence.xml.XMLPersistenceExtensionFactory;
import org.junit.Test;
/**
* This class tests the static interface operation
* IPersistenceProvider.getIPersistenceProviders().
*
* @author Jay Jay Billings
*
*/
public class IPersistenceProviderTester {
/**
* Test for {@link org.eclipse.ice.core.IPersistenceProvider.getProvider}.
*
* @throws CoreException
*/
@Test
public void test() throws CoreException {
// We need to load a class in the XML Persistence Provider bundle so
// that it will activate and the extensions will register with the
// framework. This is a hack that I don't like, but previously it wasn't
// needed because the OSGi bundles were started automatically by Tycho.
XMLPersistenceExtensionFactory factory = new XMLPersistenceExtensionFactory();
// Simply get the provider and make sure it is not null.
IPersistenceProvider provider = IPersistenceProvider.getProvider();
assertNotNull(provider);
return;
}
}
......@@ -3,5 +3,5 @@
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" enabled="true" immediate="false" name="org.eclipse.ice.core">
<implementation class="org.eclipse.ice.core.internal.Core"/>
<reference bind="registerCompositeItem" cardinality="0..n" interface="org.eclipse.ice.item.ICompositeItemBuilder" name="ICompositeItemBuilder" policy="dynamic" unbind="unregisterItem"/>
<reference bind="setIOService" cardinality="1..1" interface="org.eclipse.ice.io.serializable.IOService" name="IOService" policy="static"/>
<reference bind="setIOService" cardinality="1..1" interface="org.eclipse.ice.io.serializable.IIOService" name="IIOService" policy="static"/>
</scr:component>
......@@ -16,7 +16,14 @@ import java.util.ArrayList;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ice.item.Item;
import org.eclipse.ice.item.ItemBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An interface designed for item persistence within ICE.
......@@ -105,4 +112,45 @@ public interface IPersistenceProvider {
* now).
*/
public Item loadItem(IResource itemResource) throws IOException;
/**
* This operation retrieves the persistence from the ExtensionRegistry.
*
* @return The provider
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static IPersistenceProvider getProvider() throws CoreException {
// Logger for handling event messages and other information.
Logger logger = LoggerFactory.getLogger(IPersistenceProvider.class);
// The string identifying the persistence provider extension point.
String providerID = "org.eclipse.ice.core.persistenceProvider";
// The provider
IPersistenceProvider provider = null;
// Get the persistence provider from the extension registry.
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(providerID);
// Retrieve the provider from the registry and set it if one has not
// already been set.
if (point != null) {
// We only need one persistence provider, so just pull the
// configuration element for the first one available.
IConfigurationElement[] elements = point.getConfigurationElements();
if (elements.length > 0) {
IConfigurationElement element = elements[0];
provider = (IPersistenceProvider) element
.createExecutableExtension("class");
} else {
logger.info("No extensions found for IPersistenceProvider.");
}
} else {
logger.error("Extension Point " + providerID + "does not exist");
}
return provider;
}
}
\ No newline at end of file
......@@ -51,7 +51,7 @@ import org.eclipse.ice.datastructures.ICEObject.ICEList;
import org.eclipse.ice.datastructures.ICEObject.Identifiable;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.io.serializable.IOService;
import org.eclipse.ice.io.serializable.IIOService;
import org.eclipse.ice.item.ICompositeItemBuilder;
import org.eclipse.ice.item.ItemBuilder;
import org.eclipse.ice.item.SerializedItemBuilder;
......@@ -132,11 +132,6 @@ public class Core extends Application implements ICore, BundleActivator {
*/
public static final String builderID = "org.eclipse.ice.item.itemBuilder";
/**
* The string identifying the persistence provider extension point.
*/
public static final String providerID = "org.eclipse.ice.core.persistenceProvider";
/**
* The persistence provided by the osgi. This piece is set by the
* setPersistenceProvider method. This piece is passed to the ItemManager to
......@@ -251,30 +246,28 @@ public class Core extends Application implements ICore, BundleActivator {
// Store the component's context
bundleContext = context;
logger.info("ICore Message: Component context set!");
logger.info("Bundle context set!");
// Get the persistence provider from the extension registry.
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(providerID);
// Retrieve the provider from the registry and set it if one has not
// already been set.
if (point != null && provider == null) {
// We only need one persistence provider, so just pull the
// configuration element for the first one available.
IConfigurationElement element = point.getConfigurationElements()[0];
setPersistenceProvider((IPersistenceProvider) element
.createExecutableExtension("class"));
} else {
logger.error("Extension Point " + providerID + "does not exist");
// Set the default project on the Persistence Provider
createItemDBProjectSpace();
// If the provider has not been injected (say for testing) then pull it.
if (provider == null) {
provider = IPersistenceProvider.getProvider();
}
// If the provider IS available (since the core can run without it),
// configure it and the ItemManager.
if (provider != null) {
// Configure its default project.
provider.setDefaultProject(itemDBProject);
// Setup the persistence provider for the ItemManager so that it can
// load items.
itemManager.setPersistenceProvider(provider);
}
// Setup the persistence provider for the ItemManager so that it can
// load items.
itemManager.setPersistenceProvider(provider);
// Load up the
// Load up the ItemBuilders
ItemBuilder builder = null;
point = Platform.getExtensionRegistry().getExtensionPoint(builderID);
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(builderID);
// If the point is available, create all the builders and load them into
// the Item Manager.
......@@ -290,10 +283,6 @@ public class Core extends Application implements ICore, BundleActivator {
logger.error("Extension Point " + builderID + "does not exist");
}
// Set the default project on the Persistence Provider
createItemDBProjectSpace();
provider.setDefaultProject(itemDBProject);
// Tell the ItemManager to suit up. It's time to rock and roll.
itemManager.loadItems(itemDBProject);
......@@ -301,10 +290,12 @@ public class Core extends Application implements ICore, BundleActivator {
startHttpService();
// Check the currently registered extensions
//debugCheckExtensions();
// debugCheckExtensions();
// Register this class as a service with the framework.
registration = context.registerService(ICore.class, this, null);
if (context != null) {
registration = context.registerService(ICore.class, this, null);
}
return;
......@@ -731,59 +722,60 @@ public class Core extends Application implements ICore, BundleActivator {
*/
private void startHttpService() {
// Grab the service reference and the service
httpServiceRef = bundleContext.getServiceReference(HttpService.class);
// The service cannot be started without a valid bundle context since we
// are no longer using Declarative Services.
if (bundleContext != null) {
// Grab the service reference and the service
httpServiceRef = bundleContext
.getServiceReference(HttpService.class);
// If it is good to go, start up the webserver
if (httpServiceRef != null) {
// If it is good to go, start up the webserver
if (httpServiceRef != null) {
// Local Declaration
Dictionary<String, String> servletParams = new Hashtable<String, String>();
// Local Declaration
Dictionary<String, String> servletParams = new Hashtable<String, String>();
/// Get the service
httpService = bundleContext.getService(httpServiceRef);
/// Get the service
httpService = bundleContext.getService(httpServiceRef);
// Set the parameters
servletParams.put("javax.ws.rs.Application", Core.class.getName());
// Set the parameters
servletParams.put("javax.ws.rs.Application",
Core.class.getName());
// Register the service
try {
// Get the bundle
Bundle bundle = null;
if (bundleContext != null) {
// Register the service
try {
// Get the bundle
Bundle bundle = null;
bundle = bundleContext.getBundle();
} else {
logger.info("ICore Message: "
+ "ICE Core ComponentContext was null! No web service started.");
return;
}
// Make sure we got a valid bundle
if (bundle == null) {
logger.info(
"ICE Core Bundle was null! No web service started.");
return;
}
// Make sure we got a valid bundle
if (bundle == null) {
logger.info("ICore Message: "
+ "ICE Core Bundle was null! No web service started.");
return;
// Find the root location and the jaas_config file
URL resourceURL = bundle.getEntry("");
URL configFileURL = bundle.getEntry("jaas_config.txt");
// Resolve the URLs to be absolute
resourceURL = FileLocator.resolve(resourceURL);
configFileURL = FileLocator.resolve(configFileURL);
HttpContext httpContext = new BasicAuthSecuredContext(
resourceURL, configFileURL,
"ICE Core Server Configuration");
httpService.registerServlet("/ice",
new ServletContainer(this), servletParams,
httpContext);
} catch (ServletException | NamespaceException
| IOException e) {
logger.error(getClass().getName() + " Exception!", e);
}
// Find the root location and the jaas_config file
URL resourceURL = bundle.getEntry("");
URL configFileURL = bundle.getEntry("jaas_config.txt");
// Resolve the URLs to be absolute
resourceURL = FileLocator.resolve(resourceURL);
configFileURL = FileLocator.resolve(configFileURL);
HttpContext httpContext = new BasicAuthSecuredContext(
resourceURL, configFileURL,
"ICE Core Server Configuration");
httpService.registerServlet("/ice", new ServletContainer(this),
servletParams, httpContext);
} catch (ServletException | NamespaceException | IOException e) {
logger.error(getClass().getName() + " Exception!", e);
logger.info("ICE Core Server loaded and web service started!");
} else {
logger.info("ICE Core Server loaded, but without webservice.");
}
logger.info("ICore Message: ICE Core Server loaded and web "