2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.containsString;
12 import static org.junit.Assert.assertFalse;
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;
20 public class Bug6878Test {
23 public void testParsingXPathWithYang11Functions() throws Exception {
24 final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
25 assertFalse(testLog.contains("Could not find function: "));
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 "));
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 "));
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();
45 try (PrintStream out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
47 StmtTestUtils.parseYangSource(yangFile);
49 System.setOut(stdout);
52 return output.toString();