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);
}
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"));
}
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);
}
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());
}
}
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));
}
}
Aggregations