From aee7ff2c99074b5ba90000b91ed73d9465c7b2eb Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 23 Apr 2021 08:38:39 +0200 Subject: Make sure we are able to output context for validation errors --- .../cfg/application/invalid-services-syntax/services.xml | 11 +++++++++++ .../com/yahoo/config/model/ApplicationDeployTest.java | 12 ++++++++++-- .../model/application/provider/SchemaValidatorTest.java | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 config-model/src/test/cfg/application/invalid-services-syntax/services.xml (limited to 'config-model') diff --git a/config-model/src/test/cfg/application/invalid-services-syntax/services.xml b/config-model/src/test/cfg/application/invalid-services-syntax/services.xml new file mode 100644 index 00000000000..77b6fc0e33a --- /dev/null +++ b/config-model/src/test/cfg/application/invalid-services-syntax/services.xml @@ -0,0 +1,11 @@ + + + + + default + + + + + + diff --git a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java index 9780e9b503a..75cb41be13f 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.model; import com.google.common.io.Files; @@ -197,13 +197,21 @@ public class ApplicationDeployTest { @Test public void testThatAppWithInvalidParallelDeploymentFails() throws IOException { + String expectedMessage = "4: \n" + + "5: \n" + + "6: \n" + + "7: \n" + + "8: \n" + + "9: \n" + + "10:\n"; File tmpDir = tmpFolder.getRoot(); IOUtils.copyDirectory(new File(TESTDIR, "invalid_parallel_deployment_xml"), tmpDir); try { ApplicationPackageTester.create(tmpDir.getAbsolutePath()); fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("Invalid XML according to XML schema, error in deployment.xml: element \"instance\" not allowed here; expected the element end-tag or element \"delay\", \"region\", \"steps\" or \"test\" [7:30], input:\n", e.getMessage()); + assertEquals("Invalid XML according to XML schema, error in deployment.xml: element \"instance\" not allowed here; expected the element end-tag or element \"delay\", \"region\", \"steps\" or \"test\" [7:30], input:\n" + expectedMessage, + e.getMessage()); } } diff --git a/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java b/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java index c2938746443..3849e9e03fd 100644 --- a/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java @@ -2,12 +2,14 @@ package com.yahoo.config.model.application.provider; import com.yahoo.component.Version; +import com.yahoo.io.IOUtils; import com.yahoo.vespa.config.VespaVersion; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.xml.sax.InputSource; +import java.io.File; import java.io.IOException; import java.io.StringReader; @@ -47,15 +49,15 @@ public class SchemaValidatorTest { @Test public void testXMLParse() throws IOException { SchemaValidator validator = createValidator(); - validator.validate(new InputSource(new StringReader(okServices)), "services.xml"); + validator.validate(new StringReader(okServices)); } @Test public void testXMLParseError() throws IOException { SchemaValidator validator = createValidator(); expectedException.expect(RuntimeException.class); - expectedException.expectMessage(expectedErrorMessage("services.xml")); - validator.validate(new InputSource(new StringReader(invalidServices)), "services.xml"); + expectedException.expectMessage(expectedErrorMessage("input")); + validator.validate(new StringReader(invalidServices)); } @Test @@ -72,6 +74,14 @@ public class SchemaValidatorTest { validator.validate(new StringReader(invalidServices)); } + @Test + public void testXMLParseErrorFromFile() throws IOException { + SchemaValidator validator = createValidator(); + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage(expectedErrorMessage("services.xml")); + validator.validate(new File("src/test/cfg/application/invalid-services-syntax/services.xml")); + } + private SchemaValidator createValidator() { return new SchemaValidators(new Version(VespaVersion.major)).servicesXmlValidator(); } -- cgit v1.2.3