b6201bca7b9f28d7694b2f0bddedc4b7c160a735
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6878Test.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
9
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.containsString;
12 import static org.junit.Assert.assertFalse;
13
14 import java.io.ByteArrayOutputStream;
15 import java.io.PrintStream;
16 import java.nio.charset.StandardCharsets;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
19
20 public class Bug6878Test {
21
22     @Test
23     public void testParsingXPathWithYang11Functions() throws Exception {
24         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
25         assertFalse(testLog.contains("Could not find function: "));
26     }
27
28     @Test
29     public void shouldLogInvalidYang10XPath() throws Exception {
30         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
31         assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
32     }
33
34     @Test
35     public void shouldLogInvalidYang10XPath2() throws Exception {
36         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
37         assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
38     }
39
40     @SuppressWarnings("checkstyle:regexpSinglelineJava")
41     private static String parseAndcaptureLog(final String yangFile) throws Exception {
42         final PrintStream stdout = System.out;
43         final ByteArrayOutputStream output = new ByteArrayOutputStream();
44
45         try (PrintStream out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
46             System.setOut(out);
47             StmtTestUtils.parseYangSource(yangFile);
48         } finally {
49             System.setOut(stdout);
50         }
51
52         return output.toString();
53     }
54 }