summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentFileValidatorTest.java
blob: 5fc3f815b0936ce35c3ca19dc5afa25e48271f8c (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation;

import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.model.NullConfigModelRegistry;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.vespa.model.VespaModel;
import org.junit.Test;
import org.xml.sax.SAXException;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

/**
 * @author hmusum
 */
public class DeploymentFileValidatorTest {

    @Test
    public void testDeploymentWithNonExistentGlobalId() throws IOException, SAXException {
        final String simpleHosts = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                "<hosts>  " +
                "<host name=\"localhost\">" +
                "<alias>node0</alias>" +
                "</host>" +
                "</hosts>";

        final String services = "<services version='1.0'>" +
                "  <admin  version='2.0'>" +
                "    <adminserver hostalias='node0' />" +
                "  </admin>" +
                "  <container id='default' version='1.0'>" +
                "    <search/>" +
                "      <nodes>" +
                "        <node hostalias='node0'/>" +
                "     </nodes>" +
                "   </container>" +
                "</services>";

        final String deploymentSpec = "<?xml version='1.0' encoding='UTF-8'?>" +
                "<deployment version='1.0'>" +
                "  <test />" +
                "  <prod global-service-id='non-existing'>" +
                "    <region active='true'>us-east</region>" +
                "  </prod>" +
                "</deployment>";

        ApplicationPackage app = new MockApplicationPackage.Builder()
                .withHosts(simpleHosts)
                .withServices(services)
                .withDeploymentSpec(deploymentSpec)
                .build();
        DeployState.Builder builder = new DeployState.Builder().applicationPackage(app);
        try {
            final DeployState deployState = builder.build();
            VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);
            new DeploymentFileValidator().validate(model, deployState);
            fail("Did not get expected exception");
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), containsString("specified in deployment.xml does not match any container cluster id"));
        }
    }

}