diff options
| author | luccioman <luccioman@users.noreply.github.com> | 2018-02-06 17:17:13 +0100 |
|---|---|---|
| committer | luccioman <luccioman@users.noreply.github.com> | 2018-02-06 17:17:13 +0100 |
| commit | 33593c22e9c3f443b2636dd824965f34d2a26931 (patch) | |
| tree | 9deadbe356f9a4af52685d41432ac70135872876 /test/java | |
| parent | a9dc0874c0042cd4518e61507f6187f1fc2c595e (diff) | |
Fixed loss of other modifiers on keywords/tags search navigation links
Diffstat (limited to 'test/java')
| -rw-r--r-- | test/java/net/yacy/search/query/QueryParamsTest.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/java/net/yacy/search/query/QueryParamsTest.java b/test/java/net/yacy/search/query/QueryParamsTest.java index 8cd2a250d..a7753a5c6 100644 --- a/test/java/net/yacy/search/query/QueryParamsTest.java +++ b/test/java/net/yacy/search/query/QueryParamsTest.java @@ -23,6 +23,9 @@ package net.yacy.search.query; import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import org.junit.Assert; import org.junit.Test; @@ -233,4 +236,48 @@ public class QueryParamsTest { Assert.assertEquals(QueryParams.catchall_pattern.toString(), filter); } + + /** + * Test removal of old modifier(s) when building a search navigation URL. + */ + @Test + public void testRemoveOldModifiersFromNavUrl() { + final String baseURL = "yacysearch.html?query=test+search+terms"; + + final String newModifier = "keywords:new"; + + final Map<String, String> modifiers2Expected = new HashMap<>(); + /* No existing modifiers */ + modifiers2Expected.put(baseURL, baseURL); + + /* No existing modifiers */ + modifiers2Expected.put(baseURL + "+keywords:old", baseURL); + + /* One modifier matching the new modifier's name, but with a different value */ + modifiers2Expected.put(baseURL + "+keywords:old", baseURL); + + /* One modifier matching the new modifier's name, with the same value */ + modifiers2Expected.put(baseURL + "+keywords:new", baseURL); + + /* Two modifiers matching the new modifier's name */ + modifiers2Expected.put(baseURL + "+keywords:old keywords:new", baseURL); + + /* One modifier with a different name than the new one */ + modifiers2Expected.put(baseURL + "+site:example.org", baseURL + "+site:example.org"); + + /* Two modifiers, only one matching the new modifier's name */ + modifiers2Expected.put(baseURL + "+site:example.org keywords:old", baseURL + "+site:example.org"); + + /* Three modifiers, the one not matching the new modifier's name in the middle of the others */ + modifiers2Expected.put(baseURL + "+keywords:old site:example.org keywords:other", baseURL + "+site:example.org"); + + /* Three modifiers, only one matching the new modifier's name. The others having two different naming styles. */ + modifiers2Expected.put(baseURL + "+keywords:old /language/en site:example.org keywords:other", baseURL + "+/language/en site:example.org"); + + for(final Entry<String, String> entry : modifiers2Expected.entrySet()) { + StringBuilder sb = new StringBuilder(entry.getKey()); + QueryParams.removeOldModifiersFromNavUrl(sb, newModifier); + Assert.assertEquals(entry.getValue(), sb.toString()); + } + } } |
