2 * Copyright (c) 2016 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.stmt;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertThrows;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import java.io.ByteArrayOutputStream;
17 import java.io.PrintStream;
18 import java.io.UnsupportedEncodingException;
19 import java.nio.charset.StandardCharsets;
20 import java.util.Collection;
21 import org.junit.After;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
28 public class SubstatementValidatorTest {
29 @SuppressWarnings("checkstyle:regexpSinglelineJava")
30 private final PrintStream stdout = System.out;
31 private final ByteArrayOutputStream output = new ByteArrayOutputStream();
34 public void setUp() throws UnsupportedEncodingException {
35 System.setOut(new PrintStream(output, true, StandardCharsets.UTF_8));
39 public void cleanUp() {
40 System.setOut(stdout);
44 public void noException() throws Exception {
45 assertNotNull(TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()));
49 public void undesirableElementException() throws Exception {
51 TestUtils.loadModules(getClass().getResource("/substatement-validator/undesirable-element").toURI());
52 fail("Unexpected success");
53 } catch (ReactorException ex) {
54 assertNotNull(ex.getCause());
55 assertTrue(ex.getCause().getMessage().contains("TYPE is not valid for REVISION"));
60 public void maximalElementCountException() throws Exception {
62 TestUtils.loadModules(getClass().getResource("/substatement-validator/maximal-element").toURI());
63 fail("Unexpected success");
64 } catch (ReactorException ex) {
65 assertNotNull(ex.getCause());
66 assertTrue(ex.getCause().getMessage().contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
71 public void missingElementException() {
72 assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules(
73 SubstatementValidatorTest.class.getResource("/substatement-validator/missing-element").toURI()));
77 public void bug6173Test() throws Exception {
78 final Collection<? extends Module> loadModules = TestUtils.loadModules(getClass()
79 .getResource("/substatement-validator/empty-element").toURI()).getModules();
80 assertEquals(1, loadModules.size());
84 public void bug4310test() throws Exception {
85 assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules(
86 SubstatementValidatorTest.class.getResource("/substatement-validator/bug-4310").toURI()));