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

Added more tests



Added tests for the new bundles.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent d15e4289
<?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.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry excluding="org/eclipse/ice/viz/service/geometry/shapes/Tube.java|org/eclipse/ice/viz/service/geometry/widgets/RenderShape.java" kind="src" path="src"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.ice.viz.service.mesh"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.ice.viz.service.javafx.geometry.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
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.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JavaFX Geometry Visualization Services Test Plugin
Bundle-SymbolicName: org.eclipse.ice.viz.service.javafx.test;singleton:=true
Bundle-Version: 2.1.8
Fragment-Host: org.eclipse.ice.viz.service.javafx.geometry
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: Oak Ridge National Laboratory
Eclipse-ExtensibleAPI: true
Import-Package: junit.framework;version="4.12.0",
org.eclipse.ice.viz.service.modeling.test.utils,
org.hamcrest.core;version="1.3.0",
org.junit;version="4.12.0"
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
source.. = src/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ICE</groupId>
<artifactId>org.eclipse.ice.build</artifactId>
<version>2.1.8</version>
<relativePath>../${pom-filename}</relativePath>
</parent>
<groupId>ICE</groupId>
<artifactId>org.eclipse.ice.viz.service.javafx.geometry.test</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
\ No newline at end of file
/*******************************************************************************
* 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.geometry.datatypes.test;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeController;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeControllerFactory;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeView;
import org.eclipse.ice.viz.service.modeling.EdgeMesh;
import org.eclipse.ice.viz.service.modeling.ShapeMesh;
import org.junit.Test;
/**
* A class for testing the functionality of the FXShapeControllerFactory
*
* @author Robert Smith
*
*/
public class FXShapeControllerFactoryTester {
/**
* Check that the factory creates appropriate controllers and views for each
* type of input.
*/
@Test
public void checkCreation() {
// The factory to be tested
FXShapeControllerFactory factory = new FXShapeControllerFactory();
// Create a mesh and send it to the factory
ShapeMesh shapeMesh = new ShapeMesh();
FXShapeController shapeController = (FXShapeController) factory
.createController(shapeMesh);
// The resultant controller should have the mesh as its model and a
// FXShapeView for a view
assertTrue(shapeController.getModel() == shapeMesh);
assertTrue(shapeController.getView() instanceof FXShapeView);
// Try to send an unrecognized input mesh to the factory
EdgeMesh edgeMesh = new EdgeMesh();
assertNull(factory.createController(edgeMesh));
}
}
/*******************************************************************************
* 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.geometry.datatypes.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeController;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeView;
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.ice.viz.service.modeling.ShapeController;
import org.eclipse.ice.viz.service.modeling.ShapeMesh;
import org.eclipse.ice.viz.service.modeling.Transformation;
import org.eclipse.ice.viz.service.modeling.test.utils.TestController;
import org.eclipse.ice.viz.service.modeling.test.utils.TestMesh;
import org.junit.Test;
import javafx.scene.Group;
/**
* A class for testing the functionality of the FXShapeController.
*
* @author Robert Smith
*
*/
public class FXShapeControllerTester {
/**
* Test the FXShapeController's handling of the JavaFX Nodes' associations
* with ICE datastructures.
*/
@Test
public void checkNodes() {
// Create a cube
ShapeMesh mesh = new ShapeMesh();
mesh.setProperty("Type", "Cube");
FXShapeView view = new FXShapeView(mesh);
FXShapeController shape = new FXShapeController(mesh, view);
// The JavaFX node should have a reference to the FXShapeController
assertTrue(shape == ((Group) shape.getRepresentation()).getProperties()
.get(ShapeController.class));
// Create a sphere
ShapeMesh mesh2 = new ShapeMesh();
mesh2.setProperty("Type", "Sphere");
FXShapeView view2 = new FXShapeView(mesh2);
FXShapeController shape2 = new FXShapeController(mesh2, view2);
// Add the sphere shape as a child to the cube shape. The cube JavaFX
// node should now have the sphere JavaFX node as a child
shape.addEntity(shape2);
assertTrue(((Group) shape.getRepresentation()).getChildren()
.contains(shape2.getRepresentation()));
// Create a cylinder
ShapeMesh mesh3 = new ShapeMesh();
mesh2.setProperty("Type", "Cylinder");
FXShapeView view3 = new FXShapeView(mesh3);
FXShapeController shape3 = new FXShapeController(mesh3, view3);
// Add the cylinder shape as a child to the cube shape. The cube JavaFX
// node should now have both JavaFX nodes as children.
shape.addEntity(shape3);
assertTrue(((Group) shape.getRepresentation()).getChildren()
.contains(shape2.getRepresentation()));
assertTrue(((Group) shape.getRepresentation()).getChildren()
.contains(shape3.getRepresentation()));
// Remove the cube from being the sphere's parent. This should remove
// its JavaFX node from the cube's JavaFX node's children.
shape2.removeEntity(shape);
assertFalse(((Group) shape.getRepresentation()).getChildren()
.contains(shape2.getRepresentation()));
// Remove the cylinder from the sphere's children. This should also
// remove its JavaFX node from the cube's JavaFX node's children
shape.removeEntity(shape3);
assertFalse(((Group) shape.getRepresentation()).getChildren()
.contains(shape3.getRepresentation()));
// Create a union
ShapeMesh unionMesh = new ShapeMesh();
unionMesh.setProperty("Operator", "Union");
FXShapeView unionView = new FXShapeView(unionMesh);
FXShapeController unionShape = new FXShapeController(unionMesh,
unionView);
// Set the shape's parent as the union. This should add its JavaFX node
// to the union's java fxnode's children.
shape.setParent(unionShape);
assertTrue(((Group) unionShape.getRepresentation()).getChildren()
.contains(shape.getRepresentation()));
}
/**
* Test that the FXShape controller receives and handles updates correctly.
*/
@Test
public void checkUpdates() {
// Create a cube
ShapeMesh mesh = new ShapeMesh();
mesh.setProperty("Type", "Cube");
FXShapeView view = new FXShapeView(mesh);
FXShapeController shape = new FXShapeController(mesh, view);
// Create a test controller to monitor when the shape is updated
TestController controller = new TestController(new TestMesh(),
new AbstractView());
controller.addEntity(shape);
// Clear the controller's updated state
controller.isUpdated();
// Add a child to the mesh
mesh.addEntityByCategory(
new AbstractController(new AbstractMesh(), new AbstractView()),
"Test");
// This should have sent an update to the controller
assertTrue(controller.isUpdated());
// Select the mesh
mesh.setProperty("Selected", "True");
// The controller should have been updated
assertTrue(controller.isUpdated());
// Change one of the mesh's properties
mesh.setProperty("Test", "Property");
// The controller should not be subscribed to general property messages
// from the mesh
assertFalse(controller.isUpdated());
// Add a second child to the controller.
FXShapeController child = new FXShapeController(new ShapeMesh(),
new FXTestView());
shape.addEntity(child);
// Update the view's transformation
view.setTransformation(new Transformation());
// The controller should have been updated
assertTrue(controller.isUpdated());
// The controller should have recursively refreshed all childrens' views
assertTrue(((FXTestView) child.getView()).isRefreshed());
}
private class FXTestView extends FXShapeView {
/**
* Whether or not this view has been refreshed since the last time it
* was checked.
*/
boolean refreshed = false;
/**
* Checks if the view was refreshed and resets it to its initial,
* unrefreshed state.
*
* @return True if the view has been refreshed since the last time that
* isRefreshed() was invoked. False otherwise.
*/
public boolean isRefreshed() {
boolean temp = refreshed;
refreshed = false;
return temp;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeView#
* refresh(org.eclipse.ice.viz.service.modeling.AbstractMesh)
*/
@Override
public void refresh(AbstractMesh model) {
refreshed = true;
super.refresh(model);
}
}
}
/*******************************************************************************
* 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.geometry.datatypes.test;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeView;
import org.eclipse.ice.viz.service.modeling.ShapeMesh;
import org.junit.Test;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Box;
import javafx.scene.shape.Cylinder;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.Shape3D;
import javafx.scene.shape.Sphere;
/**
* A class to test the functionality of the FXShape.
*
* @author Robert Smith
*
*/
public class FXShapeViewTester {
/**
* Check that the view is constructed properly.
*/
@Test
public void checkConstruction() {
// Create a cube named "test"
ShapeMesh mesh = new ShapeMesh();
mesh.setProperty("Name", "test");
mesh.setProperty("Type", "Cube");
// Create a view for it
FXShapeView view = new FXShapeView(mesh);
// Whether a box shape has been found while searching the JavaFX node's
// children.
boolean boxFound = false;
// Check that the JavaFX node has the correct name
assertTrue("test".equals(((Group) view.getRepresentation()).getId()));
// Search all of the node's children
for (Node node : ((Group) view.getRepresentation()).getChildren()) {
// If the child is a 3D shape, it should be in fill mode by default
if (node instanceof Shape3D) {
assertTrue(((Shape3D) node).getDrawMode() == DrawMode.FILL);
// Check if a box has been found
if (view.getRepresentation() instanceof Box) {
boxFound = true;
}
}
}
// A child box corresponding to the cube should have been found
assertTrue(boxFound);
}
/**
* Check that the view updates itself correctly when it refreshes based on
* new information from the model.
*/
@Test
public void checkRefresh() {
// Create a cube
ShapeMesh mesh = new ShapeMesh();
mesh.setProperty("Type", "Cube");
// Create a view for it
FXShapeView view = new FXShapeView(mesh);
// Whether or not the current shape has been found in the view's
// children
boolean found = false;
// Search all of the node's children
for (Node node : ((Group) view.getRepresentation()).getChildren()) {
// If the child is a 3D shape, it should be in fill mode by default
if (node instanceof Shape3D) {
assertTrue(((Shape3D) node).getDrawMode() == DrawMode.FILL);
// Check if a box has been found
if (node instanceof Box) {
found = true;
}
}
}
// Change the shape to a cylinder
mesh.setProperty("Type", "Cylinder");
// Search all of the node's children
found = false;
for (Node node : ((Group) view.getRepresentation()).getChildren()) {
// If the child is a 3D shape, it should be in fill mode by default
if (node instanceof Shape3D) {
assertTrue(((Shape3D) node).getDrawMode() == DrawMode.FILL);
// Check if a box has been found
if (node instanceof Cylinder) {
found = true;
}
}
}
mesh.setProperty("Type", "Sphere");
found = false;
// Search all of the node's children
for (Node node : ((Group) view.getRepresentation()).getChildren()) {
// If the child is a 3D shape, it should be in fill mode by default
if (node instanceof Shape3D) {
assertTrue(((Shape3D) node).getDrawMode() == DrawMode.FILL);
// Check if a box has been found
if (node instanceof Sphere) {
found = true;
}
}
}
mesh.setProperty("Type", "Tube");
found = false;
// Search all of the node's children
for (Node node : ((Group) view.getRepresentation()).getChildren()) {
// If the child is a 3D shape, it should be in fill mode by default
if (node instanceof Shape3D) {
assertTrue(((Shape3D) node).getDrawMode() == DrawMode.FILL);
// Check if a box has been found
if (node instanceof MeshView) {
found = true;
}
}
}
}
}
/*******************************************************************************
* 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.geometry.datatypes.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXTube;
import org.junit.Test;