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

import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.config.model.test.MockRoot;
import org.junit.Test;

import java.util.Optional;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

/**
 * @author lulf
 * @since 5.1
 */
public class ConfigModelContextTest {

    @Test
    public void testConfigModelContext() {
        AbstractConfigProducer root = new MockRoot();
        String id = "foobar";
        ApplicationPackage pkg = new MockApplicationPackage.Builder()
                .withServices("<services version=\"1.0\"><admin version=\"2.0\" /></services>")
                .build();
        DeployState deployState = DeployState.createTestState(pkg);
        DeployLogger logger = deployState.getDeployLogger();
        ConfigModelContext ctx = ConfigModelContext.create(deployState, null, root, id);
        assertThat(ctx.getApplicationPackage(), is(pkg));
        assertThat(ctx.getProducerId(), is(id));
        assertThat(ctx.getParentProducer(), is(root));
        assertThat(ctx.getDeployLogger(), is(logger));
        ctx = ConfigModelContext.create(null, root, id);
        assertThat(ctx.getProducerId(), is(id));
        assertThat(ctx.getParentProducer(), is(root));
        AbstractConfigProducer newRoot = new MockRoot("bar");
        ctx = ctx.withParent(newRoot);
        assertThat(ctx.getProducerId(), is(id));
        assertThat(ctx.getParentProducer(), is(not(root)));
        assertThat(ctx.getParentProducer(), is(newRoot));
    }

}