Search in sources :

Example 1 with FindViewController

use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.

the class BasicFindPluginNGTest method getAttributes.

/**
 * Used to convert the string variant of attributes to the Attribute object
 *
 * @return the list of Attribute objects
 */
private ArrayList<Attribute> getAttributes() {
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    ArrayList<Attribute> attributes = new ArrayList<>();
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        GraphElementType type = GraphElementType.VERTEX;
        List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        ReadableGraph rg = graph.getReadableGraph();
        for (int i = 0; i < result.size(); i++) {
            int attributeInt = rg.getAttribute(type, result.get(i));
            GraphAttribute ga = new GraphAttribute(rg, attributeInt);
            if (ga.getAttributeType().equals("string")) {
                attributes.add(new GraphAttribute(rg, attributeInt));
                System.out.println(attributes.get(i).getName() + " = attribute name");
            }
        }
        rg.close();
    }
    return attributes;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) FindViewTopComponent(au.gov.asd.tac.constellation.views.find2.FindViewTopComponent) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController)

Example 2 with FindViewController

use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.

the class ReplacePluginNGTest method getAttributes.

/**
 * Used to convert the string variant of attributes to the Attribute object
 *
 * @return the list of Attribute objects
 */
private ArrayList<Attribute> getAttributes() {
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    ArrayList<Attribute> attributes = new ArrayList<>();
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        GraphElementType type = GraphElementType.VERTEX;
        List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        ReadableGraph rg = graph.getReadableGraph();
        for (int i = 0; i < result.size(); i++) {
            int attributeInt = rg.getAttribute(type, result.get(i));
            GraphAttribute ga = new GraphAttribute(rg, attributeInt);
            if (ga.getAttributeType().equals("string")) {
                attributes.add(new GraphAttribute(rg, attributeInt));
            }
        }
        rg.close();
    }
    return attributes;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) FindViewTopComponent(au.gov.asd.tac.constellation.views.find2.FindViewTopComponent) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController)

Example 3 with FindViewController

use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.

the class BasicFindTabNGTest method testFindAllAction.

/**
 * Test of findAllAction method, of class BasicFindTab.
 */
@Test
public void testFindAllAction() {
    System.out.println("findAllAction");
    setupGraph();
    // Create a controller mock and do nothing on retriveMatchingElements()
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).retriveMatchingElements(Mockito.eq(true), Mockito.eq(false));
    /**
     * Create a basicFindMock and adds a temporary choice box and textFild
     * for the functions to work.
     */
    BasicFindTab basicFindMock = mock(BasicFindTab.class);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final TextField findTextField = new TextField("test");
    // Mock the getters to return the newly made java fx element.
    when(basicFindMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    when(basicFindMock.getFindTextField()).thenReturn(findTextField);
    // Do nothing on saveSelected() and updateBasicFindParamters()
    doCallRealMethod().when(basicFindMock).findAllAction();
    doNothing().when(basicFindMock).saveSelected(Mockito.any());
    doNothing().when(basicFindMock).updateBasicFindParamters();
    /**
     * Create a static mock of the FindViewController. Call the
     * findAllAction() then verify that saveSelected,
     * updateBasicFindParameters and retrieveMatchingElements were all
     * called once.
     */
    try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
        mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
        basicFindMock.findAllAction();
        verify(basicFindMock, times(1)).saveSelected(Mockito.eq(GraphElementType.VERTEX));
        verify(basicFindMock, times(1)).updateBasicFindParamters();
        verify(mockController, times(1)).retriveMatchingElements(true, false);
    }
}
Also used : TextField(javafx.scene.control.TextField) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController) ChoiceBox(javafx.scene.control.ChoiceBox) Test(org.testng.annotations.Test)

Example 4 with FindViewController

use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.

the class BasicFindTabNGTest method testFindNextAction.

/**
 * Test of findNextAction method, of class BasicFindTab.
 */
