summaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/ModelContextImplTest.java
blob: 3102163df0d4d012d605706dde85c56cdd5fa1c1 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;

import com.yahoo.component.Version;
import com.yahoo.config.model.api.ContainerEndpoint;
import com.yahoo.config.model.api.ModelContext;
import com.yahoo.config.model.application.provider.BaseDeployLogger;
import com.yahoo.config.model.application.provider.MockFileRegistry;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Rotation;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.config.server.deploy.ModelContextImpl;
import com.yahoo.vespa.flags.InMemoryFlagSource;
import org.junit.Test;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
 * @author Ulf Lilleengen
 */
public class ModelContextImplTest {
    @Test
    public void testModelContextTest() {

        final Rotation rotation = new Rotation("this.is.a.mock.rotation");
        final Set<Rotation> rotations = Collections.singleton(rotation);

        final ContainerEndpoint endpoint = new ContainerEndpoint("foo", List.of("a", "b"));
        final Set<ContainerEndpoint> endpoints = Collections.singleton(endpoint);

        final InMemoryFlagSource flagSource = new InMemoryFlagSource();

        ModelContext context = new ModelContextImpl(
                MockApplicationPackage.createEmpty(),
                Optional.empty(),
                Optional.empty(),
                new BaseDeployLogger(),
                new StaticConfigDefinitionRepo(),
                new MockFileRegistry(),
                Optional.empty(),
                new ModelContextImpl.Properties(
                        ApplicationId.defaultId(),
                        true,
                        Collections.emptyList(),
                        null,
                        null,
                        null,
                        false,
                        Zone.defaultZone(),
                        rotations,
                        endpoints,
                        false,
                        false,
                        flagSource,
                        null),
                Optional.empty(),
                new Version(6), 
                new Version(6));
        assertTrue(context.applicationPackage() instanceof MockApplicationPackage);
        assertFalse(context.hostProvisioner().isPresent());
        assertFalse(context.permanentApplicationPackage().isPresent());
        assertFalse(context.previousModel().isPresent());
        assertTrue(context.getFileRegistry() instanceof MockFileRegistry);
        assertTrue(context.configDefinitionRepo() instanceof StaticConfigDefinitionRepo);
        assertThat(context.properties().applicationId(), is(ApplicationId.defaultId()));
        assertTrue(context.properties().configServerSpecs().isEmpty());
        assertTrue(context.properties().multitenant());
        assertNotNull(context.properties().zone());
        assertFalse(context.properties().hostedVespa());
        assertThat(context.properties().rotations(), equalTo(rotations));
        assertThat(context.properties().endpoints(), equalTo(endpoints));
        assertThat(context.properties().isFirstTimeDeployment(), equalTo(false));
    }
}