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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations