~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/attributes/CategoryAttributeImplTest.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.attributes;
2
 
 
3
 
import java.util.ArrayList;
4
 
import java.util.List;
5
 
 
6
 
import org.junit.Test;
7
 
 
8
 
import org.apache.lucene.util.LuceneTestCase;
9
 
import org.apache.lucene.facet.FacetException;
10
 
import org.apache.lucene.facet.index.DummyProperty;
11
 
import org.apache.lucene.facet.index.attributes.CategoryAttribute;
12
 
import org.apache.lucene.facet.index.attributes.CategoryAttributeImpl;
13
 
import org.apache.lucene.facet.taxonomy.CategoryPath;
14
 
 
15
 
/**
16
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
17
 
 * contributor license agreements.  See the NOTICE file distributed with
18
 
 * this work for additional information regarding copyright ownership.
19
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
20
 
 * (the "License"); you may not use this file except in compliance with
21
 
 * the License.  You may obtain a copy of the License at
22
 
 *
23
 
 *     http://www.apache.org/licenses/LICENSE-2.0
24
 
 *
25
 
 * Unless required by applicable law or agreed to in writing, software
26
 
 * distributed under the License is distributed on an "AS IS" BASIS,
27
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
 
 * See the License for the specific language governing permissions and
29
 
 * limitations under the License.
30
 
 */
31
 
 
32
 
public class CategoryAttributeImplTest extends LuceneTestCase {
33
 
 
34
 
  @Test
35
 
  public void testCategoryPath() {
36
 
    CategoryAttribute ca = new CategoryAttributeImpl();
37
 
 
38
 
    assertNull("Category Path should be null", ca.getCategoryPath());
39
 
 
40
 
    CategoryPath cp = new CategoryPath("a", "b");
41
 
    ca.setCategoryPath(cp);
42
 
 
43
 
    assertEquals("Wrong Category Path", cp, ca.getCategoryPath());
44
 
 
45
 
    ca.setCategoryPath(null);
46
 
    assertNull("Category Path should be null", ca.getCategoryPath());
47
 
 
48
 
    ca = new CategoryAttributeImpl(cp);
49
 
    assertEquals("Wrong Category Path", cp, ca.getCategoryPath());
50
 
  }
51
 
 
52
 
  @Test
53
 
  public void testProperties() throws FacetException {
54
 
    CategoryAttribute ca = new CategoryAttributeImpl();
55
 
 
56
 
    assertNull("Attribute should be null", ca
57
 
        .getProperty(DummyProperty.class));
58
 
    assertNull("Attribute classes should be null", ca.getPropertyClasses());
59
 
 
60
 
    ca.addProperty(new DummyProperty());
61
 
    assertEquals("DummyProperty should be in properties",
62
 
        new DummyProperty(), ca.getProperty(DummyProperty.class));
63
 
    assertEquals("Attribute classes should contain 1 element", 1, ca
64
 
        .getPropertyClasses().size());
65
 
 
66
 
    boolean failed = false;
67
 
    try {
68
 
      ca.addProperty(new DummyProperty());
69
 
    } catch (UnsupportedOperationException e) {
70
 
      failed = true;
71
 
    }
72
 
 
73
 
    if (!failed) {
74
 
      fail("Two DummyAttributes added to the same CategoryAttribute");
75
 
    }
76
 
 
77
 
    ca.clearProperties();
78
 
    assertNull("Attribute classes should be null", ca.getPropertyClasses());
79
 
 
80
 
    ca.addProperty(new DummyProperty());
81
 
    assertEquals("DummyProperty should be in properties",
82
 
        new DummyProperty(), ca.getProperty(DummyProperty.class));
83
 
    ca.remove(DummyProperty.class);
84
 
    assertEquals("DummyProperty should not be in properties", null, ca
85
 
        .getProperty(DummyProperty.class));
86
 
    assertNull("Attribute classes should be null", ca.getPropertyClasses());
87
 
 
88
 
    ca.addProperty(new DummyProperty());
89
 
    List<Class<? extends CategoryProperty>> propertyClasses = new ArrayList<Class<? extends CategoryProperty>>();
90
 
    assertEquals("No property expected when no classes given", null, ca
91
 
        .getProperty(propertyClasses));
92
 
    propertyClasses.add(DummyProperty.class);
93
 
    assertEquals("DummyProperty should be in properties",
94
 
        new DummyProperty(), ca.getProperty(propertyClasses));
95
 
    propertyClasses.add(OrdinalProperty.class);
96
 
    assertEquals("DummyProperty should be in properties",
97
 
        new DummyProperty(), ca.getProperty(propertyClasses));
98
 
    propertyClasses.clear();
99
 
    propertyClasses.add(OrdinalProperty.class);
100
 
    assertEquals("No ordinal property expected", null, ca
101
 
        .getProperty(propertyClasses));
102
 
  }
103
 
 
104
 
  @Test
105
 
  public void testCloneCopyToAndSet() throws FacetException {
106
 
    CategoryAttributeImpl ca1 = new CategoryAttributeImpl();
107
 
 
108
 
    CategoryPath cp = new CategoryPath("a", "b");
109
 
    ca1.setCategoryPath(cp);
110
 
    ca1.addProperty(new DummyProperty());
111
 
 
112
 
    CategoryAttribute ca2 = ca1.clone();
113
 
    assertEquals("Error in cloning", ca1, ca2);
114
 
 
115
 
    CategoryAttributeImpl ca3 = new CategoryAttributeImpl();
116
 
    assertNotSame("Should not be the same", ca1, ca3);
117
 
    ca1.copyTo(ca3);
118
 
    assertEquals("Error in cloning", ca1, ca3);
119
 
 
120
 
    ca2.setCategoryPath(null);
121
 
    assertNotSame("Should not be the same", ca1, ca2);
122
 
    ca2.set(ca3);
123
 
    assertEquals("Error in cloning", ca1, ca2);
124
 
  }
125
 
}