// 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.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 = "" + "" + " " + " " + " us-east" + " " + ""; 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 = "" + "" + " " + " " + " us-east" + " " + " " + " " + " " + ""; 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 = "" + " " + "" + "node0" + "" + ""; var 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); } } }