use of au.gov.asd.tac.constellation.views.find2.FindViewController 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);
}
}
use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.
the class BasicFindTabNGTest method testFindPrevAction.
/**
* Test of findPrevAction method, of class BasicFindTab.
*/
@Test
public void testFindPrevAction() {
System.out.println("findPrevAction");
// Refer to testFindAllAction for comments
setupGraph();
FindViewController mockController = mock(FindViewController.class);
mockController.init(spyTopComponent);
doNothing().when(mockController).retriveMatchingElements(Mockito.eq(false), Mockito.eq(false));
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).findPrevAction();
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.findPrevAction();
verify(basicFindMock, times(1)).saveSelected(Mockito.eq(GraphElementType.VERTEX));
verify(basicFindMock, times(1)).updateBasicFindParamters();
verify(mockController, times(1)).retriveMatchingElements(false, false);
}
}
use of au.gov.asd.tac.constellation.views.find2.FindViewController in project constellation by constellation-app.
the class ReplaceTabNGTest method testReplaceNextAction.
/**
* Test of replaceNextAction method, of class ReplaceTab.
*/
@Test
public void testReplaceNextAction() {
System.out.println("replaceNextAction");
setupGraph();
// Create a controller mock and do nothing on retriveMatchingElements()
FindViewController mockController = mock(FindViewController.class);
mockController.init(spyTopComponent);
doNothing().when(mockController).replaceMatchingElements(Mockito.eq(false), Mockito.eq(true));
/**
* 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).replaceNextAction();
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.replaceNextAction();
verify(replaceMock, times(1)).saveSelected(Mockito.eq(GraphElementType.VERTEX));
verify(replaceMock, times(1)).updateBasicReplaceParamters();
verify(mockController, times(1)).replaceMatchingElements(false, true);
}
}
use of au.gov.asd.tac.constellation.views.find2.FindViewController 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);
}
}
Aggregations