Search in sources :

Example 6 with StringCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues in project constellation by constellation-app.

the class AdvancedFindTabNGTest method testFindAllAction.

/**
 * Test of findAllAction method, of class AdvancedFindTab.
 */
@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).retrieveAdvancedSearch(Mockito.eq(true), Mockito.eq(false));
    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).findAllAction();
    // Do nothing on updateAdvancedSearchParameters()
    doNothing().when(advancedFindMock).updateAdvancedSearchParameters(graphElementType);
    /**
     * Create a static mock of the FindViewController. Call the
     * findAllAction() 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.findAllAction();
        verify(advancedFindMock, times(1)).updateAdvancedSearchParameters(graphElementType);
        verify(mockController, times(1)).retrieveAdvancedSearch(true, false);
    }
}
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)

Example 7 with StringCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues in project constellation by constellation-app.

the class AdvancedFindTabNGTest method testFindPreviousAction.

/**
 * Test of findPreviousAction method, of class AdvancedFindTab.
 */
@Test
public void testFindPreviousAction() {
    System.out.println("findPreviousAction");
    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(false));
    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).findPreviousAction();
    // 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.findPreviousAction();
        verify(advancedFindMock, times(1)).updateAdvancedSearchParameters(graphElementType);
        verify(mockController, times(1)).retrieveAdvancedSearch(false, false);
    }
}
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)

Example 8 with StringCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues in project constellation by constellation-app.

the class StringCriteriaPanelNGTest method testGetCriteriaValues.

/**
 * Test of getCriteriaValues method, of class StringCriteriaPanel.
 */
@Test
public void testGetCriteriaValues() {
    System.out.println("getCriteriaValues");
    setupGraph();
    AdvancedFindTab parentComponent = spy(advancedTab);
    final GraphElementType type = GraphElementType.VERTEX;
    StringCriteriaPanel stringCriteriaPanel = new StringCriteriaPanel(parentComponent, "Identifier", type);
    stringCriteriaPanel.getFilterChoiceBox().getSelectionModel().select("Is");
    stringCriteriaPanel.setSearchFieldText("hello");
    final List<AdvancedCriteriaBorderPane> tempList = new ArrayList<>();
    final GridPane tempGrid = new GridPane();
    tempList.add(stringCriteriaPanel);
    tempGrid.add(tempList.get(0), 0, 0);
    when(parentComponent.getCorrespondingCriteriaList(Mockito.eq(type))).thenReturn(tempList);
    when(parentComponent.getCorrespondingGridPane(Mockito.eq(type))).thenReturn(tempGrid);
    final List<AdvancedCriteriaBorderPane> criteriaList = parentComponent.getCorrespondingCriteriaList(type);
    final FindCriteriaValues result = criteriaList.get(0).getCriteriaValues();
    final StringCriteriaValues floatResult = (StringCriteriaValues) result;
    assertEquals(floatResult.getAttribute(), "Identifier");
    assertEquals(floatResult.getAttributeType(), "string");
    assertEquals(floatResult.getFilter(), "Is");
    assertEquals(floatResult.getText(), "hello");
}
Also used : FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) GridPane(javafx.scene.layout.GridPane) AdvancedFindTab(au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues) Test(org.testng.annotations.Test)

Example 9 with StringCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues in project constellation by constellation-app.

the class AdvancedSearchParametersNGTest method populateCriteriaLists.

private void populateCriteriaLists() {
    FindCriteriaValues valueOne = new StringCriteriaValues("string", "Identifier", "Is", "one", true, false);
    FindCriteriaValues valueTwo = new StringCriteriaValues("string", "Identifier", "Is", "two", true, false);
    criteriaValuesListOne.add(valueOne);
    criteriaValuesListOne.add(valueTwo);
    FindCriteriaValues valueThree = new StringCriteriaValues("string", "Identifier", "Is", "three", true, false);
    FindCriteriaValues valueFour = new StringCriteriaValues("string", "Identifier", "Is", "four", true, false);
    criteriaValuesListTwo.add(valueThree);
    criteriaValuesListTwo.add(valueFour);
}
Also used : FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues)

Aggregations

StringCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues)9 FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)8 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)3 AdvancedCriteriaBorderPane (au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)3 StringCriteriaPanel (au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel)3 ChoiceBox (javafx.scene.control.ChoiceBox)3 BooleanCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.BooleanCriteriaValues)2 ColourCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.ColourCriteriaValues)2 DateTimeCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.DateTimeCriteriaValues)2 FloatCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FloatCriteriaValues)2 IconCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.IconCriteriaValues)2 AdvancedSearchParameters (au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 AdvancedFindTab (au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1