Search in sources :

Example 51 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class AutosaveGraphPluginNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    graph = new DualGraph(schema);
    WritableGraph wg = graph.getWritableGraph("Autosave", true);
    try {
        attrX = VisualConcept.VertexAttribute.X.ensure(wg);
        attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
        attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
        vAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        tAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        vxId1 = wg.addVertex();
        wg.setFloatValue(attrX, vxId1, 1.0f);
        wg.setFloatValue(attrY, vxId1, 1.0f);
        wg.setBooleanValue(vAttrId, vxId1, false);
        vxId2 = wg.addVertex();
        wg.setFloatValue(attrX, vxId2, 5.0f);
        wg.setFloatValue(attrY, vxId2, 1.0f);
        wg.setBooleanValue(vAttrId, vxId2, true);
        vxId3 = wg.addVertex();
        wg.setFloatValue(attrX, vxId3, 1.0f);
        wg.setFloatValue(attrY, vxId3, 5.0f);
        wg.setBooleanValue(vAttrId, vxId3, false);
        vxId4 = wg.addVertex();
        wg.setFloatValue(attrX, vxId4, 5.0f);
        wg.setFloatValue(attrY, vxId4, 5.0f);
        wg.setBooleanValue(vAttrId, vxId4, false);
        vxId5 = wg.addVertex();
        wg.setFloatValue(attrX, vxId5, 10.0f);
        wg.setFloatValue(attrY, vxId5, 10.0f);
        wg.setBooleanValue(vAttrId, vxId5, true);
        vxId6 = wg.addVertex();
        wg.setFloatValue(attrX, vxId6, 15.0f);
        wg.setFloatValue(attrY, vxId6, 15.0f);
        vxId7 = wg.addVertex();
        wg.setFloatValue(attrX, vxId7, 100.0f);
        wg.setFloatValue(attrY, vxId7, 100.0f);
        txId1 = wg.addTransaction(vxId1, vxId2, false);
        txId2 = wg.addTransaction(vxId1, vxId3, false);
        txId3 = wg.addTransaction(vxId2, vxId4, true);
        txId4 = wg.addTransaction(vxId4, vxId2, true);
        txId5 = wg.addTransaction(vxId5, vxId6, false);
    } finally {
        wg.commit();
    }
}
Also used : Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 52 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class SimpleEditPlugin method run.

