aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-03-11 10:56:41 +0100
committerGitHub <noreply@github.com>2020-03-11 10:56:41 +0100
commit1a755712ff91739da40925fb90ed912ac02ff4d8 (patch)
treeeda67cd9494d6c37ce843296b8eceec06c52de81 /config-model/src/test/java/com
parentdf3f44d288c6a053a947d575b07dfdb9d710e330 (diff)
parent1dd80215b69d348f89753946d34e7259fb95f2b3 (diff)
Merge pull request #12525 from vespa-engine/mpolden/validate-endpoint-container-id
Validate that endpoint points to an existing container cluster
Diffstat (limited to 'config-model/src/test/java/com')
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java79
1 files changed, 50 insertions, 29 deletions
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java
index c6d56455d44..e0366b62933 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java
@@ -1,7 +1,6 @@
// 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;
@@ -11,8 +10,7 @@ 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.assertEquals;
import static org.junit.Assert.fail;
/**
@@ -21,48 +19,71 @@ import static org.junit.Assert.fail;
public class DeploymentSpecValidatorTest {
@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'?>" +
+ 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);
+ }
- ApplicationPackage app = new MockApplicationPackage.Builder()
+ @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(deploymentSpec)
+ .withDeploymentSpec(deploymentXml)
.build();
- DeployState.Builder builder = new DeployState.Builder().applicationPackage(app);
+ var builder = new DeployState.Builder().applicationPackage(app);
try {
- final DeployState deployState = builder.build();
+ 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) {
- assertThat(e.getMessage(), containsString("specified in deployment.xml does not match any container cluster id"));
+ assertEquals(message, e.getMessage());
+ } catch (SAXException|IOException e) {
+ throw new RuntimeException(e);
}
}
}
+