Search in sources :

Example 1 with DualGraph

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

the class ExtractWordsFromTextPluginNGTest method testUpdateParameters.

/**
 * Test updateParameters
 */
@Test
public void testUpdateParameters() {
    ExtractWordsFromTextPlugin instance = new ExtractWordsFromTextPlugin();
    PluginParameters parameters = new PluginParameters();
    final PluginParameter<SingleChoiceParameterValue> attributeType = SingleChoiceParameterType.build(ATTRIBUTE_PARAMETER_ID);
    parameters.addParameter(attributeType);
    final PluginParameter<StringParameterValue> textParameter = StringParameterType.build(WORDS_PARAMETER_ID);
    textParameter.setStringValue("text");
    parameters.addParameter(textParameter);
    final PluginParameter<BooleanParameterValue> useRegexParameter = BooleanParameterType.build(USE_REGEX_PARAMETER_ID);
    useRegexParameter.setBooleanValue(true);
    parameters.addParameter(useRegexParameter);
    Graph graph1 = new DualGraph(graph.getSchema(), graph);
    instance.updateParameters(graph1, parameters);
    assertEquals(parameters.getParameters().size(), 3);
    assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.ATTRIBUTE_PARAMETER_ID));
    assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.WORDS_PARAMETER_ID).getStringValue(), "text");
    assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.USE_REGEX_PARAMETER_ID).getBooleanValue(), true);
    assertFalse(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
    parameters = instance.createParameters();
    instance.updateParameters(graph1, parameters);
    assertEquals(parameters.getParameters().size(), 11);
    assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 2 with DualGraph

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

the class SelectAllPluginNGTest method testEdit0.

/**
 * Test of edit method, of class SelectAllPlugin. select all edit with only
 * attributes on graph
 */
@Test
public void testEdit0() throws Exception {
    System.out.println("select all edit with nothing on graph but attributes");
    // Open a new graph
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    int vxCount = 0;
    int txCount = 0;
    final WritableGraph wg = graph.getWritableGraph("TEST", true);
    try {
        // Create Selected Attributes
        selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
    } finally {
        wg.commit();
    }
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
    // Verify no extra elements are added
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        assertEquals(rg.getVertexCount(), vxCount);
        assertEquals(rg.getTransactionCount(), txCount);
    } finally {
        rg.close();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 3 with DualGraph

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

the class SelectAllPluginNGTest method testEdit4.

/**
 * Test of edit method, of class SelectAllPlugin. select all edit with a
 * graph that has no selected element via its schema, but contains elements.
 *
 * Should throw a pluginexception
 */
@Test(expectedExceptions = PluginException.class)
public void testEdit4() throws Exception {
    System.out.println("select all edit with no selected attribute on graph, but with elements");
    // Open a new graph
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(BareSchemaFactory.NAME).createSchema());
    int vxCount = 0;
    int txCount = 0;
    final WritableGraph wg = graph.getWritableGraph("TEST", true);
    try {
        // Add vertices
        vxId1 = wg.addVertex();
        vxId2 = wg.addVertex();
        // Add transactions
        txId1 = wg.addTransaction(vxId1, vxId2, true);
        txId2 = wg.addTransaction(vxId2, vxId1, false);
        vxCount = wg.getVertexCount();
        txCount = wg.getTransactionCount();
        // ensure both values are stored
        assertEquals(vxCount, 2);
        assertEquals(txCount, 2);
    } finally {
        wg.commit();
    }
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
}
Also used : DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 4 with DualGraph

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

the class SelectAllPluginNGTest method testEdit2.

/**
 * Test of edit method, of class SelectAllPlugin. select all edit with both
 * vx and tx on graph
 */
@Test
public void testEdit2() throws Exception {
    System.out.println("select all edit with vx and tx on graph");
    // Open a new graph
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    int vxCount = 0;
    int txCount = 0;
    final WritableGraph wg = graph.getWritableGraph("TEST", true);
    try {
        // Create Selected Attributes
        selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        // Add vertices
        vxId1 = wg.addVertex();
        vxId2 = wg.addVertex();
        // Add transactions
        txId1 = wg.addTransaction(vxId1, vxId2, true);
        txId2 = wg.addTransaction(vxId2, vxId1, false);
        // check default value is unselected
        assertFalse(wg.getBooleanValue(selectedV, vxId1));
        assertFalse(wg.getBooleanValue(selectedV, vxId2));
        assertFalse(wg.getBooleanValue(selectedV, txId1));
        assertFalse(wg.getBooleanValue(selectedV, txId2));
        vxCount = wg.getVertexCount();
        txCount = wg.getTransactionCount();
    } finally {
        wg.commit();
    }
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
    // Verify both selected and same amount of vx and tx are present
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        assertTrue(rg.getBooleanValue(selectedV, vxId1));
        assertTrue(rg.getBooleanValue(selectedV, vxId2));
        assertTrue(rg.getBooleanValue(selectedV, txId1));
        assertTrue(rg.getBooleanValue(selectedV, txId2));
        assertEquals(rg.getVertexCount(), vxCount);
        assertEquals(rg.getTransactionCount(), txCount);
    } finally {
        rg.close();
    }
    // rerun plugin to ensure values are not only toggled, but are set explicitly as selected
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
    // Verify both selected and same amount of vx and tx are present
    final ReadableGraph rg2 = graph.getReadableGraph();
    try {
        assertTrue(rg2.getBooleanValue(selectedV, vxId1));
        assertTrue(rg2.getBooleanValue(selectedV, vxId2));
        assertTrue(rg.getBooleanValue(selectedV, txId1));
        assertTrue(rg.getBooleanValue(selectedV, txId2));
        assertEquals(rg2.getVertexCount(), vxCount);
        assertEquals(rg.getTransactionCount(), txCount);
    } finally {
        rg2.close();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 5 with DualGraph

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

the class RecordStoreQueryPluginNGTest method testEdit.

/**
 * Test of edit method, of class RecordStoreQueryPlugin.
 */
@Test
public void testEdit() throws InterruptedException, PluginException {
    System.out.println("edit");
    final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    // only using a dual graph because of the need to pass a GraphWriteMethods graph to the edit() method.
    final Graph graph = new DualGraph(schema);
    final PluginInteraction interaction = null;
    final PluginParameters parameters = null;
    ReadableGraph rg = graph.getReadableGraph();
    try {
        instance.read(rg, interaction, parameters);
        instance.query(interaction, parameters);
    } finally {
        rg.release();
    }
    GraphRecordStore query;
    rg = graph.getReadableGraph();
    try {
        query = GraphRecordStoreUtilities.getAll(rg, false, false);
    } finally {
        rg.release();
    }
    final WritableGraph wg = graph.getWritableGraph("", true);
    try {
        VisualConcept.VertexAttribute.X.ensure(wg);
        VisualConcept.VertexAttribute.Y.ensure(wg);
        VisualConcept.VertexAttribute.Z.ensure(wg);
        VisualConcept.GraphAttribute.CAMERA.ensure(wg);
        instance.edit(wg, interaction, parameters);
    } finally {
        wg.commit();
    }
    rg = graph.getReadableGraph();
    try {
        query = GraphRecordStoreUtilities.getTransactions(rg, false, false);
    } finally {
        rg.release();
    }
    // verify nothing has moved
    query.reset();
    query.next();
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "20.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "20.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "20.0");
    query.next();
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "40.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "40.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "40.0");
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Aggregations

DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)66 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)41 Test (org.testng.annotations.Test)30 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)21 Graph (au.gov.asd.tac.constellation.graph.Graph)19 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)18 ArrayList (java.util.ArrayList)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)10 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)10 BeforeMethod (org.testng.annotations.BeforeMethod)9 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)7 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)3 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)3 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)3