use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.
the class AdvancedFindTabNGTest method testGetCriteriaValues.
/**
* Test of getCriteriaValues method, of class AdvancedFindTab.
*/
@Test
public void testGetCriteriaValues() {
System.out.println("getCriteriaValues");
setupGraph();
GraphElementType type = GraphElementType.VERTEX;
List<AdvancedCriteriaBorderPane> criteriaList = new ArrayList<>();
AdvancedCriteriaBorderPane pane1 = new StringCriteriaPanel(advancedTab, "Identifier", type);
AdvancedCriteriaBorderPane pane2 = new StringCriteriaPanel(advancedTab, "Label", type);
criteriaList.add(pane1);
criteriaList.add(pane2);
List<FindCriteriaValues> resultsList = advancedTab.getCriteriaValues(criteriaList);
assertEquals(resultsList.get(0).getAttribute(), "Identifier");
assertEquals(resultsList.get(1).getAttribute(), "Label");
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues 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);
}
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.
the class FloatCriteriaPanelNGTest method testGetCriteriaValues.
/**
* Test of getCriteriaValues method, of class FloatCriteriaPanel.
*/
@Test
public void testGetCriteriaValues() {
System.out.println("getCriteriaValues");
setupGraph();
AdvancedFindTab parentComponent = spy(advancedTab);
final GraphElementType type = GraphElementType.VERTEX;
FloatCriteriaPanel floatCriteriaPanel = new FloatCriteriaPanel(parentComponent, "x", type);
floatCriteriaPanel.getFilterChoiceBox().getSelectionModel().select("Is Between");
floatCriteriaPanel.getSearchField().setText("22");
floatCriteriaPanel.getSearchFieldTwo().setText("44");
final List<AdvancedCriteriaBorderPane> tempList = new ArrayList<>();
final GridPane tempGrid = new GridPane();
tempList.add(floatCriteriaPanel);
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 FloatCriteriaValues floatResult = (FloatCriteriaValues) result;
assertEquals(floatResult.getAttribute(), "x");
assertEquals(floatResult.getAttributeType(), "float");
assertEquals(floatResult.getFilter(), "Is Between");
assertEquals(floatResult.getFloatValuePrimary(), 22f);
assertEquals(floatResult.getFloatValueSecondary(), 44f);
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.
the class AdvancedSearchPlugin method searchAsString.
/**
* This function checks to see if a graph elements string attribute matches
* the criteria specified by the stringCriteriaValues.
*
* @param values the string criteriaValues
* @param attributeInt the int of the attribute
* @param currElement the currentElement
* @param graph the current graph
* @return
*/
private boolean searchAsString(final FindCriteriaValues values, final int attributeInt, final int currElement, final GraphWriteMethods graph) {
final StringCriteriaValues stringValues = (StringCriteriaValues) values;
String value = graph.getStringValue(attributeInt, currElement);
// create a list that will contain the string searches
final List<String> allSearchableString = new ArrayList<>();
allSearchableString.add(stringValues.getText());
// if using the list, clear it and re add all values in the text list
if (stringValues.isUseList()) {
allSearchableString.clear();
allSearchableString.addAll(stringValues.getTextList());
}
// if ignoring the case set the value and each of the strings to lower case
if (stringValues.isIgnoreCase() && value != null) {
value = value.toLowerCase();
int i = 0;
for (String str : allSearchableString) {
allSearchableString.set(i, str.toLowerCase());
i++;
}
}
boolean matches = false;
/**
* This switch handles the matching check based on the filter choice by
* the user. It checks all str within the allSearchable strings list.
*/
switch(stringValues.getFilter()) {
case IS:
for (final String str : allSearchableString) {
if (str.equals(value)) {
matches = true;
}
}
break;
case IS_NOT:
for (final String str : allSearchableString) {
if (!str.equals(value)) {
matches = true;
}
}
break;
case "Contains":
for (final String str : allSearchableString) {
if (value != null && value.contains(str)) {
matches = true;
}
}
break;
case "Doesn't Contain":
for (final String str : allSearchableString) {
if (value != null && !value.contains(str)) {
matches = true;
}
}
break;
case "Begins With":
for (final String str : allSearchableString) {
if (value != null && value.startsWith(str)) {
matches = true;
}
}
break;
case "Ends With":
for (final String str : allSearchableString) {
if (value != null && value.endsWith(str)) {
matches = true;
}
}
break;
case "Matches (Regex)":
for (final String str : allSearchableString) {
if (value != null) {
final int caseSensitivity = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE;
final Pattern searchPattern = Pattern.compile(str, caseSensitivity);
final Matcher match = searchPattern.matcher(value);
matches = match.find();
}
}
break;
default:
break;
}
return matches;
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.
the class AdvancedSearchPlugin method searchAsFloat.
/**
* This function checks to see if a graph elements float attribute matches
* the criteria specified by the floatCriteriaValues.
*
* @param values the float criteriaValues
* @param attributeInt the int of the attribute
* @param currElement the currentElement
* @param graph the current graph
* @return
*/
private boolean searchAsFloat(final FindCriteriaValues values, final int attributeInt, final int currElement, final GraphWriteMethods graph) {
final FloatCriteriaValues floatValues = (FloatCriteriaValues) values;
final float value = graph.getFloatValue(attributeInt, currElement);
boolean matches = false;
/**
* This switch handles the matching check based on the filter choice by
* the user. It checks the users float value against the attributes
* float value
*/
switch(floatValues.getFilter()) {
case IS:
if (floatValues.getFloatValuePrimary() == value) {
matches = true;
}
break;
case IS_NOT:
if (floatValues.getFloatValuePrimary() != value) {
matches = true;
}
break;
case "Is Less Than":
if (floatValues.getFloatValuePrimary() > value) {
matches = true;
}
break;
case "Is Greater Than":
if (floatValues.getFloatValuePrimary() < value) {
matches = true;
}
break;
case "Is Between":
if (value < floatValues.getFloatValuePrimary() && value > floatValues.getFloatValueSecondary()) {
matches = true;
}
if (value > floatValues.getFloatValuePrimary() && value < floatValues.getFloatValueSecondary()) {
matches = true;
}
break;
default:
break;
}
return matches;
}
Aggregations