aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java
blob: a19bc2347d43558240779517eb8dca3905b6c344 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.builder.xml;

import org.junit.jupiter.api.Test;
import org.xml.sax.InputSource;
import java.io.FileReader;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author hmusum
 */
public class XmlErrorHandlingTest {

    @Test
    void requireExceptionWithSourceAndFilenameAndLineNumber() {
        try {
            XmlHelper.getDocument(new FileReader("src/test/cfg/application/invalid-services-syntax/services.xml"), "services.xml");
        } catch (Exception e) {
            assertEquals("Invalid XML in services.xml: The element type \"config\" must be terminated by the matching end-tag \"</config>\". [7:5]",
                    e.getMessage());
        }
    }


    @Test
    void requireExceptionWithLineNumber() {
        try {
            XmlHelper.getDocumentBuilder().parse(
                    new InputSource(new FileReader("src/test/cfg/application/invalid-services-syntax/services.xml")));
        } catch (Exception e) {
            assertEquals("Invalid XML (unknown source): The element type \"config\" must be terminated by the matching end-tag \"</config>\". [7:5]",
                    e.getMessage());
        }
    }

}