1 package org.apache.lucene.facet.example;
3 import java.util.Iterator;
7 import org.apache.lucene.util.LuceneTestCase;
8 import org.apache.lucene.facet.example.ExampleResult;
9 import org.apache.lucene.facet.example.simple.SimpleMain;
10 import org.apache.lucene.facet.search.results.FacetResult;
11 import org.apache.lucene.facet.search.results.FacetResultNode;
14 * Licensed to the Apache Software Foundation (ASF) under one or more
15 * contributor license agreements. See the NOTICE file distributed with
16 * this work for additional information regarding copyright ownership.
17 * The ASF licenses this file to You under the Apache License, Version 2.0
18 * (the "License"); you may not use this file except in compliance with
19 * the License. You may obtain a copy of the License at
21 * http://www.apache.org/licenses/LICENSE-2.0
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS,
25 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
31 * Test that the simple example works as expected. This test helps to verify
32 * that examples code is alive!
34 public class TestSimpleExample extends LuceneTestCase {
37 public void testSimple () throws Exception {
38 ExampleResult res = new SimpleMain().runSimple();
39 assertNotNull("Null result!", res);
40 assertNotNull("Null facet result!", res.getFacetResults());
41 assertEquals("Wrong number of results!",1, res.getFacetResults().size());
42 assertEquals("Wrong number of facets!",3, res.getFacetResults().get(0).getNumValidDescendants());
46 * In drill down test we are drilling down to a facet that appears in a single document.
47 * As result, facets that without drill down got count of 2 will now get a count of 1.
50 public void testDrillDown () throws Exception {
51 ExampleResult res = new SimpleMain().runDrillDown();
52 assertNotNull("Null result!", res);
53 assertNotNull("Null facet result!", res.getFacetResults());
54 assertEquals("Wrong number of results!",1, res.getFacetResults().size());
56 // drill down facet appears in only 1 doc, and that doc has only 2 facets
57 FacetResult facetResult = res.getFacetResults().get(0);
58 assertEquals("Wrong number of facets!",2, facetResult.getNumValidDescendants());
60 Iterator<? extends FacetResultNode> resIterator = facetResult.getFacetResultNode().getSubResults().iterator();
61 assertTrue("Too few results", resIterator.hasNext());
62 assertEquals("wrong count for first result out of 2", 1, (int)resIterator.next().getValue());
63 assertTrue("Too few results", resIterator.hasNext());
64 assertEquals("wrong count for second result out of 2", 1, (int)resIterator.next().getValue());
65 assertFalse("Too many results!", resIterator.hasNext());