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

Added more tests



Added tests for the new packages and corrected some bugs which were
causing test failures.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent f583cab2
......@@ -15,6 +15,7 @@ import org.eclipse.ice.viz.service.javafx.canvas.FXAttachment;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
......@@ -64,24 +65,23 @@ public class FXMeshAttachment extends FXAttachment {
// Get each part which is managed by that controller
for (AbstractController entity : group.getEntities()) {
// Add each child of a polygon to the scene, without repeats
if (entity.getEntitiesByCategory("Edges") != null
&& entity.getEntitiesByCategory("Vertices") != null) {
// Add the entity's own representation, if it has one and is not
// already present in the scene
if (entity.getRepresentation() != null && !fxAttachmentNode
.getChildren().contains(entity.getRepresentation())) {
fxAttachmentNode.getChildren()
.add((Node) entity.getRepresentation());
}
for (AbstractController child : entity.getEntities()) {
// Add each child of a polygon to the scene, without repeats
for (AbstractController child : entity.getEntities()) {
Group render = (Group) child.getRepresentation();
Group render = (Group) child.getRepresentation();
if (!fxAttachmentNode.getChildren().contains(render)) {
// Add the representation to the scene's node
fxAttachmentNode.getChildren().add(render);
}
if (!fxAttachmentNode.getChildren().contains(render)) {
// Add the representation to the scene's node
fxAttachmentNode.getChildren().add(render);
}
} else {
// Simply add the representations of other objects
fxAttachmentNode.getChildren()
.add((Group) entity.getRepresentation());
}
}
}
......
......@@ -24,6 +24,8 @@ import org.eclipse.ice.viz.service.modeling.AbstractView;
import org.eclipse.ice.viz.service.modeling.ShapeMesh;
import org.junit.Test;
import javafx.scene.Group;
/**
* A class to test the functionality of the FXAttachment.
*
......@@ -71,9 +73,53 @@ public class FXAttachmentTester {
attachment.addGeometry(empty);
assertTrue(attachment.getKnownParts().contains(empty));
// Create a new part
ShapeMesh mesh = new ShapeMesh();
mesh.setProperty("Type", "Cube");
FXShapeController controller = new FXShapeController(mesh,
new FXShapeView(mesh));
AbstractController controller = new AbstractController(mesh,
new TestFXView("Node 1"));
// Add it to the attachment and check that its representation is present
// in the attachment's tree
attachment.addGeometry(controller);
assertTrue(attachment.getFxNode().getChildren()
.contains(controller.getRepresentation()));
// Create a second new part
AbstractController controller2 = new AbstractController(mesh,
new TestFXView("Node 2"));
// Add the second part to the attachment and check that both
// representations are still present
attachment.addGeometry(controller2);
assertTrue(attachment.getFxNode().getChildren()
.contains(controller.getRepresentation()));
assertTrue(attachment.getFxNode().getChildren()
.contains(controller2.getRepresentation()));
}
private class TestFXView extends AbstractView {
/**
* The JavaFX node that will serve as this view's representation
*/
private Group node = new Group();
public TestFXView(String name) {
super();
node.getProperties().put("Name", name);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.modeling.AbstractView#getRepresentation()
*/
@Override
public Object getRepresentation() {
return node;
}
}
}
/*******************************************************************************
* 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.javafx.canvas.test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
import java.util.Map;
import org.eclipse.ice.viz.service.javafx.canvas.AbstractViewer;
import org.eclipse.ice.viz.service.javafx.canvas.FXContentProvider;
import org.eclipse.ice.viz.service.javafx.canvas.FXViewer;
import org.eclipse.ice.viz.service.javafx.internal.Util;
import org.eclipse.ice.viz.service.javafx.scene.base.GNode;
import org.eclipse.ice.viz.service.javafx.scene.base.ICamera;
import org.eclipse.ice.viz.service.javafx.scene.model.IAttachment;
import org.eclipse.ice.viz.service.javafx.scene.model.INode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
import javafx.scene.Group;
/**
* A class to test the functionality of the FXContentProvider.
*
* @author Robert Smith
*
*/
public class FXContentProviderTester {
/**
* Test that the content provider is generating the scene correctly.
*/
@Test
public void checkSceneGeneration() {
// Create a provider
FXContentProvider provider = new FXContentProvider();
// Create some nodes
GNode root = new GNode();
GNode node1 = new GNode();
GNode node2 = new GNode();
GNode node3 = new GNode();
// Create a tree from the nodes
root.addChild(node1);
root.addChild(node2);
node1.addChild(node3);
// Give the provider some input
provider.inputChanged(new FXViewer(
new Composite(new Shell(Display.getDefault()), SWT.NONE)), root,
new GNode());
// Check that the tree of JavaFX nodes mirrors the tree of corresponding
// GNodes
assertTrue(Util.getFxGroup(root).getChildren()
.contains(Util.getFxGroup(node1)));
assertTrue(Util.getFxGroup(root).getChildren()
.contains(Util.getFxGroup(node2)));
assertTrue(Util.getFxGroup(node1).getChildren()
.contains(Util.getFxGroup(node3)));
// Check that all the JavaFX nodes have references to the containing
// GNode
assertTrue(
Util.getFxGroup(root).getProperties().get(INode.class) == root);
assertTrue(Util.getFxGroup(node1).getProperties()
.get(INode.class) == node1);
assertTrue(Util.getFxGroup(node2).getProperties()
.get(INode.class) == node2);
assertTrue(Util.getFxGroup(node3).getProperties()
.get(INode.class) == node3);
}
/**
* Check that the content provider is correctly validating its input.
*/
@Test
public void checkValidation() {
// Create a provider
FXContentProvider provider = new FXContentProvider();
// Try sending in an invalid viewer
try {
provider.inputChanged(
new TestViewer(
new Composite(new Shell(new Display()), SWT.NONE)),
new GNode(), new GNode());
// If we made it here, then the provider accepted the invalid input
// without throwing an error.
fail();
} catch (Exception e) {
// If we made it here, then an exception was thrown. Continue the
// test.
}
// Try using invalid nodes
try {
provider.inputChanged(
new TestViewer(
new Composite(new Shell(new Display()), SWT.NONE)),
new TestNode(), new GNode());
// If we made it here, then the provider accepted the invalid input
// without throwing an error.
fail();
} catch (Exception e) {
// If we made it here, then an exception was thrown. Continue the
// test.
}
// Try sending in an invalid viewer
try {
provider.inputChanged(
new TestViewer(
new Composite(new Shell(new Display()), SWT.NONE)),
new GNode(), new TestNode());
// If we made it here, then the provider accepted the invalid input
// without throwing an error.
fail();
} catch (Exception e) {
// If we made it here, then an exception was thrown. Continue the
// test.
}
}
/**
* A dummy implementation of INode for testing.
*
* @author Robert Smith
*
*/
private class TestNode implements INode {
@Override
public INode getParent() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setParent(INode parent) {
// TODO Auto-generated method stub
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addChild(INode node) {
// TODO Auto-generated method stub
}
@Override
public void removeChild(INode node) {
// TODO Auto-generated method stub
}
@Override
public void removeAllChildren() {
// TODO Auto-generated method stub
}
@Override
public List<INode> getChildren(boolean copy) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setVisible(boolean visible) {
// TODO Auto-generated method stub
}
@Override
public boolean isVisible() {
// TODO Auto-generated method stub
return false;
}
@Override
public void attach(IAttachment attachment) {
// TODO Auto-generated method stub
}
@Override
public void detach(IAttachment attachment) {
// TODO Auto-generated method stub
}
@Override
public boolean hasAttachment(Class<?> attachmentClass) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supports(IAttachment attachment) {
// TODO Auto-generated method stub
return false;
}
@Override
public Map<Class<?>, List<IAttachment>> getAttachments() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<IAttachment> getAttachments(Class<?> clazz) {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<String, Object> getProperties() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getProperty(String key) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setProperty(String key, Object value) {
// TODO Auto-generated method stub
}
@Override
public boolean hasProperty(String key) {
// TODO Auto-generated method stub
return false;
}
}
/**
* A dummy AbstractViewer for testing.
*
* @author Robert Smith
*
*/
private class TestViewer extends AbstractViewer {
public TestViewer(Composite parent) {
super(parent);
// TODO Auto-generated constructor stub
}
@Override
protected void createControl(Composite parent) {
// TODO Auto-generated method stub
}
@Override
protected void updateCamera(ICamera camera) {
// TODO Auto-generated method stub
}
@Override
public Group getRoot() {
// TODO Auto-generated method stub
return null;
}
@Override
public Control getControl() {
// TODO Auto-generated method stub
return null;
}
@Override
public void refresh() {
// TODO Auto-generated method stub
}
}
}
/*******************************************************************************
* 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.javafx.canvas.test;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.javafx.canvas.FXSelection;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
import org.eclipse.ice.viz.service.modeling.AbstractView;
import org.junit.Test;
/**
* A class to test the functionality of the FXSelection
*
* @author Robert Smith
*
*/
public class FXSelectionTester {
/**
* Check that the selection holds its input correctly.
*/
@Test
public void checkContents() {
// Create a part
AbstractController part = new AbstractController(new AbstractMesh(),
new AbstractView());
// Create a selection on the part
FXSelection selection = new FXSelection(part);
// Check that the part is in the selection
assertTrue(part == selection.getShape());
}
}
/*******************************************************************************
* 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.javafx.canvas.test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.eclipse.ice.viz.service.javafx.canvas.FXSelection;
import org.eclipse.ice.viz.service.javafx.canvas.FXViewer;
import org.eclipse.ice.viz.service.javafx.canvas.FXVizCanvas;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
import org.eclipse.ice.viz.service.modeling.AbstractView;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
/**
* A class to test the functionality of the FXVizCanvas
*
* @author Robert Smith
*
*/
public class FXVizCanvasTester {
/**
* Test that the canvas is drawn correctly.
*/
@Test
public void checkDraw() {
AbstractController root = new AbstractController(new AbstractMesh(),
new AbstractView());
TestVizFXCanvas canvas = new TestVizFXCanvas(root);
try {
canvas.draw(new Composite(new Shell(new Display()), SWT.NONE));
} catch (Exception e) {
e.printStackTrace();
fail();
}
// Check that the canvas's viewer is the correct type
assertTrue(canvas.getViewer() instanceof FXViewer);
// Change the viewer's selection and check that an update was received
canvas.getViewer().setSelection(new FXSelection(root));
assertTrue(canvas.updated);
}
/**
* An extension of FXCanvas that keeps track of when its viewer's selection
* has been changed.
*
* @author Robert Smith
*
*/
private class TestVizFXCanvas extends FXVizCanvas {
public boolean updated = false;
/**
* The default constructor.
*
* @param geometry
* The root node.
*/
public TestVizFXCanvas(AbstractController geometry) {
super(geometry);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.javafx.canvas.FXVizCa