Search in sources :

Example 41 with PluginInteraction

use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.

the class SelectTopNNGTest method testEditWithNothingSelected.

/**
 * Test of edit method, of class SelectTopNPlugin.
 *
 * @throws java.lang.Exception
 */
@Test(expectedExceptions = PluginException.class)
public void testEditWithNothingSelected() throws Exception {
    final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
    final int vertexLabelAttr = VisualConcept.VertexAttribute.LABEL.ensure(graph);
    final int vertexSelectedAttr = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    final int vertexTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    final int transactionTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
    final int vx0 = graph.addVertex();
    graph.setStringValue(vertexLabelAttr, vx0, "foo");
    graph.setBooleanValue(vertexSelectedAttr, vx0, false);
    final PluginInteraction interaction = new TextPluginInteraction();
    final SelectTopNPlugin instance = new SelectTopNPlugin();
    final PluginParameters parameters = instance.createParameters();
    instance.edit(graph, interaction, parameters);
}
Also used : PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 42 with PluginInteraction

use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.

the class SelectTopNNGTest method testEditWithTopTwoLocationsContainingDifferentTransactionTypes.

@Test
public void testEditWithTopTwoLocationsContainingDifferentTransactionTypes() throws Exception {
    final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
    final int vertexLabelAttr = VisualConcept.VertexAttribute.LABEL.ensure(graph);
    final int vertexSelectedAttr = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    final int vertexTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    final int transactionTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
    final int sourceVxId = graph.addVertex();
    graph.setStringValue(vertexLabelAttr, sourceVxId, "source");
    graph.setBooleanValue(vertexSelectedAttr, sourceVxId, true);
    // buildId the graph
    for (int i = 0; i < 2; i++) {
        final int desintationVxId = graph.addVertex();
        graph.setStringValue(vertexLabelAttr, desintationVxId, String.format("destination %s", i));
        for (int j = i; j < 10; j++) {
            int txId = graph.addTransaction(sourceVxId, desintationVxId, true);
            graph.setObjectValue(transactionTypeAttr, txId, AnalyticConcept.TransactionType.COMMUNICATION.getName());
        }
    }
    for (int i = 3; i < 10; i++) {
        final int desintationVxId = graph.addVertex();
        graph.setStringValue(vertexLabelAttr, desintationVxId, String.format("destination %s", i));
        for (int j = i; j < 10; j++) {
            int txId = graph.addTransaction(sourceVxId, desintationVxId, true);
            graph.setObjectValue(transactionTypeAttr, txId, AnalyticConcept.TransactionType.NETWORK);
        }
    }
    final PluginInteraction interaction = new TextPluginInteraction();
    final SelectTopNPlugin instance = new SelectTopNPlugin();
    final PluginParameters parameters = instance.createParameters();
    parameters.getParameters().get(SelectTopNPlugin.MODE_PARAMETER_ID).setStringValue(SelectTopNPlugin.TRANSACTION);
    parameters.getParameters().get(SelectTopNPlugin.TYPE_CATEGORY_PARAMETER_ID).setStringValue(AnalyticConcept.TransactionType.COMMUNICATION.getName());
    // TYPE_PARAMETER will always be of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> subTypeParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(SelectTopNPlugin.TYPE_PARAMETER_ID);
    final List<String> arrayList = new ArrayList<>();
    arrayList.add(AnalyticConcept.TransactionType.COMMUNICATION.getName());
    MultiChoiceParameterType.setChoices(subTypeParameter, arrayList);
    parameters.getParameters().get(SelectTopNPlugin.LIMIT_PARAMETER_ID).setIntegerValue(2);
    instance.edit(graph, interaction, parameters);
    assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId));
    assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + 1));
    assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + 2));
    for (int i = 3; i < 10; i++) {
        assertFalse(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + i));
    }
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 43 with PluginInteraction

use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.

the class MergeTransactionsPluginNGTest method testEditUnknownType.

/**
 * Test of edit method with an unknown merge transaction type
 *
 * @throws Exception
 */
