use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class SelectTopNNGTest method testEditWithTopTwoLocationsAndEverythingIsGci.
@Test
public void testEditWithTopTwoLocationsAndEverythingIsGci() 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 < 10; 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);
}
}
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));
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class SelectTopNNGTest method testEditWithTopFiveLocationsWithEqualCounts.
@Test
public void testEditWithTopFiveLocationsWithEqualCounts() 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 < 5; 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 = 0; j < 5; 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(5);
instance.edit(graph, interaction, parameters);
for (int i = 0; i < 5; i++) {
assertTrue(graph.getBooleanValue(vertexSelectedAttr, i));
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class SelectTopNNGTest method testEditWithNoResults.
@Test
public void testEditWithNoResults() 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, 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);
assertEquals(1, graph.getVertexCount());
assertTrue(graph.getBooleanValue(vertexSelectedAttr, vx0));
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class SelectTopNNGTest method testEditWithTopTwoContactsAndEverythingIsCommunicationTransactions.
@Test
public void testEditWithTopTwoContactsAndEverythingIsCommunicationTransactions() 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 < 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.COMMUNICATION.getName());
}
}
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));
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState.
@Test
public void loadDataAccessState() {
// Create current data access view state and set some parameters
// The code currenly only looks at the first tab so parameter2
// value will be ignored
final DataAccessState currentState = new DataAccessState();
currentState.newTab();
currentState.add("parameter1", "parameter1_new_value");
currentState.newTab();
currentState.add("parameter2", "parameter2_new_value");
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(currentState);
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final TabPane tabPane = mock(TabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters globalPluginParameters = mock(PluginParameters.class);
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
verify(pluginParameter1).setStringValue("parameter1_new_value");
verify(pluginParameter2, never()).setStringValue(anyString());
verify(rGraph).release();
}
}
Aggregations