@Override
public final void run(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException, RuntimeException {
    boolean inControlOfProgress = true;
    final Graph graph = graphs.getGraph();
    // graph no longer exists
    if (graph == null) {
        LOGGER.log(Level.WARNING, "Null graph not allowed in a {0}", SimpleEditPlugin.class.getSimpleName());
        return;
    }
    // Make the graph appear busy
    interaction.setBusy(graph.getId(), true);
    try {
        // Make the progress bar appear nondeterminent
        interaction.setProgress(0, 0, WAITING_INTERACTION, true);
        try {
            boolean cancelled = false;
            Object description = null;
            WritableGraph writableGraph = graph.getWritableGraph(getName(), isSignificant(), this);
            try {
                interaction.setProgress(0, 0, "Editing...", true);
                try {
                    description = describedEdit(writableGraph, interaction, parameters);
                    if (!"Editing...".equals(interaction.getCurrentMessage())) {
                        inControlOfProgress = false;
                    }
                } catch (final Exception ex) {
                    cancelled = true;
                    throw ex;
                }
            } finally {
                if (cancelled) {
                    writableGraph.rollBack();
                } else {
                    writableGraph.commit(description);
                }
            }
        } finally {
            interaction.setProgress(2, 1, inControlOfProgress ? "Finished" : interaction.getCurrentMessage(), true);
        }
    } finally {
        interaction.setBusy(graph.getId(), false);
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException)

Example 53 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class QualityControlStateUpdaterNGTest method testReadSelectedNodesWithRules.

@Test
public void testReadSelectedNodesWithRules() throws Exception {
    System.out.println("read Selected Nodes With Rules");
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    WritableGraph wg = graph.getWritableGraph("Add Elements", true);
    try {
        // Add X,Y,Z vertex attributes
        attrX = VisualConcept.VertexAttribute.X.ensure(wg);
        attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
        attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
        // Add vertex and transaction SELECTED attributes
        vSelectedAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        tSelectedAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        // Add two vertices
        vxId1 = wg.addVertex();
        vxId2 = wg.addVertex();
        // Add one transaction between the two vertices
        txId1 = wg.addTransaction(vxId1, vxId2, false);
        wg.setFloatValue(attrX, vxId1, 1.0f);
        wg.setFloatValue(attrY, vxId1, 1.0f);
        wg.setBooleanValue(vSelectedAttrId, vxId1, false);
        wg.setFloatValue(attrX, vxId2, 2.0f);
        wg.setFloatValue(attrY, vxId2, 2.0f);
        wg.setBooleanValue(vSelectedAttrId, vxId1, true);
        // Add vertex IDENTIFIER attribute and label each vertice.
        vxIdentifierAttrId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
        wg.setStringValue(vxIdentifierAttrId, vxId1, "Vertex1");
        wg.setStringValue(vxIdentifierAttrId, vxId2, "Vertex2");
        // Add vertex TYPE attribute and set each type to unknown
        typeAttrId = AnalyticConcept.VertexAttribute.TYPE.ensure(wg);
        wg.setObjectValue(typeAttrId, vxId1, SchemaVertexType.unknownType());
        wg.setObjectValue(typeAttrId, vxId2, SchemaVertexType.unknownType());
    } finally {
        wg.commit();
    }
    // Expected rules
    final List<QualityControlRule> expectedRegisteredRules = new ArrayList<>(Lookup.getDefault().lookupAll(QualityControlRule.class));
    // generate list of vertex ids
    final List<Integer> vertexIds = new ArrayList<>();
    vertexIds.add(0);
    vertexIds.add(1);
    // Check rules against vertex ids
    for (final QualityControlRule rule : expectedRegisteredRules) {
        rule.executeRule(graph.getReadableGraph(), vertexIds);
    }
    final List<QualityControlEvent> expectedQualityControlEvents = new ArrayList<>();
    expectedQualityControlEvents.add(new QualityControlEvent(0, "Vertex1", SchemaVertexType.unknownType(), expectedRegisteredRules));
    // Call update state to trigger checking of rules
    PluginExecution.withPlugin(new QualityControlStateUpdater()).executeNow(graph);
    // get the state and events
    final QualityControlState state = QualityControlAutoVetter.getInstance().getQualityControlState();
    final List<QualityControlEvent> qualityControlEvents = state.getQualityControlEvents();
    final List<QualityControlRule> registeredRules = state.getRegisteredRules();
    // Loop all events and check equality for each item specifically. Testing equality of the list was taken literally.
    assertEquals(qualityControlEvents.size(), expectedQualityControlEvents.size());
    int i = 0;
    for (QualityControlEvent event : expectedQualityControlEvents) {
        if (qualityControlEvents.size() >= i) {
            assertEquals(qualityControlEvents.get(i).getReasons(), event.getReasons());
            assertEquals(qualityControlEvents.get(i).getQuality(), event.getQuality());
            assertEquals(qualityControlEvents.get(i).getVertex(), event.getVertex());
            assertEquals(qualityControlEvents.get(i).getRules(), event.getRules());
            assertEquals(qualityControlEvents.get(i).getType(), event.getType());
        }
        i++;
    }
    // check equality of the rules
    assertEquals(registeredRules, expectedRegisteredRules);
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 54 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class GraphVisualAccessNGTest method testGetCameraAttributeAdded.

/**
 * Test of getCamera method when attribute is added, of class
 * GraphVisualAccess.
 *
 * @throws InterruptedException
 */
@Test
public void testGetCameraAttributeAdded() throws InterruptedException {
    System.out.println("getCameraAttributeAdded");
    final WritableGraph wg = graph.getWritableGraph("Graph Visual Access", true);
    try {
        final int graphCameraAttribute = VisualConcept.GraphAttribute.CAMERA.ensure(wg);
        final Camera newCamera = new Camera();
        newCamera.setVisibilityHigh(0.6f);
        wg.setObjectValue(graphCameraAttribute, 0, newCamera);
    } finally {
        wg.commit();
    }
    final GraphVisualAccess instance = new GraphVisualAccess(graph);
    instance.beginUpdate();
    instance.updateInternally();
    final Camera camera = instance.getCamera();
    instance.endUpdate();
    assertEquals(camera.getVisibilityHigh(), 0.6f);
}
Also used : Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 55 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class MergeNodeNGTest method mergeTwoTest.

// TODO: commenting out the unit test for now as it fails when run through a headless execution
// /**
// * Use this when running unit tests that requires a DialogDisplay and X11 is
// * not configured
// */
// @ServiceProviders({
// @ServiceProvider(service = DialogDisplayer.class, position = 1)
// })
// public static class DialogDisplayerForUnitTests extends DialogDisplayer {
// 
// @Override
// public Object notify(NotifyDescriptor descriptor) {
// System.out.println(descriptor.getMessage());
// return null;
// }
// 
// @Override
// public Dialog createDialog(DialogDescriptor descriptor) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
// }
// 
// }
// 
// @Test
// public void mergeNothingTest() throws InterruptedException, PluginException {
// final GraphNode graphNode1 = new GraphNode(graph, null, new TopComponent(), null);
// WritableGraph wg = graph.getWritableGraph("merge", false);
// try {
// assertEquals("Transaction count", 5, wg.getTransactionCount());
// assertEquals("Node count", 7, wg.getVertexCount());
// 
// PluginExecution.withPlugin(CorePluginRegistry.PERMANENT_NODE_MERGE)
// .withParameter(PermanentMergePlugin.SELECTED_NODES_PARAMETER_ID, new ArrayList<>())
// .withParameter(PermanentMergePlugin.ATTTRIBUTES_PARAMETER_ID, null)
// .executeNow(wg);
// 
// assertEquals("Transaction count", 5, wg.getTransactionCount());
// assertEquals("Node count", 7, wg.getVertexCount());
// } finally {
// wg.commit();
// }
// }
// 
// @Test
// public void mergeOneTest() throws InterruptedException, PluginException {
// final GraphNode graphNode1 = new GraphNode(graph, null, new TopComponent(), null);
// WritableGraph wg = graph.getWritableGraph("merge", false);
// try {
// assertEquals("Transaction count", 5, wg.getTransactionCount());
// assertEquals("Node count", 7, wg.getVertexCount());
// 
// ArrayList<Integer> list = new ArrayList<>();
// list.add(vxId7);
// 
// PluginExecution.withPlugin(CorePluginRegistry.PERMANENT_NODE_MERGE)
// .withParameter(PermanentMergePlugin.SELECTED_NODES_PARAMETER_ID, list)
// .withParameter(PermanentMergePlugin.ATTTRIBUTES_PARAMETER_ID, null)
// .executeNow(wg);
// 
// assertEquals("Transaction count", 5, wg.getTransactionCount());
// assertEquals("Node count", 7, wg.getVertexCount());
// } finally {
// wg.commit();
// }
// }
@Test
public void mergeTwoTest() throws InterruptedException, PluginException {
    WritableGraph wg = graph.getWritableGraph("merge", false);
    try {
        assertEquals("Transaction count", 5, wg.getTransactionCount());
        assertEquals("Node count", 7, wg.getVertexCount());
        ArrayList<Integer> list = new ArrayList<>();
        list.add(vxId5);
        list.add(vxId6);
        HashMap<Integer, String> values = new HashMap<>();
        values.put(attrX, "123.0");
        values.put(attrY, "456.0");
        values.put(attrZ, "789.0");
        PluginExecution.withPlugin(VisualGraphPluginRegistry.PERMANENT_MERGE).withParameter(PermanentMergePlugin.SELECTED_NODES_PARAMETER_ID, list).withParameter(PermanentMergePlugin.ATTTRIBUTES_PARAMETER_ID, values).executeNow(wg);
        assertEquals("Transaction count", 5, wg.getTransactionCount());
        assertEquals("Node count", 6, wg.getVertexCount());
        assertFalse("node 5 has been eliminated", this.nodeExists(wg, 10.0f, 10.0f, 0.0f));
        assertFalse("node 6 has been eliminated", this.nodeExists(wg, 15.0f, 15.0f, 0.0f));
        assertTrue("new node has been created", this.nodeExists(wg, 123.0f, 456.0f, 789.0f));
    } finally {
        wg.commit();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Aggregations

WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)116 Test (org.testng.annotations.Test)77 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)39 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)37 Graph (au.gov.asd.tac.constellation.graph.Graph)20 ArrayList (java.util.ArrayList)14 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)8 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)6 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 Attribute (au.gov.asd.tac.constellation.graph.Attribute)5 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)5 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 DuplicateKeyException (au.gov.asd.tac.constellation.graph.DuplicateKeyException)3 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)3