@Test(expectedExceptions = PluginException.class)
public void testEditUnknownType() throws Exception {
    MergeTransactionsPlugin instance = new MergeTransactionsPlugin();
    PluginInteraction interaction = new TextPluginInteraction();
    PluginParameters parameters = instance.createParameters();
    parameters.getParameters().get(MergeTransactionsPlugin.MERGE_TYPE_PARAMETER_ID).setStringValue("None");
    instance.edit(graph, interaction, parameters);
}
Also used : PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) Test(org.testng.annotations.Test)

Example 44 with PluginInteraction

use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.

the class MergeTransactionsPluginNGTest method testEdit.

/**
 * Test of edit method, of class MergeTransactionsPlugin.
 *
 * @throws Exception
 */
@Test
public void testEdit() throws Exception {
    MergeTransactionsPlugin instance = new MergeTransactionsPlugin();
    PluginInteraction interaction = new TextPluginInteraction();
    PluginParameters parameters = instance.createParameters();
    parameters.getParameters().get(MergeTransactionsPlugin.THRESHOLD_PARAMETER_ID).setIntegerValue(5);
    parameters.getParameters().get(MergeTransactionsPlugin.MERGE_TYPE_PARAMETER_ID).setStringValue("DateTime");
    parameters.getParameters().get(MergeTransactionsPlugin.LEAD_PARAMETER_ID).setEnabled(true);
    parameters.getParameters().get(MergeTransactionsPlugin.SELECTED_PARAMETER_ID).setBooleanValue(true);
    instance.edit(graph, interaction, parameters);
    // Check that the transactions were merged
    assertEquals(graph.getTransactionCount(), 3);
    assertEquals(graph.getTransaction(txId1), 1);
    assertEquals(graph.getTransaction(txId3), 2);
    assertEquals(graph.getTransaction(txId4), 3);
}
Also used : PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) Test(org.testng.annotations.Test)

Example 45 with PluginInteraction

use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.

the class GraphAttributePluginNGTest method testRead.

/**
 * Test of read method, of class GraphAttributePlugin.
 */
@Test
public void testRead() throws Exception {
    System.out.println("read");
    setupGraph();
    PluginInteraction interaction = mock(PluginInteraction.class);
    PluginParameters pluginParameters = mock(PluginParameters.class);
    WritableGraph wg = graph.getWritableGraph("", true);
    GraphElementType type = GraphElementType.VERTEX;
    GraphAttributePlugin graphAttributePlugin = new GraphAttributePlugin(type, attributeList, amc);
    int selectedInt = wg.getAttribute(type, 0);
    Attribute selectedAttribute = new GraphAttribute(wg, selectedInt);
    int labelInt = wg.getAttribute(type, 1);
    Attribute labelAttribute = new GraphAttribute(wg, labelInt);
    int identifierInt = wg.getAttribute(type, 2);
    Attribute identifierAttribute = new GraphAttribute(wg, identifierInt);
    int xInt = wg.getAttribute(type, 3);
    Attribute xAttribute = new GraphAttribute(wg, xInt);
    List<Attribute> expectedList = new ArrayList<>();
    expectedList.add(selectedAttribute);
    expectedList.add(labelAttribute);
    expectedList.add(identifierAttribute);
    expectedList.add(xAttribute);
    /**
     * The attributeList should contain all the avalible attributes of the
     * given type that exist on the graph. It should contain the selected,
     * label, identifier and x attributes as they are the vertex attributes
     * the graph has been set with.
     */
    graphAttributePlugin.read(wg, interaction, pluginParameters);
    assertEquals(attributeList, expectedList);
    wg.commit();
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Aggregations

PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)51 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)44 Test (org.testng.annotations.Test)33 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)16 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)15 ArrayList (java.util.ArrayList)15 TextPluginInteraction (au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction)14 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)13 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)9 Graph (au.gov.asd.tac.constellation.graph.Graph)8 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)8 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)8 List (java.util.List)8 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)7 PluginInfo (au.gov.asd.tac.constellation.plugins.PluginInfo)7 PluginTags (au.gov.asd.tac.constellation.plugins.templates.PluginTags)7 SimpleEditPlugin (au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin)7 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)6