Search in sources :

Example 11 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class DataAccessViewTopComponentNGTest method componentShowing.

@Test(enabled = false)
public void componentShowing() {
    final GraphManager graphManager = mock(GraphManager.class);
    final Graph graph = mock(Graph.class);
    when(graphManager.getActiveGraph()).thenReturn(graph);
    final DataAccessViewTopComponent spiedTopComponent = spy(dataAccessViewTopComponent);
    doNothing().when(spiedTopComponent).handleNewGraph(graph);
    try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        spiedTopComponent.componentShowing();
        verify(spiedTopComponent).handleNewGraph(graph);
    }
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Graph(au.gov.asd.tac.constellation.graph.Graph) Test(org.testng.annotations.Test)

Example 12 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class DataAccessPaneNGTest method update_active_graph_present.

@Test
public void update_active_graph_present() {
    doNothing().when(dataAccessPane).update(isNull(String.class));
    doNothing().when(dataAccessPane).update(isNull(Graph.class));
    try (final MockedStatic<GraphManager> graphManageMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        final GraphManager graphManager = mock(GraphManager.class);
        graphManageMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        final Graph graph = mock(Graph.class);
        when(graphManager.getActiveGraph()).thenReturn(graph);
        when(graph.getId()).thenReturn("graphId");
        dataAccessPane.update();
        verify(dataAccessPane).update("graphId");
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 13 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class DataAccessPaneNGTest method update_active_graph_not_present.

@Test
public void update_active_graph_not_present() {
    doNothing().when(dataAccessPane).update(isNull(String.class));
    try (final MockedStatic<GraphManager> graphManageMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        final GraphManager graphManager = mock(GraphManager.class);
        graphManageMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        when(graphManager.getActiveGraph()).thenReturn(null);
        dataAccessPane.update();
        verify(dataAccessPane).update((String) null);
    }
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 14 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class FindViewControllerNGTest method testPopulateAttributes.

/**
 * Test of populateAttributes method, of class FindViewController.
 */
@Test
public void testPopulateAttributes() {
    System.out.println("populateAttributes");
    /**
     * Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
     * (2 of type string), 3 transaction attributes (2 of type string)
     */
    setupGraph();
    /**
     * Create a mock of the top component, get an intsance of the
     * controller, create a mock of the graph manager, when getAllGraphs is
     * called return the graphMap created in this class
     */
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    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);
        List<Attribute> attributes = new ArrayList<>();
        GraphElementType type = GraphElementType.VERTEX;
        List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        assertEquals(result.get(0), "Label");
        assertEquals(result.get(1), "Identifier");
        assertEquals(result.size(), 2);
        type = GraphElementType.TRANSACTION;
        result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        assertEquals(result.get(0), "Label");
        assertEquals(result.get(1), "Identifier");
        assertEquals(result.size(), 2);
        type = GraphElementType.EDGE;
        result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        assertEquals(result.size(), 0);
    }
// TODO review the generated test code and remove the default call to fail.
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 15 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class FindViewControllerNGTest method testRetriveMatchingElements.

/**
 * Test of retriveMatchingElements method, of class FindViewController.
 */
@Test
public void testRetriveMatchingElements() {
    System.out.println("retriveMatchingElements");
    /**
     * Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
     * (2 of type string), 3 transaction attributes (2 of type string)
     */
    setupGraph();
    /**
     * Create a mock of the top component, get an instance of the
     * controller, create a mock of the graph manager, when getAllGraphs is
     * called return the graphMap created in this class
     */
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    when(gm.getActiveGraph()).thenReturn(graph);
    System.out.println("before try");
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        System.out.println("in try");
        try (MockedStatic<PluginExecution> mockedStaticPlugin = Mockito.mockStatic(PluginExecution.class)) {
            PluginExecution pluginExecution = mock(PluginExecution.class);
            /**
             * The first test should execute the plugin once on graph as the
             * parameters are not set to look at all graphs
             */
            when(pluginExecution.executeLater(Mockito.eq(graph))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.retriveMatchingElements(true, false);
            verify(pluginExecution).executeLater(Mockito.eq(graph));
            /**
             * Set the parameters to find in all graphs and repeat the same
             * process. The plugin should be executed on graph a second
             * time, and should be executed on graph2 for the first time.
             */
            instance.updateBasicFindParameters(parametersAllGraphs);
            when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.retriveMatchingElements(true, false);
            verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
            verify(pluginExecution).executeLater(Mockito.eq(graph2));
        }
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Aggregations

GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)20 Test (org.testng.annotations.Test)15 Graph (au.gov.asd.tac.constellation.graph.Graph)11 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)4 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)4 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)4 ArrayList (java.util.ArrayList)4 Attribute (au.gov.asd.tac.constellation.graph.Attribute)3 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)3 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)2 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)2 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)2 FindViewTopComponent (au.gov.asd.tac.constellation.views.find2.FindViewTopComponent)2 UserTablePreferences (au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2