Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2011-10-31 19:02:39 +0000
committerRoberto E. Escobar2011-10-31 19:02:39 +0000
commitea7a3940bd83d582f548250de8aa00a5d99fe5db (patch)
tree514daa3079172318b6fde2e96071d3c81afa6a68 /plugins/org.eclipse.osee.framework.jdk.core.test
parentc12efada41b4e1f60cefdd9d13a272580e65de57 (diff)
downloadorg.eclipse.osee-ea7a3940bd83d582f548250de8aa00a5d99fe5db.tar.gz
org.eclipse.osee-ea7a3940bd83d582f548250de8aa00a5d99fe5db.tar.xz
org.eclipse.osee-ea7a3940bd83d582f548250de8aa00a5d99fe5db.zip
feature: Create UrlQuery utility class
Diffstat (limited to 'plugins/org.eclipse.osee.framework.jdk.core.test')
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/JdkCoreUtilTestSuite.java3
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/UrlQueryTest.java153
2 files changed, 155 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/JdkCoreUtilTestSuite.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/JdkCoreUtilTestSuite.java
index 01023f3123..70c65f6e9a 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/JdkCoreUtilTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/JdkCoreUtilTestSuite.java
@@ -29,7 +29,8 @@ import org.junit.runners.Suite;
HashCollectionTest.class,
HumanReadableIdTest.class,
ReservedCharactersTest.class,
- StringsTest.class,})
+ StringsTest.class,
+ UrlQueryTest.class})
public class JdkCoreUtilTestSuite {
@BeforeClass
public static void setUp() throws Exception {
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/UrlQueryTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/UrlQueryTest.java
new file mode 100644
index 0000000000..1d8c1cf309
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/util/UrlQueryTest.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Test Case for {@link UrlQuery}
+ *
+ * @author Roberto E. Escobar
+ */
+@RunWith(Parameterized.class)
+public class UrlQueryTest {
+
+ private final String queryString;
+ private final TestData expected;
+
+ public UrlQueryTest(String queryString, TestData expected) {
+ this.queryString = queryString;
+ this.expected = expected;
+ }
+
+ @Test
+ public void testParse() throws UnsupportedEncodingException {
+ UrlQuery query = new UrlQuery();
+ query.parse(queryString);
+
+ Set<String> expectedKeys = expected.keySet();
+ for (String key : expectedKeys) {
+ Assert.assertTrue(query.containsKey(key));
+ }
+ Assert.assertFalse(query.containsKey("dummy"));
+
+ Enumeration<String> keys = query.getParameterNames();
+ Set<String> data = new HashSet<String>();
+ while (keys.hasMoreElements()) {
+ data.add(keys.nextElement());
+ }
+
+ assertEquals(expectedKeys, data);
+
+ for (Entry<String, List<String>> entry : expected.entrySet()) {
+ String[] values = query.getParameterValues(entry.getKey());
+ List<String> actual = new ArrayList<String>();
+ actual.addAll(Arrays.asList(values));
+ java.util.Collections.sort(actual);
+
+ List<String> expected = entry.getValue();
+ java.util.Collections.sort(expected);
+
+ assertEquals(expected, actual);
+ }
+
+ for (Entry<String, String[]> entry : query.getParameterMap().entrySet()) {
+
+ List<String> actual = new ArrayList<String>();
+ actual.addAll(Arrays.asList(entry.getValue()));
+ java.util.Collections.sort(actual);
+
+ List<String> expData = expected.get(entry.getKey());
+ java.util.Collections.sort(expData);
+
+ assertEquals(expData, actual);
+ }
+
+ Assert.assertEquals(queryString, query.toUrl());
+ Assert.assertEquals(queryString, query.toString());
+ }
+
+ private static <T> void assertEquals(Collection<T> expected, Collection<T> actual) {
+ Collection<T> set1 = Collections.setComplement(expected, actual);
+ Collection<T> set2 = Collections.setComplement(actual, expected);
+ Assert.assertTrue(set1.toString(), set1.isEmpty());
+ Assert.assertTrue(set2.toString(), set2.isEmpty());
+ }
+
+ @Parameters
+ public static List<Object[]> getData() {
+ List<Object[]> data = new LinkedList<Object[]>();
+ add(data, "phrase=Hello+Dude&value1=%2212345%22&value2=4%3C6",
+ new TestData().put("phrase", "Hello Dude").put("value1", "\"12345\"").put("value2", "4<6"));
+ add(data, "query+name=Hello+dude&query+name=one+more+string",
+ new TestData().put("query name", "Hello dude", "one more string"));
+ return data;
+ }
+
+ private static final void add(List<Object[]> data, Object... args) {
+ data.add(args);
+ }
+
+ private static final class TestData {
+ private final Map<String, List<String>> data = new TreeMap<String, List<String>>();
+
+ public TestData put(String key, String... values) {
+ List<String> vals = get(key);
+ if (vals == null) {
+ vals = new ArrayList<String>();
+ data.put(key, vals);
+ }
+ for (String value : values) {
+ vals.add(value);
+ }
+ return this;
+ }
+
+ public List<String> get(String key) {
+ return data.get(key);
+ }
+
+ public Set<Entry<String, List<String>>> entrySet() {
+ return data.entrySet();
+ }
+
+ public Set<String> keySet() {
+ return data.keySet();
+ }
+ }
+
+}

Back to the top