Roy Golan has uploaded a new change for review. Change subject: core: fix search validation of OSs ......................................................................
core: fix search validation of OSs the UI is validating the input for OSs and was mistakenly lower casing each input. this created a corner case where and os unique name with that had capital letters, windows_2008_R2 was not a valid input for search. its a false assumption to make that all osinfo unique os name are case sensitive ATM and no point in trying to refactor that. Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1003804 Change-Id: I818dd4eead46402d1fb6a832786020a5458c533d Signed-off-by: Roy Golan <rgo...@redhat.com> --- M backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleter.java M backend/manager/modules/searchbackend/src/test/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleterTest.java 2 files changed, 46 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/21707/1 diff --git a/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleter.java b/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleter.java index b4ef765..51aaba3 100644 --- a/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleter.java +++ b/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleter.java @@ -38,7 +38,7 @@ @Override public boolean validate(String text) { - text = text.trim().toLowerCase(); + text = text.trim(); for (String os : map.values()) { if (os.equals(text)) { return true; diff --git a/backend/manager/modules/searchbackend/src/test/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleterTest.java b/backend/manager/modules/searchbackend/src/test/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleterTest.java index 2ba08c7..ee4d62b 100644 --- a/backend/manager/modules/searchbackend/src/test/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleterTest.java +++ b/backend/manager/modules/searchbackend/src/test/java/org/ovirt/engine/core/searchbackend/OsValueAutoCompleterTest.java @@ -1,23 +1,41 @@ package org.ovirt.engine.core.searchbackend; -import junit.framework.Assert; -import org.junit.Before; -import org.junit.Test; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; import java.util.HashMap; import java.util.Map; +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.Theories; +import org.junit.experimental.theories.Theory; +import org.junit.runner.RunWith; + +@RunWith(Theories.class) public class OsValueAutoCompleterTest { private OsValueAutoCompleter completer; + public static Map<Integer, String> completionMap; + + @DataPoints + public static Map.Entry<Integer, String>[] data() { + Map.Entry[] arr = completionMap.entrySet().toArray(new Map.Entry[] {}); + return (Map.Entry<Integer, String>[]) arr; + } @Before public void setup() { - - Map<Integer, String> completionMap = new HashMap<Integer, String>(); + completionMap = new HashMap<Integer, String>(); completionMap.put(0, "other"); completionMap.put(1, "rhel_x"); completionMap.put(2, "rhel_x_y"); + completionMap.put(3, "windows_2008"); + completionMap.put(4, "windows_2008_R2"); + completionMap.put(5, "windows_2008_R2x64"); completer = new OsValueAutoCompleter(completionMap); } @@ -31,12 +49,29 @@ Assert.assertTrue(completer.getCompletion("r").length > 1); } - @Test - public void testConvertStringToId() { - Assert.assertEquals("0", completer.convertFieldEnumValueToActualValue("other")); - Assert.assertEquals("1", completer.convertFieldEnumValueToActualValue("rhel_x")); - Assert.assertEquals("2", completer.convertFieldEnumValueToActualValue("rhel_x_y")); + /** + * every auto completed input is always valid when using the auto-completer validate() method + * @param osCompletionEntry + */ + @Theory + public void autoCompletedInputIsAlwaysValid(Map.Entry<Integer, String> osCompletionEntry) { + String reason = "input " + osCompletionEntry.getValue() + " is invalid"; + assertThat(reason, + true, is(completer.validate(osCompletionEntry.getValue()))); } + /** + * every auto-completed value matches its numeric key value. + * e.g + * when auto-completing "rhel" and "rhel_x" was picked and is used as a search term, it shall + * match its key in the completion list. i.e convertFieldEnumValueToActualValue("rhel_x") always yields -> 1 + * + * @param osCompletionEntry + */ + @Theory + public void autoCompletedInputMatchesItsNumericKeyValue(Map.Entry<Integer, String> osCompletionEntry) { + assertThat(osCompletionEntry.getKey().toString(), + is(completer.convertFieldEnumValueToActualValue(osCompletionEntry.getValue()))); + } } -- To view, visit http://gerrit.ovirt.org/21707 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I818dd4eead46402d1fb6a832786020a5458c533d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.3 Gerrit-Owner: Roy Golan <rgo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches