blob: ff765af1bd8281ab78c638bcf6d0446b86a79d4e (
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
86
87
88
89
|
// Copyright Yahoo. 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.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.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author hmusum
*/
public class DeploymentSpecValidatorTest {
@Test
public void testDeploymentWithNonExistentGlobalId() {
var deploymentXml = "<?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>";
assertValidationError("Attribute 'globalServiceId' in instance default: 'non-existing' specified in " +
"deployment.xml does not match any container cluster ID", deploymentXml);
}
@Test
public void testEndpointNonExistentContainerId() {
var deploymentXml = "<?xml version='1.0' encoding='UTF-8'?>" +
"<deployment version='1.0'>" +
" <test />" +
" <prod>" +
" <region active='true'>us-east</region>" +
" </prod>" +
" <endpoints>" +
" <endpoint container-id='non-existing'/>" +
" </endpoints>" +
"</deployment>";
assertValidationError("Endpoint 'default' in instance default: 'non-existing' specified in " +
"deployment.xml does not match any container cluster ID", deploymentXml);
}
private static void assertValidationError(String message, String deploymentXml) {
var simpleHosts = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<hosts> " +
"<host name=\"localhost\">" +
"<alias>node0</alias>" +
"</host>" +
"</hosts>";
var 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>";
var app = new MockApplicationPackage.Builder()
.withHosts(simpleHosts)
.withServices(services)
.withDeploymentSpec(deploymentXml)
.build();
var builder = new DeployState.Builder().applicationPackage(app);
try {
var deployState = builder.build();
VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);
new DeploymentSpecValidator().validate(model, deployState);
fail("Did not get expected exception");
} catch (IllegalArgumentException e) {
assertEquals(message, e.getMessage());
} catch (SAXException|IOException e) {
throw new RuntimeException(e);
}
}
}
|