~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryAttributesStreamTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.facet.index.streaming;
2
 
 
3
 
import java.io.IOException;
4
 
import java.util.ArrayList;
5
 
import java.util.HashSet;
6
 
import java.util.Set;
7
 
 
8
 
import org.junit.Test;
9
 
 
10
 
import org.apache.lucene.facet.index.CategoryContainerTestBase;
11
 
import org.apache.lucene.facet.index.attributes.CategoryAttribute;
12
 
import org.apache.lucene.facet.index.attributes.CategoryAttributeImpl;
13
 
import org.apache.lucene.facet.index.streaming.CategoryAttributesStream;
14
 
import org.apache.lucene.facet.taxonomy.CategoryPath;
15
 
 
16
 
/**
17
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
18
 
 * contributor license agreements.  See the NOTICE file distributed with
19
 
 * this work for additional information regarding copyright ownership.
20
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
21
 
 * (the "License"); you may not use this file except in compliance with
22
 
 * the License.  You may obtain a copy of the License at
23
 
 *
24
 
 *     http://www.apache.org/licenses/LICENSE-2.0
25
 
 *
26
 
 * Unless required by applicable law or agreed to in writing, software
27
 
 * distributed under the License is distributed on an "AS IS" BASIS,
28
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
 
 * See the License for the specific language governing permissions and
30
 
 * limitations under the License.
31
 
 */
32
 
 
33
 
public class CategoryAttributesStreamTest extends CategoryContainerTestBase {
34
 
 
35
 
  /**
36
 
   * Verifies that a {@link CategoryAttributesStream} accepts
37
 
   * {@link CategoryAttribute} and passes them on as tokens.
38
 
   * 
39
 
   * @throws IOException
40
 
   */
41
 
  @Test
42
 
  public void testStream() throws IOException {
43
 
    ArrayList<CategoryAttribute> attributesList = new ArrayList<CategoryAttribute>();
44
 
    for (int i = 0; i < initialCatgeories.length; i++) {
45
 
      attributesList.add(new CategoryAttributeImpl(initialCatgeories[i]));
46
 
    }
47
 
 
48
 
    // test number of tokens
49
 
    CategoryAttributesStream stream = new CategoryAttributesStream(
50
 
        attributesList);
51
 
    int nTokens = 0;
52
 
    while (stream.incrementToken()) {
53
 
      nTokens++;
54
 
    }
55
 
    assertEquals("Wrong number of tokens", 3, nTokens);
56
 
 
57
 
    // test reset
58
 
    stream.reset();
59
 
    nTokens = 0;
60
 
    while (stream.incrementToken()) {
61
 
      nTokens++;
62
 
    }
63
 
    assertEquals("Wrong number of tokens", 3, nTokens);
64
 
 
65
 
    // test reset and contents
66
 
    Set<CategoryPath> pathsSet = new HashSet<CategoryPath>();
67
 
    for (int i = 0; i < initialCatgeories.length; i++) {
68
 
      pathsSet.add(initialCatgeories[i]);
69
 
    }
70
 
    stream.reset();
71
 
    while (stream.incrementToken()) {
72
 
      CategoryAttribute fromStream = stream
73
 
          .getAttribute(CategoryAttribute.class);
74
 
      if (!pathsSet.remove(fromStream.getCategoryPath())) {
75
 
        fail("Unexpected category path: "
76
 
            + fromStream.getCategoryPath().toString(':'));
77
 
      }
78
 
    }
79
 
    assertTrue("all category paths should have been found", pathsSet
80
 
        .isEmpty());
81
 
  }
82
 
}