diff --git a/vscode-extensions/commons/application-properties-metadata/pom.xml b/vscode-extensions/commons/application-properties-metadata/pom.xml
index 6a7762a82..c91603ca9 100644
--- a/vscode-extensions/commons/application-properties-metadata/pom.xml
+++ b/vscode-extensions/commons/application-properties-metadata/pom.xml
@@ -11,6 +11,14 @@
Builds metadata for boot application properties based on project's classpath contents
+
+
+ libs
+ json
+ 1.0
+ system
+ ${project.basedir}/lib/org.springframework.ide.eclipse.org.json-20140107-repackaged.jar
+
com.google.guava
@@ -38,14 +46,34 @@
util-commons
${project.version}
-
-
-
- org.eclipse.jdt
- core
- 3.3.0-v_771
-
-
+
+
+
\ No newline at end of file
diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/FuzzyMapTests.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/FuzzyMapTests.java
new file mode 100644
index 000000000..ec078ed9c
--- /dev/null
+++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/FuzzyMapTests.java
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Pivotal, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Pivotal, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.springframework.ide.vscode.boot.properties.metadata;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.junit.Test;
+import org.springframework.ide.vscode.boot.properties.util.FuzzyMap;
+import org.springframework.ide.vscode.boot.properties.util.FuzzyMap.Match;
+import org.springframework.ide.vscode.util.FuzzyMatcher;
+
+public class FuzzyMapTests {
+
+ @Test
+ public void testMatches() {
+ assertMatch(true, "", "");
+ assertMatch(true, "", "abc");
+ assertMatch(true, "server.port", "server.port");
+ assertMatch(true, "port", "server.port");
+ assertMatch(true, "sport", "server.port");
+ assertMatch(false, "spox", "server.port");
+ }
+
+ @Test
+ public void testOrder() {
+ assertMatchOrder("port",
+ "port",
+ "server.port",
+ "server.port-mapping",
+ "piano.sorting"
+ );
+ }
+
+ @Test
+ public void testPrefixAlfaOrder() {
+ //all matches are prefix matches so should come in alpha order
+ assertMatchOrder("spring",
+ "spring.abracdabra",
+ "spring.boot",
+ "spring.candel",
+ "spring.shoe",
+ "spring.springer"
+ );
+ }
+
+ @Test
+ public void testPrefixMixedOrder() {
+ assertMatchOrder("spring",
+ //prefix matches first
+ "spring.abracdabra",
+ "spring.boot",
+ "spring.candel",
+ "spring.shoe",
+ "spring.springer",
+ //non prefix matches after prefix matches in 'similarity order'
+ "zspring",
+ "asprouting"
+ );
+ }
+
+ public class TestMap extends FuzzyMap {
+ public TestMap(String... entries) {
+ for (String e : entries) {
+ add(e);
+ }
+ }
+ protected String getKey(String entry) {
+ return entry;
+ }
+ }
+
+ @Test
+ public void testCommonPrefix() {
+ String[] entries = {
+ "a",
+ "archipel",
+ "aardappel",
+ "aardbei",
+ "aardvark",
+ "zoroaster"
+ };
+ String[] expectPrefix = {
+ "a",
+ "a",
+ "aard",
+ "aard",
+ "aard",
+ ""
+ };
+ for (int focusOn = 0; focusOn < entries.length; focusOn++) {
+ TestMap map = new TestMap();
+ for (int other = 0; other < entries.length; other++) {
+ if (focusOn!=other) {
+ map.add(entries[other]);
+ }
+ }
+ String prefix = map.findValidPrefix(entries[focusOn]);
+ String prefixEntry = map.findLongestCommonPrefixEntry(entries[focusOn]);
+ assertEquals(expectPrefix[focusOn], prefix);
+ assertTrue(prefixEntry.startsWith(prefixEntry));
+ assertTrue(prefixEntry.length()>prefix.length());
+ }
+ }
+
+ @Test
+ public void testCommonPrefixWithExactMatch() {
+ String[] entries = {
+ "a",
+ "archipel",
+ "aardappel",
+ "aardbei",
+ "aardvark",
+ "zoroaster"
+ };
+ TestMap map = new TestMap(entries);
+ for (String find : entries) {
+ String found = map.findLongestCommonPrefixEntry(find);
+ assertEquals(find, found);
+ }
+ }
+
+ @Test
+ public void testCommonPrefixEmptyMap() {
+ TestMap empty = new TestMap();
+ assertEquals(null, empty.findValidPrefix("foo"));
+ assertEquals(null, empty.findValidPrefix(""));
+ assertEquals(null, empty.findLongestCommonPrefixEntry("aaa"));
+ assertEquals(null, empty.findLongestCommonPrefixEntry(""));
+ }
+
+
+ private void assertMatchOrder(String pattern, String... datas) {
+ TestMap map = new TestMap(datas);
+ List> found = map.find(pattern);
+
+ //Note that found elements are scored but not sorted.
+ Collections.sort(found, new Comparator>() {
+ public int compare(Match o1, Match o2) {
+ return Double.valueOf(o2.score).compareTo(o1.score);
+ }
+ });
+
+ //all the datas should be found and be in the order given.
+ assertEquals(found.size(), datas.length);
+ for (int i = 0; i < datas.length; i++) {
+ assertEquals(datas[i], found.get(i).data);
+ }
+
+ // also check that scores are decreasing.
+ double previousScore = found.get(0).score;
+ assertTrue(previousScore!=0.0);
+ for (int i = 1; i < datas.length; i++) {
+ String data = datas[i];
+ double score = found.get(i).score;
+ assertTrue("Wrong score order: '"+datas[i-1]+"'["+previousScore+"] '"+data+"' ["+score+"]", previousScore>=score);
+ previousScore = score;
+ }
+ }
+
+ private void assertMatch(boolean expect, String pattern, String data) {
+ boolean actual = FuzzyMatcher.matchScore(pattern, data)!=0.0;
+ assertEquals(expect, actual);
+ }
+
+}
diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/StringUtilTests.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/StringUtilTests.java
new file mode 100644
index 000000000..0b4ac1cf1
--- /dev/null
+++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/StringUtilTests.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2014-2015 Pivotal, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Pivotal, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.springframework.ide.vscode.boot.properties.metadata;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.springframework.ide.vscode.boot.properties.util.StringUtil;
+
+/**
+ * @author Kris De Volder
+ */
+public class StringUtilTests {
+
+ @Test
+ public void testUpperCaseToHyphens() throws Exception {
+ assertEquals("extra-small", StringUtil.upperCaseToHyphens("EXTRA_SMALL"));
+ assertEquals("extra-small", StringUtil.upperCaseToHyphens("extra-small")); //can be applied to already converted string without any harm
+ assertEquals("", StringUtil.upperCaseToHyphens(""));
+ assertNull(StringUtil.upperCaseToHyphens(null));
+ }
+
+ @Test
+ public void testHasText() throws Exception {
+ assertFalse(StringUtil.hasText(null));
+ assertFalse(StringUtil.hasText(""));
+ assertFalse(StringUtil.hasText(" \t\n\r"));
+ assertTrue(StringUtil.hasText("something"));
+ }
+
+ @Test
+ public void testTrim() throws Exception {
+ assertNull(StringUtil.trim(null));
+ assertEquals("foo", StringUtil.trim(" foo \n\r\t"));
+ }
+
+ @Test
+ public void testCommonPrefixLen() throws Exception {
+ assertEquals("foo".length(), StringUtil.commonPrefixLength("foobarlonger", "fooshort"));
+ assertEquals("foo".length(), StringUtil.commonPrefixLength("fooshort", "foobarlonger"));
+ assertEquals("foo".length(), StringUtil.commonPrefixLength("foo", "foobarlonger"));
+ assertEquals("foo".length(), StringUtil.commonPrefixLength("foobarlonger", "foo"));
+ assertEquals(0, StringUtil.commonPrefixLength("", ""));
+ assertEquals(0, StringUtil.commonPrefixLength("", "something"));
+ assertEquals(0, StringUtil.commonPrefixLength("something", ""));
+ assertEquals(0, StringUtil.commonPrefixLength("nothing", "in common"));
+ }
+
+ @Test
+ public void testCommonPrefix() throws Exception {
+ assertEquals("foo", StringUtil.commonPrefix("foobarlonger", "fooshort"));
+ assertEquals("foo", StringUtil.commonPrefix("fooshort", "foobarlonger"));
+ assertEquals("foo", StringUtil.commonPrefix("foo", "foobarlonger"));
+ assertEquals("foo", StringUtil.commonPrefix("foobarlonger", "foo"));
+ assertEquals("", StringUtil.commonPrefix("", ""));
+ assertEquals("", StringUtil.commonPrefix("", "something"));
+ assertEquals("", StringUtil.commonPrefix("something", ""));
+ assertEquals("", StringUtil.commonPrefix("nothing", "in common"));
+ }
+
+}
diff --git a/vscode-extensions/commons/pom.xml b/vscode-extensions/commons/pom.xml
index 2c1163850..27739a9be 100644
--- a/vscode-extensions/commons/pom.xml
+++ b/vscode-extensions/commons/pom.xml
@@ -15,6 +15,7 @@
yaml-commons
util-commons
java-properties
+ application-properties-metadata