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.Matchers.containsString;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertThat;
14 import java.io.ByteArrayOutputStream;
15 import java.io.PrintStream;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
19 public class Bug6878Test {
22 public void testParsingXPathWithYang11Functions() throws Exception {
23 final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
24 assertFalse(testLog.contains("Could not find function: "));
28 public void shouldLogInvalidYang10XPath() throws Exception {
29 final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
30 assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
34 public void shouldLogInvalidYang10XPath2() throws Exception {
35 final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
36 assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
39 @SuppressWarnings("checkstyle:regexpSinglelineJava")
40 private static String parseAndcaptureLog(final String yangFile) throws Exception {
41 final PrintStream stdout = System.out;
42 final ByteArrayOutputStream output = new ByteArrayOutputStream();
44 try (PrintStream out = new PrintStream(output, true, "UTF-8")) {
46 StmtTestUtils.parseYangSource(yangFile);
48 System.setOut(stdout);
51 return output.toString();