Commit 768133f3 authored by Robert Smith's avatar Robert Smith
Browse files

Updated SWTBot and VIBE tests



Updated the tests for VIBE, as well as the SWTBOT UI tests.
Signed-off-by: Robert Smith's avatarRobert Smith <smithrw@ornl.gov>
parent 382df19e
......@@ -183,7 +183,7 @@ public class ReflectivityPage extends ICEResourcePage
Section listSection = formToolkit.createSection(sashForm,
Section.TITLE_BAR | Section.DESCRIPTION | Section.TWISTIE
| Section.EXPANDED | Section.COMPACT);
listSection.setLayout(new GridLayout(1, false));
listSection.setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
......@@ -243,9 +243,9 @@ public class ReflectivityPage extends ICEResourcePage
if (!newSelection.equals(selectedCell)) {
selectedCell = newSelection;
for (ISelectionChangedListener listener : listeners) {
listener.selectionChanged(new SelectionChangedEvent(
ReflectivityPage.this, ReflectivityPage.this
.getSelection()));
listener.selectionChanged(
new SelectionChangedEvent(ReflectivityPage.this,
ReflectivityPage.this.getSelection()));
}
}
}
......@@ -262,10 +262,12 @@ public class ReflectivityPage extends ICEResourcePage
// Create the resource form page contents
super.createFormContent(resourceForm);
//Open the properties view and set the focuse on this view to force the correct properties to display.
// Open the properties view and set the focuse on this view to force the
// correct properties to display.
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.ui.propertiesView");
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("org.eclipse.ui.propertiesView");
} catch (PartInitException e) {
e.printStackTrace();
}
......@@ -331,9 +333,9 @@ public class ReflectivityPage extends ICEResourcePage
list.getReadWriteLock().writeLock().unlock();
}
}
}
listTable.getTable().refresh();
}
......@@ -375,7 +377,7 @@ public class ReflectivityPage extends ICEResourcePage
}
}
}
listTable.getTable().refresh();
}
......@@ -432,7 +434,7 @@ public class ReflectivityPage extends ICEResourcePage
}
}
listTable.getTable().refresh();
}
}
......@@ -489,7 +491,7 @@ public class ReflectivityPage extends ICEResourcePage
listTable.setSelection(selected);
}
}
listTable.getTable().refresh();
}
}
......@@ -515,7 +517,7 @@ public class ReflectivityPage extends ICEResourcePage
list.clear();
list.getReadWriteLock().writeLock().unlock();
}
listTable.getTable().refresh();
}
......@@ -676,7 +678,5 @@ public class ReflectivityPage extends ICEResourcePage
public void setSelection(ISelection selection) {
// Do nothing, as we do not want this capability
}
}
......@@ -30,7 +30,7 @@ public class MOOSETester extends AbstractWorkbenchTester {
// Test the functionality of the Moose Actions drop down button
@Test
public void checkMooseActions() {
// Open the MOOSE perspective
bot.menu("Window").menu("Perspective").menu("Open Perspective")
.menu("Other...").click();
......@@ -60,7 +60,7 @@ public class MOOSETester extends AbstractWorkbenchTester {
// Open the add item dialog and add a MOOSE workflow
bot.viewByPartName("Item Viewer").setFocus();
//bot.toolbarButton(0).click();
// bot.toolbarButton(0).click();
bot.toolbarButtonWithTooltip("Create an Item").click();
bot.list(0).select("MOOSE Workflow");
bot.button("Finish").click();
......@@ -85,11 +85,12 @@ public class MOOSETester extends AbstractWorkbenchTester {
.equals("There are unsaved changes on the form."));
// Save and check that the header's text returned to normal.
try{
bot.toolbarButtonWithTooltip("Save (Ctrl+S)").click();
//If the save button wasn't found with the windows/linux tooltip, try the mac tooltip
}catch(WidgetNotFoundException e){
try {
bot.toolbarButtonWithTooltip("Save (Ctrl+S)").click();
// If the save button wasn't found with the windows/linux tooltip,
// try the mac tooltip
} catch (WidgetNotFoundException e) {
bot.toolbarButtonWithTooltip("Save (\u2318S)").click();
}
assertTrue(bot.clabel(0).getText().equals("Ready to process."));
......
......@@ -127,6 +127,7 @@ public class ReflectivityModelTester extends AbstractWorkbenchTester {
assertTrue("107Ag".equals(cellName));
// Move it up two rows
table.selectCell(bot, 0, 5);
bot.button("^").click();
bot.button("^").click();
cellName = (String) realTable.getDataValueByPosition(1, 4);
......
......@@ -70,9 +70,12 @@ public class VIBEKeyValuePairTester extends AbstractWorkbenchTester {
// Change the first row's value to two
bot.table(1).click(0, 1);
bot.text().typeText("2");
bot.text("1 ", 0).setText("2");
bot.table(1).click(0, 0);
// Check that the cell was set
assertTrue("2".equals(bot.table(1).cell(0, 1)));
// Makes sure the form registers that it is dirty
assertTrue("There are unsaved changes on the form."
.equals(bot.clabel(0).getText()));
......@@ -100,5 +103,37 @@ public class VIBEKeyValuePairTester extends AbstractWorkbenchTester {
bot.button("Go!").click();
assertTrue(bot.clabel(0).getText().equals("Done!"));
// Set the template to DualFoil
bot.radio(1).click();
// Check that a couple of the DualFoil's rows are set up correctly
assertTrue("NUMSEG".equals(bot.table(1).cell(14, 0)));
assertTrue("CUTOFFL".equals(bot.table(1).cell(17, 0)));
assertTrue("2.0,2.0,2.0,2.0,2.0".equals(bot.table(1).cell(17, 1)));
// Set the NUMSEG key to 8.
bot.table(1).click(14, 1);
bot.text("5", 0).setText("8");
bot.table(1).click(14, 0);
// CUTOFFL should have had its vector increased in size to account for
// the new NUMSEG value
assertTrue("2.0,2.0,2.0,2.0,2.0,0.0,0.0,0.0"
.equals(bot.table(1).cell(17, 1)));
// Set NUMSEG to 4
bot.table(1).click(14, 1);
bot.text("8", 0).setText("4");
bot.table(1).click(14, 0);
// CUTOFFL should have been reduced to only 4 numbers
assertTrue("2.0,2.0,2.0,2.0".equals(bot.table(1).cell(17, 1)));
// Set the template back to NTG
bot.radio(0).click();
// Check one of the rows to ensure that the NTG template has been loaded
assertTrue("CUTOFF".equals(bot.table(1).cell(15, 0)));
}
}
......@@ -155,15 +155,11 @@ public class VIBEModelTester extends AbstractWorkbenchTester {
// Check each of the port types available in the menu and check the
// number of text fields they display.
// FIXME INIT_STATE, CHARTRAN_ElECTRICAL_THERMAL_DRIVER, and NTG have
// different variables available for editing between the default
// provided sockets and the ones added by the button. Need to figure out
// if this is intentional.
bot.button(2).click();
bot.table().select("INIT_STATE");
bot.button("OK").click();
// bot.table(1).select(5);
// bot.text(13).typeText("Test");
bot.table(1).select(5);
bot.text(13).typeText("Test");
bot.button(2).click();
bot.table().select("AMPERES_THERMAL");
......@@ -180,14 +176,14 @@ public class VIBEModelTester extends AbstractWorkbenchTester {
bot.button(2).click();
bot.table().select("CHARTRAN_ELECTRICAL_THERMAL_DRIVER");
bot.button("OK").click();
// bot.table(1).select(8);
// bot.text(11).typeText("Test");
bot.table(1).select(8);
bot.text(12).typeText("Test");
bot.button(2).click();
bot.table().select("NTG");
bot.button("OK").click();
// bot.table(1).select(9);
// bot.text(13).typeText("Test");
bot.table(1).select(9);
bot.text(14).typeText("Test");
bot.button(2).click();
bot.table().select("DUALFOIL");
......@@ -197,9 +193,21 @@ public class VIBEModelTester extends AbstractWorkbenchTester {
// table to see if it was added instead.
assertEquals(11, bot.table(1).rowCount());
bot.button(2).click();
bot.table().select("AMPERES");
bot.button("OK").click();
bot.table(1).select(11);
bot.text(14).typeText("Test");
bot.button(2).click();
bot.table().select("CHARTRAN_THERMAL_DRIVER");
bot.button("OK").click();
bot.table(1).select(12);
bot.text(10).typeText("Test");
// Delete a row and make sure it's gone
bot.table().select(0);
bot.button("Delete").click();
assertTrue("11 DUALFOIL".equals(bot.table(1).cell(9, 0)));
assertTrue("11 DUALFOIL".equals(bot.table(1).cell(10, 0)));
}
}
/*******************************************************************************
* 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.vibe.kvPair.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.datastructures.entry.StringEntry;
import org.eclipse.ice.vibe.kvPair.VibeKVPairRow;
import org.junit.Test;
/**
* A class to test the functionality of the VibeKVPairRow
*
* @author Robert Smith
*
*/
public class VibeKVPairRowTester {
/**
* Test that rows can be cloned and copied.
*/
@Test
public void checkClone() {
// Initialize the test row
StringEntry testKey = new StringEntry();
StringEntry testValue = new StringEntry();
VibeKVPairRow row = new VibeKVPairRow(testKey, testValue);
// Set some values to the row
testKey.setValue("key");
testValue.setValue("value");
row.setName("row");
// Initialize another row
VibeKVPairRow copyRow = new VibeKVPairRow(new StringEntry(),
new StringEntry());
// Copy the first row's data into the second
copyRow.copy(row);
// Check that the data members were all copied correctly
assertTrue("key".equals(copyRow.getKey().getValue()));
assertTrue("value".equals(copyRow.getValue().getValue()));
assertTrue("row".equals(copyRow.getName()));
// Clone the row
VibeKVPairRow clone = (VibeKVPairRow) row.clone();
// Check that the data members were all copied correctly
assertTrue("key".equals(clone.getKey().getValue()));
assertTrue("value".equals(clone.getValue().getValue()));
assertTrue("row".equals(clone.getName()));
}
/**
* Check that the getters and setters for the class work correctly.
*/
@Test
public void checkSetters() {
// Initiailze the test row
StringEntry testKey = new StringEntry();
StringEntry testValue = new StringEntry();
VibeKVPairRow row = new VibeKVPairRow(testKey, testValue);
// Check that the key and value entries are correct
assertTrue(testKey == row.getKey());
assertTrue(testValue == row.getValue());
// Check the context methods
row.setContext("context");
assertTrue("context".equals(row.getContext()));
// Check the description methods
row.setDescription("description");
assertTrue("description".equals(row.getDescription()));
// Check the ID methods
row.setId(2);
assertEquals(2, row.getId());
// Check the name methods
row.setName("name");
assertTrue("name".equals(row.getName()));
}
/**
* Test the row's ability to give and receive updates
*/
@Test
public void checkUpdate() {
// Initiailze the test row
StringEntry testKey = new StringEntry();
StringEntry testValue = new StringEntry();
VibeKVPairRow row = new VibeKVPairRow(testKey, testValue);
// Add a listener
TestListener listener = new TestListener(row);
listener.wasUpdated();
// Update the value and make sure that the listener was notified.
testValue.setValue("test");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Exception while waiting for update.");
}
assertTrue(listener.wasUpdated());
}
/**
* A simple class to listen to a VibeKVPairRow and record when it sends an
* update.
*
* @author Robert Smith
*
*/
private class TestListener implements IUpdateableListener {
/**
* Whether or not this object has received an update since the last time
* it was checked.
*/
private boolean updated = false;
public TestListener(VibeKVPairRow row) {
row.register(this);
}
/**
* Checks whether the listener was updated since the last time this
* message was called
*
* @return True if update() was called since the last time this method
* was invoked. False otherwise.
*/
public boolean wasUpdated() {
boolean temp = updated;
updated = false;
return temp;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.datastructures.ICEObject.IUpdateableListener#update(
* org.eclipse.ice.datastructures.ICEObject.IUpdateable)
*/
@Override
public void update(IUpdateable component) {
updated = true;
}
}
}
......@@ -17,6 +17,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
......@@ -26,8 +28,11 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.ice.datastructures.ICEObject.Component;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.datastructures.form.TableComponent;
import org.eclipse.ice.vibe.kvPair.VibeKVPair;
import org.junit.AfterClass;
import org.junit.BeforeClass;
......@@ -138,6 +143,119 @@ public class VibeKVPairTester {
vibeKVPair.getDescription());
}
/**
* Test that changing the template will set the table up appropriately.
*/
@Test
public void checkTemplates() {
VibeKVPair vibeKVPair;
IProject project = projectSpace;
// Create a VibeLauncher
vibeKVPair = new VibeKVPair(project);
// The components from the item's form.
ArrayList<Component> components = vibeKVPair.getForm().getComponents();
// The component containing the table Key-Value pairs
TableComponent table = null;
// The component containing the problem templates
DataComponent template = null;
// Search the list of components, saving them to the approrpiate
// variables
for (Component component : components) {
// The template component will be the only DataComponent
if (component instanceof DataComponent) {
template = (DataComponent) component;
}
// The table will be the only TableComponent
else if (component instanceof TableComponent) {
table = (TableComponent) component;
}
}
// Whether or not the CUTOFF key was found in the table
boolean foundCutoff = false;
// Search for the CUTOFF key in each of the tables rows
for (int id : table.getRowIds()) {
if ("CUTOFF".equals(table.getRow(id).get(0).getValue())) {
foundCutoff = true;
break;
}
}
// If the CUTOFF key was absent, then the table was not set up correctly
if (!foundCutoff) {
fail("Did not find CUTOFF row in default table.");
}
// Set the item to the DualFoil template
template.retrieveAllEntries().get(0).setValue("DualFoil");
// Give the form time to load the new data
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
// Whether the CUTOFFL key was found in the table
boolean foundL = false;
// Whether the CUTOFFH key was found in the table
boolean foundH = false;
// Search each row of the table for the DualFoil keys
for (int id : table.getRowIds()) {
// Get the value of the current key-value pair's row
String value = table.getRow(id).get(0).getValue();
if ("CUTOFFL".equals(value)) {
foundL = true;
} else if ("CUTOFFH".equals(value)) {
foundH = true;
}
}
// If the expected keys were not found, then the DualFoil template was
// not properly applied to the table
if (!foundL || !foundH) {
fail("Table was not changed to DualFoil template.");
}
// Set the template back to NTG
template.retrieveAllEntries().get(0).setValue("NTG");
// Give the form time to load the new data
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
// Search for the CUTOFF key in each of the tables rows
foundCutoff = false;
for (int id : table.getRowIds()) {
if ("CUTOFF".equals(table.getRow(id).get(0).getValue())) {
foundCutoff = true;
break;
}
}
// If the CUTOFF key was absent, then the table was not set up correctly
if (!foundCutoff) {
fail("Table was not changed to NTG template.");
}
}
/**
* Try processing the form with both valid and invalid
*/
......
......@@ -131,7 +131,7 @@ public class VibeKVPairRow implements IUpdateable, IUpdateableListener {