Search in sources :

Example 6 with ReplaceTab

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

the class ReplaceTabNGTest method testUpdateBasicReplaceParamters.

/**
 * Test of updateBasicReplaceParamters method, of class ReplaceTab.
 */
@Test
public void testUpdateBasicReplaceParamters() {
    System.out.println("updateBasicReplaceParamters");
    final BasicFindReplaceParameters controlllerParameters = FindViewController.getDefault().getCurrentBasicReplaceParameters();
    replaceTab.lookForChoiceBox.getSelectionModel().select(0);
    replaceTab.getFindTextField().setText("test");
    replaceTab.getReplaceTextField().setText("replace");
    final GraphElementType elementType = GraphElementType.getValue(replaceTab.lookForChoiceBox.getSelectionModel().getSelectedItem());
    replaceTab.currentSelectionChoiceBox.getSelectionModel().select(0);
    /**
     * Call the updateBasicFindParamters function. Check that each of the
     * javaFX elements passes their corresponding data correctly to the
     * controllers basicFindParamters
     */
    replaceTab.updateBasicReplaceParamters();
    /**
     * All parameters should equal the current value of the basicFindTabs
     * elements
     */
    assertEquals(controlllerParameters.getFindString(), replaceTab.getFindTextField().getText());
    assertEquals(controlllerParameters.getReplaceString(), replaceTab.getReplaceTextField().getText());
    assertEquals(controlllerParameters.getGraphElement(), elementType);
    assertEquals(controlllerParameters.getAttributeList(), replaceTab.getMatchingAttributeList(elementType));
    assertEquals(controlllerParameters.isStandardText(), replaceTab.standardRadioBtn.isSelected());
    assertEquals(controlllerParameters.isRegEx(), replaceTab.regExBtn.isSelected());
    assertEquals(controlllerParameters.isIgnoreCase(), replaceTab.ignoreCaseCB.isSelected());
    /**
     * All 4 should be false as currentSelectionChoiceBox is set to select
     * index 0 which is "Ignore"
     */
    assertEquals(controlllerParameters.isFindIn(), false);
    assertEquals(controlllerParameters.isAddTo(), false);
    assertEquals(controlllerParameters.isRemoveFrom(), false);
    assertEquals(controlllerParameters.isReplaceIn(), false);
    assertEquals(controlllerParameters.isSearchAllGraphs(), replaceTab.searchAllGraphs.isSelected());
// TODO review the generated test code and remove the default call to fail.
}
Also used : BasicFindReplaceParameters(au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 7 with ReplaceTab

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

the class ReplaceTabNGTest method testReplaceAllAction.

/**
 * Test of replaceAllAction method, of class ReplaceTab.
 */
@Test
public void testReplaceAllAction() {
    System.out.println("replaceAllAction");
    setupGraph();
    // Create a controller mock and do nothing on retriveMatchingElements()
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).replaceMatchingElements(Mockito.eq(true), Mockito.eq(false));
    /**
     * Create a basicFindMock and adds a temporary choice box and textFild
     * for the functions to work.
     */
    ReplaceTab replaceMock = mock(ReplaceTab.class);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final TextField findTextField = new TextField("test");
    final TextField repalceTextField = new TextField("replace");
    // Mock the getters to return the newly made java fx element.
    when(replaceMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    when(replaceMock.getFindTextField()).thenReturn(findTextField);
    when(replaceMock.getReplaceTextField()).thenReturn(repalceTextField);
    // Do nothing on saveSelected() and updateBasicFindParamters()
    doCallRealMethod().when(replaceMock).replaceAllAction();
    doNothing().when(replaceMock).saveSelected(Mockito.any());
    doNothing().when(replaceMock).updateBasicReplaceParamters();
    /**
     * 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);
        replaceMock.replaceAllAction();
        verify(replaceMock, times(1)).saveSelected(Mockito.eq(GraphElementType.VERTEX));
        verify(replaceMock, times(1)).updateBasicReplaceParamters();
        verify(mockController, times(1)).replaceMatchingElements(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)

Aggregations

FindViewTopComponent (au.gov.asd.tac.constellation.views.find2.FindViewTopComponent)4 AdvancedFindTab (au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab)4 BasicFindTab (au.gov.asd.tac.constellation.views.find2.components.BasicFindTab)4 FindViewPane (au.gov.asd.tac.constellation.views.find2.components.FindViewPane)4 FindViewTabs (au.gov.asd.tac.constellation.views.find2.components.FindViewTabs)4 ReplaceTab (au.gov.asd.tac.constellation.views.find2.components.ReplaceTab)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Test (org.testng.annotations.Test)3 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)2 ChoiceBox (javafx.scene.control.ChoiceBox)2 TextField (javafx.scene.control.TextField)2 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)1