use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.
the class BasicFindTabNGTest method testPopulateAttributes.
/**
* Test of populateAttributes method, of class BasicFindTab.
*/
@Test
public void testPopulateAttributes() {
System.out.println("populateAttributes");
setupGraph();
/**
* Add the vertex label and identifier attribute to the selected vertex
* attribute list
*/
basicFindTab.selectedNodeAttributes.add(labelAttributeV);
basicFindTab.selectedNodeAttributes.add(identifierAttributeV);
/**
* Add the transaction label attribute to the selected vertex attribute
* list
*/
basicFindTab.selectedTransAttributes.add(labelAttributeT);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
// Call the populateAttributes function with the type VERTEX
GraphElementType elementType = GraphElementType.VERTEX;
basicFindTab.populateAttributes(elementType);
/**
* As both the label and identifier attributes were in the selected
* vertex attribute list. Both should be checked in the
* inAttributesMenu
*/
assertEquals(basicFindTab.inAttributesMenu.getCheckModel().isChecked(labelAttributeV.getName()), true);
assertEquals(basicFindTab.inAttributesMenu.getCheckModel().isChecked(identifierAttributeV.getName()), true);
/**
* Clear the current selections, and calls the populateAttribute
* function with Transactions
*/
basicFindTab.inAttributesMenu.getCheckModel().clearChecks();
elementType = GraphElementType.TRANSACTION;
basicFindTab.populateAttributes(elementType);
/**
* As only the label attribute was selected in the selected
* transaction attributes list. Only the label should be selected
*/
assertEquals(basicFindTab.inAttributesMenu.getCheckModel().isChecked(labelAttributeT.getName()), true);
assertEquals(basicFindTab.inAttributesMenu.getCheckModel().isChecked(identifierAttributeT.getName()), false);
/**
* Repeat the same for vertex again to show the vertex attributes
* remain selected when calling the populateAttribute function
*/
basicFindTab.inAttributesMenu.getCheckModel().clearChecks();
elementType = GraphElementType.VERTEX;
basicFindTab.populateAttributes(elementType);
assertEquals(basicFindTab.inAttributesMenu.getCheckModel().isChecked(labelAttributeV.getName()), true);
assertEquals(basicFindTab.inAttributesMenu.getCheckModel().isChecked(identifierAttributeV.getName()), true);
}
}
use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.
the class PreferenceMenuNGTest method verifySavePreferencesAction.
/**
* Verifies that when the save userTablePreferences button is pressed then
* it will call out to
* {@link TableViewPreferencesIoProvider#savePreferences(GraphElementType, TableView, int)}.
* If certain values are not set, then it will not save the preferences and
* just return.
* <p/>
* There is a lot of mock setup for this so the code tries to re-use as much
* of that as possible which is why its a little weird.
*
* @param savePreferencesMenu the save userTablePreferences menu
* @param isTableViewColumnsEmpty true if when
* {@link TableView#getColumns()} is called it should return an empty list,
* false otherwise
* @param isActivGraphNull true if when
* {@link GraphManager#getActiveGraph()} is called it should return null,
* false otherwise
* @param expectSavePrefsCalled true if it is expected that
* {@link TableViewPreferencesIoProvider#savePreferences(GraphElementType, TableView, int)}
* should have been called, false otherwise
*/
private void verifySavePreferencesAction(final MenuItem savePreferencesMenu, final boolean isTableViewColumnsEmpty, final boolean isActivGraphNull, final boolean expectSavePrefsCalled) {
try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefsIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class);
final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
final TableView<ObservableList<String>> tableView = mock(TableView.class);
when(table.getTableView()).thenReturn(tableView);
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(GraphElementType.VERTEX);
when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(42);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
final GraphManager graphManager = mock(GraphManager.class);
graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
final Graph graph = mock(Graph.class);
final ActionEvent actionEvent = mock(ActionEvent.class);
if (isTableViewColumnsEmpty) {
when(tableView.getColumns()).thenReturn(FXCollections.observableArrayList());
} else {
when(tableView.getColumns()).thenReturn(FXCollections.observableArrayList(mock(TableColumn.class)));
}
if (isActivGraphNull) {
when(graphManager.getActiveGraph()).thenReturn(null);
} else {
when(graphManager.getActiveGraph()).thenReturn(graph);
}
savePreferencesMenu.getOnAction().handle(actionEvent);
if (expectSavePrefsCalled) {
tablePrefsIOUtilsMockedStatic.verify(() -> TableViewPreferencesIoProvider.savePreferences(GraphElementType.VERTEX, tableView, 42));
} else {
tablePrefsIOUtilsMockedStatic.verifyNoInteractions();
}
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.
the class LayersViewControllerNGTest method testRemoveBitmaskFromElements.
/**
* Test of removeBitmaskFromElements method, of class LayersViewController.
*/
@Test
public void testRemoveBitmaskFromElements() {
System.out.println("removeBitmaskFromElements");
// Setup a graph with elements
setupGraph();
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getActiveGraph()).thenReturn(graph);
// Create mock of DataAccessPane to return the query phase pane mock
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
WritableGraph wg;
try {
wg = graph.getWritableGraph("", true);
// Check Vertex set correctly
assertEquals(wg.getIntValue(layerMaskV, vxId1), 1);
assertEquals(wg.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertFalse(wg.getBooleanValue(selectedV, vxId1));
assertEquals(wg.getIntValue(layerMaskV, vxId2), 1);
assertEquals(wg.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertFalse(wg.getBooleanValue(selectedV, vxId2));
// Check Transaction set correctly
assertEquals(wg.getIntValue(layerMaskT, vxId1), 1);
assertEquals(wg.getFloatValue(layerVisibilityT, vxId1), 1.0f);
assertFalse(wg.getBooleanValue(selectedT, vxId1));
assertEquals(wg.getIntValue(layerMaskT, vxId2), 1);
assertEquals(wg.getFloatValue(layerVisibilityT, vxId2), 1.0f);
assertFalse(wg.getBooleanValue(selectedT, vxId2));
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
// remove bitmask from elements - nothing should be on layer 5
int currentIndex = 5;
LayersViewController instance = LayersViewController.getDefault().init(null);
instance.removeBitmaskFromElements(currentIndex);
try {
wg = graph.getWritableGraph("", true);
// Check Vertex unchanged
assertEquals(wg.getIntValue(layerMaskV, vxId1), 1);
assertEquals(wg.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertFalse(wg.getBooleanValue(selectedV, vxId1));
assertEquals(wg.getIntValue(layerMaskV, vxId2), 1);
assertEquals(wg.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertFalse(wg.getBooleanValue(selectedV, vxId2));
// Check Transaction set correctly
assertEquals(wg.getIntValue(layerMaskT, vxId1), 1);
assertEquals(wg.getFloatValue(layerVisibilityT, vxId1), 1.0f);
assertFalse(wg.getBooleanValue(selectedT, vxId1));
assertEquals(wg.getIntValue(layerMaskT, vxId2), 1);
assertEquals(wg.getFloatValue(layerVisibilityT, vxId2), 1.0f);
assertFalse(wg.getBooleanValue(selectedT, vxId2));
// Set vx2 and tx2 into layer 2. Both are visibility 0 because current layer is 1.
wg.setIntValue(layerMaskV, vxId2, 0b11);
wg.setFloatValue(layerVisibilityV, vxId2, 0.0f);
wg.setIntValue(layerMaskT, txId2, 0b11);
wg.setFloatValue(layerVisibilityT, txId2, 0.0f);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
// remove bitmask from elements - should only remove the elements vx2 and tx2
currentIndex = 1;
instance.removeBitmaskFromElements(currentIndex);
try {
wg = graph.getWritableGraph("", true);
// Check Vertex 1 unchanged
assertEquals(wg.getIntValue(layerMaskV, vxId1), 1);
assertEquals(wg.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertFalse(wg.getBooleanValue(selectedV, vxId1));
// Check Vertex 2 changed - visibility 0.0 because no visibility update
assertEquals(wg.getIntValue(layerMaskV, vxId2), 1);
assertEquals(wg.getFloatValue(layerVisibilityV, vxId2), 0.0f);
assertFalse(wg.getBooleanValue(selectedV, vxId2));
// Check Transaction 1 unchanged
assertEquals(wg.getIntValue(layerMaskT, vxId1), 1);
assertEquals(wg.getFloatValue(layerVisibilityT, vxId1), 1.0f);
assertFalse(wg.getBooleanValue(selectedT, vxId1));
assertEquals(wg.getIntValue(layerMaskT, vxId2), 1);
assertEquals(wg.getFloatValue(layerVisibilityT, vxId2), 0.0f);
assertFalse(wg.getBooleanValue(selectedT, vxId2));
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
}
use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.
the class LayersViewControllerNGTest method testRemoveBitmaskFromElementsEmptyGraph.
/**
* Verify that no elements are added to the graph when an empty graph is
* used
*/
@Test
public void testRemoveBitmaskFromElementsEmptyGraph() {
System.out.println("removeBitmaskFromElements_EmptyGraph");
setupEmptyGraph();
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getActiveGraph()).thenReturn(graph);
// Create mock of DataAccessPane to return the query phase pane mock
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
ReadableGraph rg = graph.getReadableGraph();
assertEquals(rg.getVertexCount(), 0);
rg.close();
// remove bitmask from elements - nothing should be on layer 5
int currentIndex = 5;
LayersViewController instance = LayersViewController.getDefault().init(null);
instance.removeBitmaskFromElements(currentIndex);
ReadableGraph rg2 = graph.getReadableGraph();
assertEquals(rg2.getVertexCount(), 0);
rg2.close();
currentIndex = 1;
instance.removeBitmaskFromElements(currentIndex);
ReadableGraph rg3 = graph.getReadableGraph();
assertEquals(rg3.getVertexCount(), 0);
rg3.close();
}
}
use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.
the class TableViewTopComponentNGTest method componentShowing.
@Test
public void componentShowing() throws InterruptedException {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
doCallRealMethod().when(tableViewTopComponent).componentShowing();
doNothing().when(tableViewTopComponent).handleNewGraph(any(Graph.class));
try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
final GraphManager graphManager = mock(GraphManager.class);
final Graph activeGraph = mock(Graph.class);
graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
when(graphManager.getActiveGraph()).thenReturn(activeGraph);
tableViewTopComponent.componentShowing();
verify(tableViewTopComponent).handleNewGraph(activeGraph);
}
}
Aggregations