Search in sources :

Example 16 with PluginParameter

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

the class MergeNodesPluginNGTest method editNoMergeOptionSelected.

@Test(expectedExceptions = PluginException.class)
public void editNoMergeOptionSelected() throws InterruptedException, PluginException {
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    final PluginInteraction interaction = mock(PluginInteraction.class);
    final PluginParameters parameters = mock(PluginParameters.class);
    final PluginParameter pluginParameter = mock(PluginParameter.class);
    final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", pluginParameter);
    when(parameters.getParameters()).thenReturn(pluginParameters);
    when(pluginParameter.getStringValue()).thenReturn(null);
    mergeNodesPlugin.edit(graph, interaction, parameters);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 17 with PluginParameter

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

the class MergeNodesPluginNGTest method createParameters.

@Test
public void createParameters() {
    final PluginParameters actual = mergeNodesPlugin.createParameters();
    final Map<String, PluginParameter<?>> parameters = actual.getParameters();
    assertEquals(parameters.keySet(), Set.of("MergeNodesPlugin.merge_type", "MergeNodesPlugin.threshold", "MergeNodesPlugin.merger", "MergeNodesPlugin.lead", "MergeNodesPlugin.selected"));
    final PluginParameter<SingleChoiceParameterValue> mergeTypeParameter = (PluginParameter<SingleChoiceParameterValue>) parameters.get("MergeNodesPlugin.merge_type");
    assertEquals(mergeTypeParameter.getName(), "Merge By");
    assertEquals(mergeTypeParameter.getDescription(), "Nodes will be merged based on this");
    assertEquals(mergeTypeParameter.getParameterValue().getOptions(), List.of(TestMergeType.NAME, "Geospatial Distance", "Identifier Prefix Length", "Identifier Suffix Length", "Supported Type"));
    assertEquals(mergeTypeParameter.getProperty("choices").getClass(), Object.class);
    final PluginParameter<IntegerParameterValue> thresholdParameter = (PluginParameter<IntegerParameterValue>) parameters.get("MergeNodesPlugin.threshold");
    assertEquals(thresholdParameter.getName(), "Threshold");
    assertEquals(thresholdParameter.getDescription(), "The maximum nodes to merge");
    assertFalse(thresholdParameter.isEnabled());
    final PluginParameter<SingleChoiceParameterValue> mergingRuleParameter = (PluginParameter<SingleChoiceParameterValue>) parameters.get("MergeNodesPlugin.merger");
    assertEquals(mergingRuleParameter.getName(), "Merging Rule");
    assertEquals(mergingRuleParameter.getDescription(), "The rule deciding how attributes are merged");
    assertEquals(mergingRuleParameter.getParameterValue().getOptions(), List.of("Retain lead vertex attributes if present", "Retain lead vertex attributes always", "Copy merged vertex attributes if present", "Copy merged vertex attributes always"));
    assertEquals(mergingRuleParameter.getProperty("choices").getClass(), Object.class);
    assertEquals(mergingRuleParameter.getParameterValue().getChoice(), "Retain lead vertex attributes if present");
    assertFalse(mergingRuleParameter.isEnabled());
    final PluginParameter<SingleChoiceParameterValue> leadNodeParameter = (PluginParameter<SingleChoiceParameterValue>) parameters.get("MergeNodesPlugin.lead");
    assertEquals(leadNodeParameter.getName(), "Lead Node");
    assertEquals(leadNodeParameter.getDescription(), "The rule deciding how to choose the lead node");
    assertEquals(leadNodeParameter.getParameterValue().getOptions(), List.of("Longest Value", "Shortest Value", "Ask Me"));
    assertEquals(leadNodeParameter.getProperty("choices").getClass(), Object.class);
    assertEquals(leadNodeParameter.getParameterValue().getChoice(), "Longest Value");
    assertFalse(leadNodeParameter.isEnabled());
    final PluginParameter<BooleanParameterValue> selectedOnlyParameter = (PluginParameter<BooleanParameterValue>) parameters.get("MergeNodesPlugin.selected");
    assertEquals(selectedOnlyParameter.getName(), "Selected Only");
    assertEquals(selectedOnlyParameter.getDescription(), "Merge Only Selected Nodes");
    assertTrue(selectedOnlyParameter.getBooleanValue());
    assertFalse(selectedOnlyParameter.isEnabled());
    final Map<String, PluginParameterController> controllers = actual.getControllers();
    assertEquals(controllers.keySet(), Set.of("MergeNodesPlugin.merge_type"));
}
Also used : BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameterController(au.gov.asd.tac.constellation.plugins.parameters.PluginParameterController) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Test(org.testng.annotations.Test)

Example 18 with PluginParameter

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

the class MergeNodesPluginNGTest method editMergeNodeTypeNotFound.

@Test(expectedExceptions = PluginException.class)
public void editMergeNodeTypeNotFound() throws InterruptedException, PluginException {
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    final PluginInteraction interaction = mock(PluginInteraction.class);
    final PluginParameters parameters = mock(PluginParameters.class);
    final PluginParameter pluginParameter = mock(PluginParameter.class);
    final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", pluginParameter);
    when(parameters.getParameters()).thenReturn(pluginParameters);
    when(pluginParameter.getStringValue()).thenReturn("Something Random");
    mergeNodesPlugin.edit(graph, interaction, parameters);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 19 with PluginParameter

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

the class TestParametersPluginNGTest method testGraphElementType1.

/**
 * Test of query method, of class TestParametersPlugin. Tests throwing
 * runtime exception
 */
@Test
public void testGraphElementType1() throws Exception {
    System.out.println("test graph element type1");
    final TestParametersPlugin instance = new TestParametersPlugin();
    final PluginParameters result = instance.createParameters();
    // Set plugin query name here before execution
    result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
    // Set plugin parameters here before execution
    final GraphElementTypeParameterValue graphElementType = new GraphElementTypeParameterValue();
    assertTrue(graphElementType.set(GraphElementType.META));
    // return false when setting same attribute
    assertFalse(graphElementType.set(GraphElementType.META));
    assertTrue(graphElementType.setObjectValue(GraphElementType.VERTEX));
    // return false when setting same attribute
    assertFalse(graphElementType.setObjectValue(GraphElementType.VERTEX));
    for (final GraphElementType elementType : GraphElementType.values()) {
        graphElementType.setObjectValue(elementType);
        result.getParameters().get(TestParametersPlugin.ELEMENT_TYPE_PARAMETER_ID).setObjectValue(graphElementType);
        // Ensure it is still selected as the correct value
        assertEquals(SingleChoiceParameterType.getChoice((PluginParameter<SingleChoiceParameterType.SingleChoiceParameterValue>) result.getParameters().get(TestParametersPlugin.ELEMENT_TYPE_PARAMETER_ID)), elementType.getShortLabel());
    }
}
Also used : SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) GraphElementTypeParameterValue(au.gov.asd.tac.constellation.views.dataaccess.plugins.experimental.TestParametersPlugin.GraphElementTypeParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 20 with PluginParameter

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

the class SelectTopNNGTest method testEditWithTopTwoLocationsContainingDifferentTypes.

@Test
public void testEditWithTopTwoLocationsContainingDifferentTypes() 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);
    graph.setObjectValue(vertexTypeAttr, sourceVxId, AnalyticConcept.VertexType.COUNTRY);
    // buildId the graph
    for (int i = 0; i < 2; i++) {
        final int desintationVxId = graph.addVertex();
        graph.setStringValue(vertexLabelAttr, desintationVxId, String.format("destination %s", i));
        graph.setObjectValue(vertexTypeAttr, desintationVxId, AnalyticConcept.VertexType.COUNTRY);
        for (int j = i; j < 10; j++) {
            graph.addTransaction(sourceVxId, desintationVxId, true);
        }
    }
    for (int i = 3; i < 10; i++) {
        final int desintationVxId = graph.addVertex();
        graph.setStringValue(vertexLabelAttr, desintationVxId, String.format("destination %s", i));
        graph.setObjectValue(vertexTypeAttr, desintationVxId, AnalyticConcept.VertexType.DOCUMENT);
        for (int j = i; j < 10; j++) {
            graph.addTransaction(sourceVxId, desintationVxId, true);
        }
    }
    final PluginInteraction interaction = new TextPluginInteraction();
    final SelectTopNPlugin instance = new SelectTopNPlugin();
    final PluginParameters parameters = instance.createParameters();
    parameters.getParameters().get(SelectTopNPlugin.MODE_PARAMETER_ID).setStringValue(SelectTopNPlugin.NODE);
    parameters.getParameters().get(SelectTopNPlugin.TYPE_CATEGORY_PARAMETER_ID).setStringValue(AnalyticConcept.VertexType.LOCATION.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.VertexType.COUNTRY.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)

Aggregations

PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)93 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)53 Test (org.testng.annotations.Test)52 ArrayList (java.util.ArrayList)36 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)25 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)21 Map (java.util.Map)16 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)15 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)11 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)11 Graph (au.gov.asd.tac.constellation.graph.Graph)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)10 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)10 HashMap (java.util.HashMap)10 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)9 List (java.util.List)9 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)8 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)8