@Test
  public void testNamedWildcardAndLookupWithWildcard() {
    PathTrie<String> trie = new PathTrie<String>();
    trie.insert("x/{test}", "test1");
    trie.insert("{test}/a", "test2");
    trie.insert("/{test}", "test3");
    trie.insert("/{test}/_endpoint", "test4");
    trie.insert("/*/{test}/_endpoint", "test5");

    Map<String, String> params = newHashMap();
    assertThat(trie.retrieve("/x/*", params), equalTo("test1"));
    assertThat(params.get("test"), equalTo("*"));

    params = newHashMap();
    assertThat(trie.retrieve("/b/a", params), equalTo("test2"));
    assertThat(params.get("test"), equalTo("b"));

    params = newHashMap();
    assertThat(trie.retrieve("/*", params), equalTo("test3"));
    assertThat(params.get("test"), equalTo("*"));

    params = newHashMap();
    assertThat(trie.retrieve("/*/_endpoint", params), equalTo("test4"));
    assertThat(params.get("test"), equalTo("*"));

    params = newHashMap();
    assertThat(trie.retrieve("a/*/_endpoint", params), equalTo("test5"));
    assertThat(params.get("test"), equalTo("*"));
  }
예제 #2
0
 @Test
 public void testEndWithNamedWildcardAndLookupWithWildcard() {
   PathTrie<String> trie = new PathTrie<String>();
   trie.insert("x/{test}", "test1");
   Map<String, String> params = newHashMap();
   assertThat(trie.retrieve("/x/*", params), equalTo("test1"));
   assertThat(params.get("test"), equalTo("*"));
 }
  @Test
  public void testSameNameOnDifferentPath() {
    PathTrie<String> trie = new PathTrie<String>();
    trie.insert("/a/c/{name}", "test1");
    trie.insert("/b/{name}", "test2");

    Map<String, String> params = newHashMap();
    assertThat(trie.retrieve("/a/c/test", params), equalTo("test1"));
    assertThat(params.get("name"), equalTo("test"));

    params.clear();
    assertThat(trie.retrieve("/b/testX", params), equalTo("test2"));
    assertThat(params.get("name"), equalTo("testX"));
  }
  @Test
  public void testPreferNonWildcardExecution() {
    PathTrie<String> trie = new PathTrie<String>();
    trie.insert("{test}", "test1");
    trie.insert("b", "test2");
    trie.insert("{test}/a", "test3");
    trie.insert("b/a", "test4");

    Map<String, String> params = newHashMap();
    assertThat(trie.retrieve("/b", params), equalTo("test2"));
    assertThat(trie.retrieve("/b/a", params), equalTo("test4"));
  }
 @Test
 public void testEmptyPath() {
   PathTrie<String> trie = new PathTrie<String>();
   trie.insert("/", "walla");
   assertThat(trie.retrieve(""), equalTo("walla"));
 }
  @Test
  public void testPath() {
    PathTrie<String> trie = new PathTrie<String>();
    trie.insert("/a/b/c", "walla");
    trie.insert("a/d/g", "kuku");
    trie.insert("x/b/c", "lala");
    trie.insert("a/x/*", "one");
    trie.insert("a/b/*", "two");
    trie.insert("*/*/x", "three");
    trie.insert("{index}/insert/{docId}", "bingo");

    assertThat(trie.retrieve("a/b/c"), equalTo("walla"));
    assertThat(trie.retrieve("a/d/g"), equalTo("kuku"));
    assertThat(trie.retrieve("x/b/c"), equalTo("lala"));
    assertThat(trie.retrieve("a/x/b"), equalTo("one"));
    assertThat(trie.retrieve("a/b/d"), equalTo("two"));

    assertThat(trie.retrieve("a/b"), nullValue());
    assertThat(trie.retrieve("a/b/c/d"), nullValue());
    assertThat(trie.retrieve("g/t/x"), equalTo("three"));

    Map<String, String> params = newHashMap();
    assertThat(trie.retrieve("index1/insert/12", params), equalTo("bingo"));
    assertThat(params.size(), equalTo(2));
    assertThat(params.get("index"), equalTo("index1"));
    assertThat(params.get("docId"), equalTo("12"));
  }