Search in sources :

Example 11 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessParametersIoProviderNGTest method loadParameters.

@Test
public void loadParameters() throws IOException {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    final QueryPhasePane tab1 = mock(QueryPhasePane.class);
    final QueryPhasePane tab2 = mock(QueryPhasePane.class);
    when(dataAccessTabPane.newTab(anyString())).thenReturn(tab1).thenReturn(tab2);
    final GlobalParametersPane globalParametersPane1 = mock(GlobalParametersPane.class);
    final GlobalParametersPane globalParametersPane2 = mock(GlobalParametersPane.class);
    when(tab1.getGlobalParametersPane()).thenReturn(globalParametersPane1);
    when(tab2.getGlobalParametersPane()).thenReturn(globalParametersPane2);
    // By adding the settings bit here, it forces mockito to generate two different
    // classes. Otherwise they would be two different objects but have the same class name
    final Plugin plugin1 = mock(Plugin.class, withSettings().extraInterfaces(Comparable.class));
    final Plugin plugin2 = mock(Plugin.class, withSettings().extraInterfaces(Serializable.class));
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane1.getPlugin()).thenReturn(plugin1);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin2);
    when(tab1.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
    when(tab2.getDataAccessPanes()).thenReturn(List.of());
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    when(pluginParameter1.getId()).thenReturn("param1");
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameter2.getId()).thenReturn("param2");
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    when(pluginParameter3.getId()).thenReturn("param3");
    final PluginParameter pluginParameter4 = mock(PluginParameter.class);
    when(pluginParameter4.getId()).thenReturn("param4");
    final PluginParameters globalPluginParameters1 = new PluginParameters();
    globalPluginParameters1.addParameter(pluginParameter1);
    globalPluginParameters1.addParameter(pluginParameter2);
    globalPluginParameters1.addParameter(pluginParameter3);
    final PluginParameters globalPluginParameters2 = new PluginParameters();
    globalPluginParameters2.addParameter(pluginParameter3);
    globalPluginParameters2.addParameter(pluginParameter4);
    when(globalParametersPane1.getParams()).thenReturn(globalPluginParameters1);
    when(globalParametersPane2.getParams()).thenReturn(globalPluginParameters2);
    try (final MockedStatic<JsonIO> jsonIOStaticMock = Mockito.mockStatic(JsonIO.class)) {
        final ObjectMapper objectMapper = new ObjectMapper();
        final String json = IOUtils.toString(new FileInputStream(getClass().getResource("resources/preferences.json").getPath()), StandardCharsets.UTF_8);
        // We do not know the mockito plugin names ahead of time so substitute them in now
        final StringSubstitutor substitutor = new StringSubstitutor(Map.of("INSERT_PLUGIN1_NAME", plugin1.getClass().getSimpleName(), "INSERT_PLUGIN2_NAME", plugin2.getClass().getSimpleName()));
        final List<DataAccessUserPreferences> preferences = objectMapper.readValue(substitutor.replace(json), new TypeReference<List<DataAccessUserPreferences>>() {
        });
        jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("DataAccessView")), any(TypeReference.class))).thenReturn(preferences);
        DataAccessParametersIoProvider.loadParameters(dataAccessPane);
    }
    verify(dataAccessTabPane, times(2)).newTab(anyString());
    // tab1 global parameters
    verify(pluginParameter1).setStringValue("tab1_param1_value");
    verify(pluginParameter3).setStringValue(null);
    // tab1 plugin parameters - only plugin1 because plugin2 is disabled
    verify(dataSourceTitledPane1).setParameterValues(Map.of(plugin1.getClass().getSimpleName() + "." + "__is_enabled__", "true", plugin1.getClass().getSimpleName() + "." + "param1", "plugin1_param1_value"));
    // tab2 global parameters
    verify(pluginParameter4).setStringValue("tab2_param4_value");
    // tab2 plugin parameters
    verify(dataSourceTitledPane2, times(0)).setParameterValues(anyMap());
}
Also used : JsonIO(au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO) Serializable(java.io.Serializable) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) DataAccessUserPreferences(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) StringSubstitutor(org.apache.commons.text.StringSubstitutor) List(java.util.List) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 12 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessViewTopComponentNGTest method handleNewGraph.

