97b99d06a8116b4da03fd37bc3287261ea653199
[yangtools.git] / yang / yang-parser-impl / 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.io.ByteArrayOutputStream;
16 import java.io.PrintStream;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
20
21 public class Bug6878Test {
22
23     @Test
24     public void testParsingXPathWithYang11Functions() throws Exception {
25         final PrintStream stdout = System.out;
26         final ByteArrayOutputStream output = new ByteArrayOutputStream();
27         final String testLog;
28
29         System.setOut(new PrintStream(output, true, "UTF-8"));
30
31         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6878/foo.yang");
32         assertNotNull(schemaContext);
33
34         testLog = output.toString();
35         assertFalse(testLog.contains("Could not find function: "));
36         System.setOut(stdout);
37     }
38
39     @Test
40     public void shouldLogInvalidYang10XPath() throws Exception {
41         final PrintStream stdout = System.out;
42         final ByteArrayOutputStream output = new ByteArrayOutputStream();
43         final String testLog;
44
45         System.setOut(new PrintStream(output, true, "UTF-8"));
46
47         StmtTestUtils.parseYangSource("/rfc7950/bug6878/foo10-invalid.yang");
48
49         testLog = output.toString();
50         assertTrue(testLog.contains("Could not find function: re-match"));
51         System.setOut(stdout);
52     }
53
54     @Test
55     public void shouldLogInvalidYang10XPath2() throws Exception {
56         final PrintStream stdout = System.out;
57         final ByteArrayOutputStream output = new ByteArrayOutputStream();
58         final String testLog;
59
60         System.setOut(new PrintStream(output, true, "UTF-8"));
61
62         StmtTestUtils.parseYangSource("/rfc7950/bug6878/foo10-invalid-2.yang");
63
64         testLog = output.toString();
65         assertTrue(testLog.contains("Could not find function: deref"));
66         System.setOut(stdout);
67     }
68 }