diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-03-10 14:22:14 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-03-10 14:22:14 +0100 |
commit | 49498ed0fd54e21161303901fb1198ac0ce3c885 (patch) | |
tree | e8873fca01a7fabe608ec94154615fa9f0b21722 /config-model | |
parent | 4390a0a5c47681708ce4e6665fce64d4214d3461 (diff) |
Simplify
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java | 62 |
1 files changed, 33 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..1e3a0500844 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,47 +19,53 @@ 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); + } + + 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>"; - ApplicationPackage app = new MockApplicationPackage.Builder() + 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); } } |