1
package org.apache.lucene.facet.index.streaming;
3
import java.io.IOException;
4
import java.util.ArrayList;
5
import java.util.HashSet;
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;
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
24
* http://www.apache.org/licenses/LICENSE-2.0
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.
33
public class CategoryAttributesStreamTest extends CategoryContainerTestBase {
36
* Verifies that a {@link CategoryAttributesStream} accepts
37
* {@link CategoryAttribute} and passes them on as tokens.
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]));
48
// test number of tokens
49
CategoryAttributesStream stream = new CategoryAttributesStream(
52
while (stream.incrementToken()) {
55
assertEquals("Wrong number of tokens", 3, nTokens);
60
while (stream.incrementToken()) {
63
assertEquals("Wrong number of tokens", 3, nTokens);
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]);
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(':'));
79
assertTrue("all category paths should have been found", pathsSet