Commit 44fdce3d authored by Robert Smith's avatar Robert Smith
Browse files

Added more tests



Added more tests for the new data structures.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 43907cd8
/*******************************************************************************
* Copyright (c) 2016 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:
* Robert Smith
*******************************************************************************/
package org.eclipse.ice.viz.service.datastructures.VizObject.test;
import java.util.ArrayList;
import org.eclipse.ice.viz.service.datastructures.VizObject.IManagedUpdateable;
import org.eclipse.ice.viz.service.datastructures.VizObject.IManagedUpdateableListener;
import org.eclipse.ice.viz.service.datastructures.VizObject.SubscriptionType;
/**
* A basic implementation of IManagedUpdateableListener for testing purposes.
*
* @author Robert Smith
*
*/
public class TestManagedListener implements IManagedUpdateableListener {
/**
* Whether the listener has received an update of the property type
*/
private boolean propertyNotified = false;
/**
* Whether the listener has received an update of the child type
*/
private boolean childNotified = false;
/**
* Whether the listener has received an update of the all type
*/
private boolean allNotified = false;
/**
* Whether the listener has received an update of the selection type
*/
private boolean selectionNotified = false;
/**
* Whether the listener has received an update of the wireframe type
*/
private boolean wireframeNotified = false;
/**
* Whether the listener has received an update of the transformation type
*/
private boolean transformationNotified = false;
/**
* The list of types of events this listener will receive
*/
ArrayList<SubscriptionType> types;
/**
* The default constructor.
*
* @param types
* The list of types of events this listener will receive.
*/
public TestManagedListener(ArrayList<SubscriptionType> types) {
this.types = types;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.datastructures.VizObject.
* IManagedUpdateableListener#getSubscriptions(org.eclipse.ice.viz.
* service.datastructures.VizObject.IManagedUpdateable)
*/
@Override
public ArrayList<SubscriptionType> getSubscriptions(
IManagedUpdateable source) {
return types;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.datastructures.VizObject.
* IManagedUpdateableListener#update(org.eclipse.ice.viz.service.
* datastructures.VizObject.IManagedUpdateable,
* org.eclipse.ice.viz.service.datastructures.VizObject.
* UpdateableSubscriptionType[])
*/
@Override
public void update(IManagedUpdateable component, SubscriptionType[] types) {
// For each type in the update, set each notification received to
// true if it matches one of the checked types
for (SubscriptionType type : types) {
if (type == SubscriptionType.PROPERTY) {
propertyNotified = true;
}
else if (type == SubscriptionType.CHILD) {
childNotified = true;
}
else if (type == SubscriptionType.ALL) {
allNotified = true;
}
else if (type == SubscriptionType.SELECTION) {
selectionNotified = true;
}
else if (type == SubscriptionType.WIREFRAME) {
wireframeNotified = true;
}
else if (type == SubscriptionType.TRANSFORMATION) {
transformationNotified = true;
}
}
}
/**
* Checks if the listener has received an ALL type notification and resets
* its state for the ALL type to the original, unnotified state.
*
* @return True if the listener has received a notification of type ALL
* since the last time this function was invoked. False otherwise.
*/
public boolean gotAll() {
boolean temp = allNotified;
allNotified = false;
return temp;
}
/**
* Checks if the listener has received a CHILD type notification and resets
* its state for the CHILD type to the original, unnotified state.
*
* @return True if the listener has received a notification of type CHILD
* since the last time this function was invoked. False otherwise.
*/
public boolean gotChild() {
boolean temp = childNotified;
childNotified = false;
return temp;
}
/**
* Checks if the listener has received an PROPERTY type notification and
* resets its state for the PROPERTY type to the original, unnotified state.
*
* @return True if the listener has received a notification of type PROPERTY
* since the last time this function was invoked. False otherwise.
*/
public boolean gotProperty() {
boolean temp = propertyNotified;
propertyNotified = false;
return temp;
}
/**
* Checks if the listener has received an SELECTION type notification and
* resets its state for the SELECTION type to the original, unnotified
* state.
*
* @return True if the listener has received a notification of type
* SELECTION since the last time this function was invoked. False
* otherwise.
*/
public boolean gotSelection() {
boolean temp = selectionNotified;
selectionNotified = false;
return temp;
}
/**
* Checks if the listener has received an TRANSFORMATION type notification
* and resets its state for the TRANSFORMATION type to the original,
* unnotified state.
*
* @return True if the listener has received a notification of type
* TRANSFORMATION since the last time this function was invoked.
* False otherwise.
*/
public boolean gotTransformation() {
boolean temp = transformationNotified;
transformationNotified = false;
return temp;
}
/**
* Checks if the listener has received an WIREFRAME type notification and
* resets its state for the WIREFRAME type to the original, unnotified
* state.
*
* @return True if the listener has received a notification of type
* WIREFRAME since the last time this function was invoked. False
* otherwise.
*/
public boolean gotWireframe() {
boolean temp = wireframeNotified;
wireframeNotified = false;
return temp;
}
}
\ No newline at end of file
......@@ -17,8 +17,8 @@ import java.util.ArrayList;
import org.eclipse.ice.viz.service.datastructures.VizObject.IManagedUpdateable;
import org.eclipse.ice.viz.service.datastructures.VizObject.IManagedUpdateableListener;
import org.eclipse.ice.viz.service.datastructures.VizObject.UpdateableSubscriptionManager;
import org.eclipse.ice.viz.service.datastructures.VizObject.SubscriptionType;
import org.eclipse.ice.viz.service.datastructures.VizObject.UpdateableSubscriptionManager;
import org.junit.Test;
/**
......@@ -43,7 +43,7 @@ public class UpdateableSubscriptionManagerTester {
// Create a listener for the object
ArrayList<SubscriptionType> allList = new ArrayList<SubscriptionType>();
allList.add(SubscriptionType.ALL);
TestListener listener = new TestListener(allList);
TestManagedListener listener = new TestManagedListener(allList);
source.register(listener);
// Create a list containing the CHILD type
......@@ -102,7 +102,7 @@ public class UpdateableSubscriptionManagerTester {
manager.setParent(parent);
// Create a listener for the object
TestListener parentListener = new TestListener(allList);
TestManagedListener parentListener = new TestManagedListener(allList);
parentSource.register(parentListener);
// Queuing the child should block the parent's messages
......@@ -160,11 +160,11 @@ public class UpdateableSubscriptionManagerTester {
propertyList.add(SubscriptionType.PROPERTY);
// Create a listener that will receive all updates
TestListener listener = new TestListener(allList);
TestManagedListener listener = new TestManagedListener(allList);
source.register(listener);
// Create a listener that will only receive CHILD type updates
TestListener childListener = new TestListener(childList);
TestManagedListener childListener = new TestManagedListener(childList);
source.register(childListener);
// Send a child update and check that it was received.
......@@ -220,7 +220,7 @@ public class UpdateableSubscriptionManagerTester {
propertyList.add(SubscriptionType.PROPERTY);
// Create two listeners that will receive property updates
TestListener listener = new TestListener(propertyList);
TestManagedListener listener = new TestManagedListener(propertyList);
source.register(listener);
// Check that the listener receives updates
......@@ -233,7 +233,7 @@ public class UpdateableSubscriptionManagerTester {
assertFalse(listener.gotProperty());
// Add two listeners and check that both receive updates
TestListener listener2 = new TestListener(propertyList);
TestManagedListener listener2 = new TestManagedListener(propertyList);
source.register(listener);
source.register(listener2);
source.sendUpdate(propertyList);
......@@ -262,136 +262,6 @@ public class UpdateableSubscriptionManagerTester {
assertTrue(listener2.gotProperty());
}
/**
* A basic implementation of IManagedUpdateableListener for testing
* purposes.
*
* @author Robert Smith
*
*/
private class TestListener implements IManagedUpdateableListener {
/**
* Whether the listener has received an update of the property type
*/
private boolean propertyNotified;
/**
* Whether the listener has received an update of the child type
*/
private boolean childNotified;
/**
* Whether the listener has received an update of the all type
*/
private boolean allNotified;
/**
* The list of types of events this listener will receive
*/
ArrayList<SubscriptionType> types;
/**
* The default constructor.
*
* @param types
* The list of types of events this listener will receive.
*/
public TestListener(ArrayList<SubscriptionType> types) {
this.types = types;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.datastructures.VizObject.
* IManagedUpdateableListener#getSubscriptions(org.eclipse.ice.viz.
* service.datastructures.VizObject.IManagedUpdateable)
*/
@Override
public ArrayList<SubscriptionType> getSubscriptions(
IManagedUpdateable source) {
return types;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.datastructures.VizObject.
* IManagedUpdateableListener#update(org.eclipse.ice.viz.service.
* datastructures.VizObject.IManagedUpdateable,
* org.eclipse.ice.viz.service.datastructures.VizObject.
* UpdateableSubscriptionType[])
*/
@Override
public void update(IManagedUpdateable component,
SubscriptionType[] types) {
// For each type in the update, set each notification received to
// true if it matches one of the checked types
for (SubscriptionType type : types) {
if (type == SubscriptionType.PROPERTY) {
propertyNotified = true;
}
else if (type == SubscriptionType.CHILD) {
childNotified = true;
}
else if (type == SubscriptionType.ALL) {
allNotified = true;
}
}
}
/**
* Checks if the listener has received an ALL type notification and
* resets its state for the ALL type to the original, unnotified state.
*
* @return True if the listener has received a notification of type ALL
* since the last time this function was invoked. False
* otherwise.
*/
public boolean gotAll() {
boolean temp = allNotified;
allNotified = false;
return temp;
}
/**
* Checks if the listener has received a CHILD type notification and
* resets its state for the CHILD type to the original, unnotified
* state.
*
* @return True if the listener has received a notification of type
* CHILD since the last time this function was invoked. False
* otherwise.
*/
public boolean gotChild() {
boolean temp = childNotified;
childNotified = false;
return temp;
}
/**
* Checks if the listener has received an PROPERTY type notification and
* resets its state for the PROPERTY type to the original, unnotified
* state.
*
* @return True if the listener has received a notification of type
* PROPERTY since the last time this function was invoked. False
* otherwise.
*/
public boolean gotProperty() {
boolean temp = propertyNotified;
propertyNotified = false;
return temp;
}
}
/**
* A basic implementation of IManagedUpdateable for testing purposes.
*
......@@ -419,8 +289,7 @@ public class UpdateableSubscriptionManagerTester {
public void sendUpdate(ArrayList<SubscriptionType> types) {
// Convert the array list to an array and send it to the manager
SubscriptionType[] temp = new SubscriptionType[types
.size()];
SubscriptionType[] temp = new SubscriptionType[types.size()];
temp = types.toArray(temp);
manager.notifyListeners(temp);
}
......
/*******************************************************************************
* 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:
* Robert Smith
*******************************************************************************/
package org.eclipse.ice.viz.service.modeling.test;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractControllerFactory;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
import org.eclipse.ice.viz.service.modeling.AbstractView;
import org.eclipse.ice.viz.service.modeling.PointController;
import org.eclipse.ice.viz.service.modeling.PointMesh;
import org.eclipse.ice.viz.service.modeling.VertexController;
import org.eclipse.ice.viz.service.modeling.VertexMesh;
import org.junit.Test;
/**
* A class for testing the functionality of the AbstractControllerFactory
*
* @author Robert Smith
*
*/
public class AbstractControllerFactoryTester {
/**
* Test that the controller invokes the proper provider for the given
* object.
*/
@Test
public void checkControllerCreation() {
TestControllerFactory factory = new TestControllerFactory();
// Check that the factory creates the right kind of controller for a
// PointMesh
PointMesh point = new PointMesh();
AbstractController pointC = factory.createController(point);
assertTrue(pointC instanceof PointController);
// Check that the factory creates the right kind of controller for a
// VertexMesh
VertexMesh vertex = new VertexMesh();
AbstractController vertexC = factory.createController(vertex);
assertTrue(vertexC instanceof VertexController);
// Check that the factory returns null for an unrecognized type.
AbstractController nullC = factory.createController(new AbstractMesh());
assertTrue(nullC == null);
}
/**
* A simple extension of the AbstractControllerFactory to include test
* classes
*
* @author Robert Smith
*
*/
public class TestControllerFactory extends AbstractControllerFactory {
/**
* The default constructor.
*/
public TestControllerFactory() {
super();
// Put the test providers into the map
typeMap.put(PointMesh.class, new TestPointProvider());
typeMap.put(VertexMesh.class, new TestVertexProvider());
}
/**
* Creates a PointController for PointMeshes
*
* @author Robert Smith
*
*/
public class TestPointProvider implements IControllerProvider {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.modeling.AbstractControllerFactory.
* IControllerProvider#createController(org.eclipse.ice.viz.service.
* modeling.AbstractMesh)
*/
@Override
public AbstractController createController(AbstractMesh model) {
return new PointController((PointMesh) model,
new AbstractView());
}
}
/**
* Creates a PointController for PointMeshes
*
* @author Robert Smith
*
*/
public class TestVertexProvider implements IControllerProvider {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.modeling.AbstractControllerFactory.
* IControllerProvider#createController(org.eclipse.ice.viz.service.
* modeling.AbstractMesh)
*/
@Override
public AbstractController createController(AbstractMesh model) {
return new VertexController((VertexMesh) model,
new AbstractView());
}
}
}
}
......@@ -702,6 +702,24 @@ class TestView extends AbstractView {
this.data = data;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.modeling.AbstractView#clone()
*/
@Override
public Object clone() {
// Create a new view
TestView clone = new TestView();
// Copy this object's data into the clone and return it
clone.