aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
blob: 570c835c617ad0fcfaafd4d683f266eacae418c0 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition;

import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.model.test.TestDriver;
import com.yahoo.config.model.test.TestRoot;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import org.junit.Test;

import java.io.File;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

/**
 * @author lulf
 * @since 5.20
 */
public class RankProfileRegistryTest {
    private static final String TESTDIR = "src/test/cfg/search/data/v2/inherited_rankprofiles";

    @Test
    public void testRankProfileInheritance() {
        TestRoot root = new TestDriver().buildModel(FilesApplicationPackage.fromFile(new File(TESTDIR)));
        RankProfilesConfig left = root.getConfig(RankProfilesConfig.class, "inherit/search/cluster.inherit/left");
        RankProfilesConfig right = root.getConfig(RankProfilesConfig.class, "inherit/search/cluster.inherit/right");
        System.out.println(left);
        assertThat(left.rankprofile().size(), is(3));
        System.out.println("\n\n");
        System.out.println(right);
        assertThat(right.rankprofile().size(), is(2));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testRankProfileDuplicateNameIsIllegal() {
        Search search = new Search("foo", null);
        RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
        final RankProfile barRankProfile = new RankProfile("bar", search, rankProfileRegistry);
        rankProfileRegistry.addRankProfile(barRankProfile);
        rankProfileRegistry.addRankProfile(barRankProfile);
    }

    @Test
    public void testRankProfileDuplicateNameLegalForOverridableRankProfiles() {
        Search search = new Search("foo", null);
        RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);

        for (String rankProfileName : RankProfileRegistry.overridableRankProfileNames) {
            assertNull(rankProfileRegistry.getRankProfile(search, rankProfileName).getMacros().get("foo"));
            final RankProfile rankProfileWithAddedMacro = new RankProfile(rankProfileName, search, rankProfileRegistry);
            rankProfileWithAddedMacro.addMacro("foo", true);
            rankProfileRegistry.addRankProfile(rankProfileWithAddedMacro);
            assertNotNull(rankProfileRegistry.getRankProfile(search, rankProfileName).getMacros().get("foo"));
        }
    }
}