@Test
public void testFindNextAction() {
    System.out.println("findNextAction");
    // Refer to testFindAllAction for comments
    setupGraph();
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).retriveMatchingElements(Mockito.eq(false), Mockito.eq(true));
    BasicFindTab basicFindMock = mock(BasicFindTab.class);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final TextField findTextField = new TextField("test");
    when(basicFindMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    when(basicFindMock.getFindTextField()).thenReturn(findTextField);
    doCallRealMethod().when(basicFindMock).findNextAction();
    doNothing().when(basicFindMock).saveSelected(Mockito.any());
    doNothing().when(basicFindMock).updateBasicFindParamters();
    try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
        mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
        basicFindMock.findNextAction();
        verify(basicFindMock, times(1)).saveSelected(Mockito.eq(GraphElementType.VERTEX));
        verify(basicFindMock, times(1)).updateBasicFindParamters();
        verify(mockController, times(1)).retriveMatchingElements(false, true);
    }
}
Also used : TextField(javafx.scene.control.TextField) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController) ChoiceBox(javafx.scene.control.ChoiceBox) Test(org.testng.annotations.Test)

Example 5 with FindViewController

use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.

the class AdvancedFindTabNGTest method testFindNextAction.

/**
 * Test of findNextAction method, of class AdvancedFindTab.
 */
@Test
public void testFindNextAction() {
    System.out.println("findNextAction");
    setupGraph();
    // Create a controller mock and do nothing on retriveMatchingElements()
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).retrieveAdvancedSearch(Mockito.eq(false), Mockito.eq(true));
    GraphElementType graphElementType = GraphElementType.VERTEX;
    /**
     * Create temporary advancedFindMock, pane, criteriaPaneList,
     * LookForChoiceBox, findCriteriaValuesList and a stringCriteriaValue
     */
    AdvancedFindTab advancedFindMock = mock(AdvancedFindTab.class);
    StringCriteriaPanel tempPane = new StringCriteriaPanel(advancedTab, "Identifer", graphElementType);
    tempPane.setSearchFieldText("hello");
    final List<AdvancedCriteriaBorderPane> criteriaPaneList = new ArrayList<>();
    criteriaPaneList.add(tempPane);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final List<FindCriteriaValues> findCriteriaValues = new ArrayList<>();
    final StringCriteriaValues stringCriteriaValue = new StringCriteriaValues("string", "Identifer", "Is", "hello", false, false);
    findCriteriaValues.add(stringCriteriaValue);
    // When each function is called return the temporarily created elements above
    when(advancedFindMock.getCorrespondingCriteriaList(graphElementType)).thenReturn(criteriaPaneList);
    when(advancedFindMock.getCriteriaValues(criteriaPaneList)).thenReturn(findCriteriaValues);
    when(advancedFindMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    // Do real call on findAllAction
    doCallRealMethod().when(advancedFindMock).findNextAction();
    // Do nothing on updateAdvancedSearchParameters()
    doNothing().when(advancedFindMock).updateAdvancedSearchParameters(graphElementType);
    /**
     * Create a static mock of the FindViewController. Call the
     * findNextAction() then verify that updateAdvancedSearchParameters and
     * retrieveAdvancedSearch were all called once.
     */
    try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
        mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
        advancedFindMock.findNextAction();
        verify(advancedFindMock, times(1)).updateAdvancedSearchParameters(graphElementType);
        verify(mockController, times(1)).retrieveAdvancedSearch(false, true);
    }
}
Also used : ArrayList(java.util.ArrayList) StringCriteriaPanel(au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues) ChoiceBox(javafx.scene.control.ChoiceBox) FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)12 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)10 ChoiceBox (javafx.scene.control.ChoiceBox)8 ArrayList (java.util.ArrayList)7 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 TextField (javafx.scene.control.TextField)5 Attribute (au.gov.asd.tac.constellation.graph.Attribute)4 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)4 AdvancedCriteriaBorderPane (au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)3 StringCriteriaPanel (au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel)3 FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)3 StringCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues)3 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)2 FindViewTopComponent (au.gov.asd.tac.constellation.views.find2.FindViewTopComponent)2