@Test(enabled = false)
public void handleNewGraph() {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessViewTopComponent spiedTopComponent = spy(dataAccessViewTopComponent);
    doReturn(dataAccessPane).when(spiedTopComponent).getDataAccessPane();
    final Graph graph = mock(Graph.class);
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class);
        final MockedStatic<DataAccessUtilities> utilitiesMockedStatic = Mockito.mockStatic(DataAccessUtilities.class)) {
        platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer((iom) -> {
            final Runnable runnable = iom.getArgument(0);
            runnable.run();
            return null;
        });
        spiedTopComponent.componentOpened();
        spiedTopComponent.handleNewGraph(graph);
        verify(dataAccessPane).update(graph);
        utilitiesMockedStatic.verify(() -> DataAccessUtilities.loadDataAccessState(dataAccessPane, graph));
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) Platform(javafx.application.Platform) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) Test(org.testng.annotations.Test)

Example 13 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessViewTopComponentNGTest method handleNewGraph_data_access_view_not_open.

@Test(enabled = false)
public void handleNewGraph_data_access_view_not_open() {
    final Graph graph = mock(Graph.class);
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessViewTopComponent spiedTopComponent = spy(dataAccessViewTopComponent);
    doReturn(dataAccessPane).when(spiedTopComponent).getDataAccessPane();
    spiedTopComponent.handleNewGraph(graph);
    verify(dataAccessPane, never()).update(graph);
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) Test(org.testng.annotations.Test)

Example 14 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessViewTopComponentNGTest method handleComponentClosed.

@Test(enabled = false)
public void handleComponentClosed() {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessViewTopComponent spiedTopComponent = spy(dataAccessViewTopComponent);
    doReturn(dataAccessPane).when(spiedTopComponent).getDataAccessPane();
    try (final MockedStatic<QualityControlAutoVetter> qualityControlAutoVetterMockedStatic = Mockito.mockStatic(QualityControlAutoVetter.class)) {
        final QualityControlAutoVetter instance = mock(QualityControlAutoVetter.class);
        qualityControlAutoVetterMockedStatic.when(QualityControlAutoVetter::getInstance).thenReturn(instance);
        spiedTopComponent.handleComponentClosed();
        verify(instance).removeObserver(dataAccessPane);
    }
}
Also used : QualityControlAutoVetter(au.gov.asd.tac.constellation.views.qualitycontrol.daemon.QualityControlAutoVetter) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) Test(org.testng.annotations.Test)

Example 15 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessUtilitiesNGTest method testGetDataAccessPaneNotCalledByEventDispatchThreadInterruptError.

@Test
public void testGetDataAccessPaneNotCalledByEventDispatchThreadInterruptError() {
    swingUtilitiesStaticMock.when(SwingUtilities::isEventDispatchThread).thenReturn(false);
    swingUtilitiesStaticMock.when(() -> SwingUtilities.invokeAndWait(any(Runnable.class))).thenThrow(new InterruptedException());
    final DataAccessPane actual = DataAccessUtilities.getDataAccessPane();
    assertTrue(Thread.interrupted());
}
Also used : DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) Test(org.testng.annotations.Test)

Aggregations

DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)19 Test (org.testng.annotations.Test)15 Graph (au.gov.asd.tac.constellation.graph.Graph)8 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)8 Tab (javafx.scene.control.Tab)6 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)5 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)5 DataAccessViewTopComponent (au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent)4 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3 TabPane (javafx.scene.control.TabPane)3 WindowManager (org.openide.windows.WindowManager)3 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 JsonIO (au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO)2 DataAccessUserPreferences (au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences)2 DataSourceTitledPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane)2 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)2 DataAccessState (au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState)2 QualityControlAutoVetter (au.gov.asd.tac.constellation.views.qualitycontrol.daemon.QualityControlAutoVetter)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2