summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java
blob: 9e16b7312eb5ae40d5f1bd496221a03a32037fa7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.result.test;

import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;

/**
 * @author bratseth
 */
public class FillingTestCase extends junit.framework.TestCase {

    public void testFillingAPIConsistency() {
        HitGroup group=new HitGroup();
        group.add(new Hit("hit:1"));
        group.add(new Hit("hit:2"));
        assertTrue(group.isFilled("summary"));
    }

    public void testFillingAPIConsistencyTwoPhase() {
        HitGroup group=new HitGroup();
        group.add(createNonFilled("hit:1"));
        group.add(createNonFilled("hit:2"));
        assertFalse(group.isFilled("summary"));
        fillHitsIn(group, "summary");
        group.analyze();
        assertTrue(group.isFilled("summary"));  // consistent again
    }

    public void testFillingAPIConsistencyThreePhase() {
        HitGroup group=new HitGroup();
        group.add(createNonFilled("hit:1"));
        group.add(createNonFilled("hit:2"));
        assertFalse(group.isFilled("summary"));
        assertFalse(group.isFilled("otherSummary"));
        fillHitsIn(group, "otherSummary");
        group.analyze();
        assertFalse(group.isFilled("summary"));
        assertTrue(group.isFilled("otherSummary"));
        fillHitsIn(group, "summary");
        assertTrue(group.isFilled("otherSummary"));
        group.analyze();
        assertTrue(group.isFilled("summary"));  // consistent again
        assertTrue(group.isFilled("otherSummary"));
    }

    private Hit createNonFilled(String id) {
        Hit hit=new Hit(id);
        hit.setFillable();
        return hit;
    }

    private void fillHitsIn(HitGroup group,String summary) {
        for (Hit hit : group.asList()) {
            if (hit.isMeta()) continue;
            hit.setFilled(summary);
        }
    }

}