aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/config/model/test/TestRoot.java
blob: f243c4635c731bf10be92bee1f3f556a60a7af5d (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
60
61
62
63
64
65
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.test;

import com.yahoo.api.annotations.Beta;
import com.yahoo.config.ConfigInstance;
import com.yahoo.config.model.ConfigModel;
import com.yahoo.vespa.model.HostResource;
import com.yahoo.vespa.model.VespaModel;

import java.util.List;

/**
 * Test utility class that provides many methods for inspecting the state of a completely built model
 *
 * @author Ulf Lilleengen
 */
@Beta
public class TestRoot {
    private final VespaModel model;
    TestRoot(VespaModel model) {
        this.model = model;
    }

    /**
     * Get a list of all config models of a particular type.
     *
     * @param clazz The class of the models to find.
     * @return A list of models of given type.
     */
    public <MODEL extends ConfigModel> List<MODEL> getConfigModels(Class<MODEL> clazz) {
        return model.configModelRepo().getModels(clazz);
    }

    /**
     * Ask model to populate builder with config for a given config id. This method gives the same config as the
     * configserver would return to its clients.
     * @param builder The builder to populate
     * @param configId The config id of the producer to ask for config.
     * @return the same builder.
     */
    public <BUILDER extends ConfigInstance.Builder> BUILDER getConfig(BUILDER builder, String configId) {
        return (BUILDER) model.getConfig(builder, configId);
    }

    /**
     * Request config of a given type and id. This method gives the same config as the configserver would return to
     * its clients.
     *
     * @param clazz Type of config to request.
     * @param configId The config id of the producer to ask for config.
     * @return A config object of the appropriate type with config values set.
     */
    public <CONFIGTYPE extends ConfigInstance> CONFIGTYPE getConfig(Class<CONFIGTYPE> clazz, String configId) {
        return model.getConfig(clazz, configId);
    }

    /**
     * Retrieve the hosts available in this model. Useful to verify that hostnames are set correctly etc.
     *
     * @return A list of hosts.
     */
    public List<HostResource> getHosts() {
        return model.hostSystem().getHosts();
    }
}