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. Change-Id: I818dd4eead46402d1fb6a832786020a5458c533d Signed-off-by: Roy Golan <rgo...@redhat.com> --- M backend/manager/modules/searchbackend/pom.xml 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 M pom.xml 4 files changed, 77 insertions(+), 12 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/61/21661/1 diff --git a/backend/manager/modules/searchbackend/pom.xml b/backend/manager/modules/searchbackend/pom.xml index 3a5100e..6da95fd 100644 --- a/backend/manager/modules/searchbackend/pom.xml +++ b/backend/manager/modules/searchbackend/pom.xml @@ -38,7 +38,12 @@ <type>test-jar</type> <scope>test</scope> </dependency> -</dependencies> + <dependency> + <groupId>org.ovirt.engine.core</groupId> + <artifactId>utils</artifactId> + <version>3.3.0-SNAPSHOT</version> + </dependency> + </dependencies> <build> <plugins> 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()))); + } } diff --git a/pom.xml b/pom.xml index e5759a8..3dab7dd 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,7 @@ <!-- Plugins Versions --> <maven-surefire-plugin.version>2.7.2</maven-surefire-plugin.version> <maven-resources-plugin.version>2.4.3</maven-resources-plugin.version> + <maven-remote-resources-plugin.version>1.5</maven-remote-resources-plugin.version> <exec-maven-plugin.version>1.2</exec-maven-plugin.version> <maven-ejb-plugin.version>2.3</maven-ejb-plugin.version> </properties> @@ -469,6 +470,11 @@ <version>${maven-resources-plugin.version}</version> </plugin> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-remote-resources-plugin</artifactId> + <version>${maven-remote-resources-plugin.version}</version> + </plugin> + <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>${exec-maven-plugin.version}</version> @@ -577,6 +583,22 @@ </ignores> </configuration> </plugin> + <plugin> + <artifactId>maven-remote-resources-plugin</artifactId> + <version>1.5</version> + <executions> + <execution> + <goals> + <goal>bundle</goal> + </goals> + </execution> + </executions> + <configuration> + <includes> + <include>${project.basedir}}/conf/*.properties</include> + </includes> + </configuration> + </plugin> </plugins> </pluginManagement> <resources> @@ -589,6 +611,9 @@ <resource> <directory>src/main/resources</directory> </resource> + <resource> + <directory>packaging</directory> + </resource> </resources> </build> <profiles> -- To view, visit http://gerrit.ovirt.org/21661 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I818dd4eead46402d1fb6a832786020a5458c533d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Roy Golan <rgo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches