use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class UndoRedoNGTest method addNode.
// @Test
// public void undoTwoOperationsTest() throws InterruptedException {
// final boolean[] canUndo = new boolean[4];
// final boolean[] canRedo = new boolean[4];
// final boolean[] undoNamesMatch = new boolean[3];
// final boolean[] redoNamesMatch = new boolean[2];
//
// checkBaseElements();
// checkElementCount(7, 5);
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[0] = undoMgr.canUndo();
// canRedo[0] = undoMgr.canRedo();
// undoNamesMatch[0] = "Undo original load".equals(undoMgr.getUndoPresentationName());
// });
// } catch (InterruptedException | InvocationTargetException ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[0]);
// assertFalse("redo not available", canRedo[0]);
// assertTrue("last undo", undoNamesMatch[0]);
//
// addNode();
//
// checkElementCount(8, 5);
// checkNewNode();
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[1] = undoMgr.canUndo();
// canRedo[1] = undoMgr.canRedo();
// undoNamesMatch[1] = "Undo add vertex".equals(undoMgr.getUndoPresentationName());
// });
// } catch (InterruptedException | InvocationTargetException ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[1]);
// assertFalse("redo not available", canRedo[1]);
// assertTrue("Next undo", undoNamesMatch[0]);
//
// graph.undo();
//
// checkElementCount(7, 5);
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[2] = undoMgr.canUndo();
// canRedo[2] = undoMgr.canRedo();
// undoNamesMatch[2] = "Undo original load".equals(undoMgr.getUndoPresentationName());
// redoNamesMatch[0] = "Redo add vertex".equals(undoMgr.getRedoPresentationName());
// });
// } catch (InterruptedException | InvocationTargetException ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[2]);
// assertTrue("redo available", canRedo[2]);
// assertTrue("Next undo", undoNamesMatch[2]);
// assertTrue("Next redo", redoNamesMatch[0]);
//
// graph.undo();
//
// checkElementCount(0, 0);
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[3] = undoMgr.canUndo();
// canRedo[3] = undoMgr.canRedo();
// redoNamesMatch[1] = "Redo original load".equals(undoMgr.getRedoPresentationName());
// });
// } catch (InterruptedException | InvocationTargetException ex) {
// assertFalse(ex.toString(), false);
// }
// assertFalse("undo not available", canUndo[3]);
// assertTrue("redo available", canRedo[3]);
// assertTrue("Next redo", redoNamesMatch[1]);
// }
// @Test
// public void vertexUndoRedoTest() throws InterruptedException {
// final boolean[] canUndo = new boolean[4];
// final boolean[] canRedo = new boolean[4];
// final boolean[] undoNamesMatch = new boolean[4];
// final boolean[] redoNamesMatch = new boolean[1];
//
// checkBaseElements();
// checkElementCount(7, 5);
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[0] = undoMgr.canUndo();
// canRedo[0] = undoMgr.canRedo();
// undoNamesMatch[0] = "Undo original load".equals(undoMgr.getUndoPresentationName());
// });
// } catch (InterruptedException | InvocationTargetException ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[0]);
// assertFalse("redo not available", canRedo[0]);
// assertTrue("last undo", undoNamesMatch[0]);
//
// addNode();
//
// checkElementCount(8, 5);
// checkNewNode();
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[1] = undoMgr.canUndo();
// canRedo[1] = undoMgr.canRedo();
// undoNamesMatch[1] = "Undo add vertex".equals(undoMgr.getUndoPresentationName());
// });
// } catch (Exception ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[1]);
// assertFalse("redo not available", canRedo[1]);
// assertTrue("last undo", undoNamesMatch[1]);
//
// graph.undo();
//
// checkElementCount(7, 5);
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[2] = undoMgr.canUndo();
// canRedo[2] = undoMgr.canRedo();
// undoNamesMatch[2] = "Undo original load".equals(undoMgr.getUndoPresentationName());
// redoNamesMatch[0] = "Redo add vertex".equals(undoMgr.getRedoPresentationName());
// });
// } catch (Exception ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[2]);
// assertTrue("redo available", canRedo[2]);
// assertTrue("last undo", undoNamesMatch[2]);
// assertTrue("last redo", redoNamesMatch[0]);
//
// graph.redo();
//
// checkElementCount(8, 5);
// checkNewNode();
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[3] = undoMgr.canUndo();
// canRedo[3] = undoMgr.canRedo();
// undoNamesMatch[3] = "Undo add vertex".equals(undoMgr.getUndoPresentationName());
// });
// } catch (Exception ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[3]);
// assertFalse("redo not available", canRedo[3]);
// assertTrue("last undo", undoNamesMatch[3]);
// }
// @Test
// public void undoOneOperationsTest() throws InterruptedException {
// final boolean[] canUndo = new boolean[3];
// final boolean[] canRedo = new boolean[3];
// final boolean[] undoNamesMatch = new boolean[3];
// final boolean[] redoNamesMatch = new boolean[1];
//
// checkBaseElements();
// checkElementCount(7, 5);
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[0] = undoMgr.canUndo();
// canRedo[0] = undoMgr.canRedo();
// undoNamesMatch[0] = "Undo original load".equals(undoMgr.getUndoPresentationName());
// });
// } catch (Exception ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[0]);
// assertFalse("redo not available", canRedo[0]);
// assertTrue("last undo", undoNamesMatch[0]);
//
// addNode();
//
// checkElementCount(8, 5);
// checkNewNode();
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[1] = undoMgr.canUndo();
// canRedo[1] = undoMgr.canRedo();
// undoNamesMatch[1] = "Undo add vertex".equals(undoMgr.getUndoPresentationName());
// });
// } catch (Exception ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[1]);
// assertFalse("redo not available", canRedo[1]);
// assertTrue("Next undo", undoNamesMatch[1]);
//
// graph.undo();
//
// checkElementCount(7, 5);
// checkBaseElements();
// try {
// SwingUtilities.invokeAndWait(() -> {
// canUndo[2] = undoMgr.canUndo();
// canRedo[2] = undoMgr.canRedo();
// undoNamesMatch[2] = "Undo original load".equals(undoMgr.getUndoPresentationName());
// redoNamesMatch[0] = "Redo add vertex".equals(undoMgr.getRedoPresentationName());
// });
// } catch (Exception ex) {
// assertFalse(ex.toString(), false);
// }
// assertTrue("undo available", canUndo[2]);
// assertTrue("redo available", canRedo[2]);
// assertTrue("Next undo", undoNamesMatch[2]);
// assertTrue("Next redo", redoNamesMatch[0]);
//
// checkBaseElements();
// }
// add new node
private void addNode() throws InterruptedException {
WritableGraph wg = graph.getWritableGraph("add vertex", true);
try {
int id = wg.addVertex();
wg.setFloatValue(attrX, id, 126.0f);
wg.setFloatValue(attrY, id, 126.60f);
wg.setBooleanValue(vSelAttr, id, true);
wg.setStringValue(vNameAttr, id, "name10");
} finally {
wg.commit();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class UndoRedoNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
graph = new DualGraph(null);
undoMgr = new UndoManager();
graph.setUndoManager(undoMgr);
WritableGraph wg = graph.getWritableGraph("original load", true);
try {
attrX = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", 0.0, null);
if (attrX == Graph.NOT_FOUND) {
fail();
}
attrY = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "y", "y", 0.0, null);
if (attrY == Graph.NOT_FOUND) {
fail();
}
attrZ = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "z", "z", 0.0, null);
if (attrZ == Graph.NOT_FOUND) {
fail();
}
vNameAttr = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
if (vNameAttr == Graph.NOT_FOUND) {
fail();
}
tNameAttr = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
if (tNameAttr == Graph.NOT_FOUND) {
fail();
}
vSelAttr = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
if (vSelAttr == Graph.NOT_FOUND) {
fail();
}
tSelAttr = wg.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
if (tSelAttr == Graph.NOT_FOUND) {
fail();
}
vxId1 = wg.addVertex();
wg.setFloatValue(attrX, vxId1, 1.0f);
wg.setFloatValue(attrY, vxId1, 1.0f);
wg.setBooleanValue(vSelAttr, vxId1, false);
wg.setStringValue(vNameAttr, vxId1, "name1");
vxId2 = wg.addVertex();
wg.setFloatValue(attrX, vxId2, 5.0f);
wg.setFloatValue(attrY, vxId2, 1.0f);
wg.setBooleanValue(vSelAttr, vxId2, true);
wg.setStringValue(vNameAttr, vxId2, "name2");
vxId3 = wg.addVertex();
wg.setFloatValue(attrX, vxId3, 1.0f);
wg.setFloatValue(attrY, vxId3, 5.0f);
wg.setBooleanValue(vSelAttr, vxId3, false);
wg.setStringValue(vNameAttr, vxId3, "name3");
vxId4 = wg.addVertex();
wg.setFloatValue(attrX, vxId4, 5.0f);
wg.setFloatValue(attrY, vxId4, 5.4f);
wg.setBooleanValue(vSelAttr, vxId4, true);
wg.setStringValue(vNameAttr, vxId4, "name4");
vxId5 = wg.addVertex();
wg.setFloatValue(attrX, vxId5, 15.0f);
wg.setFloatValue(attrY, vxId5, 15.5f);
wg.setBooleanValue(vSelAttr, vxId5, false);
wg.setStringValue(vNameAttr, vxId5, "name5");
vxId6 = wg.addVertex();
wg.setFloatValue(attrX, vxId6, 26.0f);
wg.setFloatValue(attrY, vxId6, 26.60f);
wg.setBooleanValue(vSelAttr, vxId6, true);
wg.setStringValue(vNameAttr, vxId6, "name6");
vxId7 = wg.addVertex();
wg.setFloatValue(attrX, vxId7, 37.0f);
wg.setFloatValue(attrY, vxId7, 37.7f);
wg.setBooleanValue(vSelAttr, vxId7, false);
wg.setStringValue(vNameAttr, vxId7, "name7");
txId1 = wg.addTransaction(vxId1, vxId2, true);
wg.setBooleanValue(tSelAttr, txId1, false);
wg.setStringValue(tNameAttr, txId1, "name101");
txId2 = wg.addTransaction(vxId1, vxId3, true);
wg.setBooleanValue(tSelAttr, txId2, true);
wg.setStringValue(tNameAttr, txId2, "name102");
txId3 = wg.addTransaction(vxId2, vxId4, true);
wg.setBooleanValue(tSelAttr, txId3, false);
wg.setStringValue(tNameAttr, txId3, "name103");
txId4 = wg.addTransaction(vxId4, vxId2, true);
wg.setBooleanValue(tSelAttr, txId4, true);
wg.setStringValue(tNameAttr, txId4, "name104");
txId5 = wg.addTransaction(vxId5, vxId6, true);
wg.setBooleanValue(tSelAttr, txId5, false);
wg.setStringValue(tNameAttr, txId5, "name105");
} finally {
wg.commit();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class UpdateNGTest method multiRollback.
@Test
public void multiRollback() {
try {
final DualGraph g = new DualGraph(null);
final WritableGraph wg = g.getWritableGraph("", true);
wg.rollBack();
try {
wg.rollBack();
} catch (IllegalMonitorStateException ex) {
System.out.printf("%s\n", ex);
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class UpdateNGTest method createTransactionToNonexistentDestination.
// /**
// * This test is strange: sometimes it fails (and sometimes with a
// * CannotUndoException, sometimes with a NullPointerException), sometimes it
// * doesn't.
// */
// @Test
// public void rollbackNaN() {
// final float defaultValue = 3;
// try {
// final DualGraph g = new DualGraph(null);
// g.setUndoManager(new UndoRedo.Manager());
// final WritableGraph wg = g.getWritableGraph("add stuff", true);
// int attrId, vxId;
// try {
// attrId = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", defaultValue, null);
// vxId = wg.addVertex();
// } finally {
// wg.commit();
// }
//
// final WritableGraph wg2 = g.getWritableGraph("set NaN", true);
// try {
// wg2.setFloatValue(attrId, vxId, Float.NaN);
// } finally {
// wg2.commit();
// }
//
// // Update the graph.
// final ReadableGraph rg = g.getReadableGraph();
// float v;
// try {
// v = rg.getFloatValue(attrId, vxId);
// } finally {
// rg.release();
// }
// assertTrue("should be Nan", Float.isNaN(v));
//
// // Undo the update: should go back to the previous value.
// try {
// SwingUtilities.invokeAndWait(() -> {
// g.undo();
// });
// } catch (InterruptedException | InvocationTargetException ex) {
// }
//
// final ReadableGraph rg2 = g.getReadableGraph();
// float v2;
// try {
// v2 = rg2.getFloatValue(attrId, vxId);
// } finally {
// rg2.release();
// }
// assertEquals(defaultValue, v2);
// } catch (InterruptedException ex) {
// Exceptions.printStackTrace(ex);
// }
// }
@Test
public void createTransactionToNonexistentDestination() {
final DualGraph g = new DualGraph(null);
g.setUndoManager(new UndoRedo.Manager());
WritableGraph wg = null;
try {
wg = g.getWritableGraph("Tx test", true);
for (int i = 0; i < 100; i++) {
final String s = String.format("x%d", i);
wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, s, s, 0, null);
}
int vx = 0;
for (int i = 0; i < 100; i++) {
vx = wg.addVertex();
}
final int tx = wg.addTransaction(vx, vx + 1, true);
Assert.fail("Shouldn't get here, wg.addTransaction() should fail.");
} catch (IllegalArgumentException ex) {
// Expected result.
System.out.printf("Expected exception: %s\n", ex.getMessage());
// ex.printStackTrace(System.out);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
if (wg != null) {
wg.rollBack();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class UpdateNGTest method rollingBack.
@Test
public void rollingBack() {
try {
final DualGraph g = new DualGraph(null);
final WritableGraph wg = g.getWritableGraph("", true);
final int af;
final int ac;
final int v;
try {
af = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", 0, null);
ac = wg.addAttribute(GraphElementType.VERTEX, IntegerAttributeDescription.ATTRIBUTE_NAME, "level", "description", null, null);
v = wg.addVertex();
wg.setFloatValue(af, v, 2.71828f);
wg.setStringValue(ac, v, "3");
} finally {
wg.commit();
}
final WritableGraph wgr = g.getWritableGraph("", true);
try {
final int vr = wgr.addVertex();
wgr.setFloatValue(af, vr, 99);
wgr.setStringValue(ac, vr, "5");
// throw new Exception();
} finally {
wgr.rollBack();
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
Aggregations