diff options
Diffstat (limited to 'config-model/src/test/java/com')
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java | 79 |
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); } } } + |