Search in sources :

Example 1 with PathTrie

use of org.apache.solr.util.PathTrie in project lucene-solr by apache.

the class TestApiFramework method testTrailingTemplatePaths.

public void testTrailingTemplatePaths() {
    PathTrie<Api> registry = new PathTrie<>();
    Api api = new Api(EMPTY_SPEC) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
        }
    };
    Api intropsect = new ApiBag.IntrospectApi(api, false);
    ApiBag.registerIntrospect(Collections.emptyMap(), registry, "/c/.system/blob/{name}", intropsect);
    ApiBag.registerIntrospect(Collections.emptyMap(), registry, "/c/.system/{x}/{name}", intropsect);
    assertEquals(intropsect, registry.lookup("/c/.system/blob/random_string/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/blob/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/v1/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/v1/v2/_introspect", new HashMap<>()));
}
Also used : PathTrie(org.apache.solr.util.PathTrie) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) HashMap(java.util.HashMap) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) Api(org.apache.solr.api.Api)

Example 2 with PathTrie

use of org.apache.solr.util.PathTrie in project lucene-solr by apache.

the class TestPathTrie method testPathTrie.

public void testPathTrie() {
    PathTrie<String> pathTrie = new PathTrie<>(ImmutableSet.of("_introspect"));
    pathTrie.insert("/", emptyMap(), "R");
    pathTrie.insert("/aa", emptyMap(), "d");
    pathTrie.insert("/aa/bb/{cc}/dd", emptyMap(), "a");
    pathTrie.insert("/$handlerName/{cc}/dd", singletonMap(HANDLER_NAME, "test"), "test");
    pathTrie.insert("/aa/bb/{cc}/{xx}", emptyMap(), "b");
    pathTrie.insert("/aa/bb", emptyMap(), "c");
    HashMap templateValues = new HashMap<>();
    assertEquals("R", pathTrie.lookup("/", templateValues, null));
    assertEquals("d", pathTrie.lookup("/aa", templateValues, null));
    assertEquals("a", pathTrie.lookup("/aa/bb/hello/dd", templateValues, null));
    templateValues.clear();
    assertEquals("test", pathTrie.lookup("/test/hello/dd", templateValues, null));
    assertEquals("hello", templateValues.get("cc"));
    templateValues.clear();
    assertEquals("b", pathTrie.lookup("/aa/bb/hello/world", templateValues, null));
    assertEquals("hello", templateValues.get("cc"));
    assertEquals("world", templateValues.get("xx"));
    Set<String> subPaths = new HashSet<>();
    templateValues.clear();
    pathTrie.lookup("/aa", templateValues, subPaths);
    assertEquals(3, subPaths.size());
}
Also used : PathTrie(org.apache.solr.util.PathTrie) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)2 PathTrie (org.apache.solr.util.PathTrie)2 HashSet (java.util.HashSet)1 Api (org.apache.solr.api.Api)1 CompositeApi (org.apache.solr.api.V2HttpCall.CompositeApi)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)1