1 package org.apache.lucene.facet.example;
3 import java.util.Iterator;
8 import org.apache.lucene.util.LuceneTestCase;
9 import org.apache.lucene.facet.example.ExampleResult;
10 import org.apache.lucene.facet.example.multiCL.MultiCLMain;
11 import org.apache.lucene.facet.search.results.FacetResult;
12 import org.apache.lucene.facet.search.results.FacetResultNode;
15 * Licensed to the Apache Software Foundation (ASF) under one or more
16 * contributor license agreements. See the NOTICE file distributed with
17 * this work for additional information regarding copyright ownership.
18 * The ASF licenses this file to You under the Apache License, Version 2.0
19 * (the "License"); you may not use this file except in compliance with
20 * the License. You may obtain a copy of the License at
22 * http://www.apache.org/licenses/LICENSE-2.0
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS,
26 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
32 * Test that the multi-category list example works as expected. This test helps
33 * to verify that examples code is alive!
35 public class TestMultiCLExample extends LuceneTestCase {
38 public void testMulti() throws Exception {
39 ExampleResult res = new MultiCLMain().runSample();
40 assertCorrectMultiResults(res);
43 public static void assertCorrectMultiResults(ExampleResult exampleResults)
45 List<FacetResult> results = exampleResults.getFacetResults();
46 FacetResult result = results.get(0);
47 assertNotNull("Result should not be null", result);
48 assertEquals("Invalid label", "5", result.getFacetResultNode()
49 .getLabel().toString());
50 assertEquals("Invalid value", 2.0, result.getFacetResultNode()
52 assertEquals("Invalid # of subresults", 3, result.getFacetResultNode()
55 Iterator<? extends FacetResultNode> subResults = result
56 .getFacetResultNode().getSubResults().iterator();
57 FacetResultNode sub = subResults.next();
58 assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
59 assertEquals("Invalid subresult label", "5/2", sub.getLabel()
61 sub = subResults.next();
62 assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
63 assertEquals("Invalid subresult label", "5/7", sub.getLabel()
65 sub = subResults.next();
66 assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
67 assertEquals("Invalid subresult label", "5/5", sub.getLabel()
70 result = results.get(1);
71 assertNotNull("Result should not be null", result);
72 assertEquals("Invalid label", "5/5", result.getFacetResultNode()
73 .getLabel().toString());
74 assertEquals("Invalid value", 1,
75 result.getFacetResultNode().getValue(), 0.0);
76 assertEquals("Invalid number of subresults", 0, result
77 .getFacetResultNode().getNumSubResults());
79 result = results.get(2);
80 assertNotNull("Result should not be null", result);
81 assertEquals("Invalid label", "6/2", result.getFacetResultNode()
82 .getLabel().toString());
83 assertEquals("Invalid value", 1,
84 result.getFacetResultNode().getValue(), 0.0);
85 assertEquals("Invalid number of subresults", 0, result
86 .getFacetResultNode().getNumSubResults());