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.util.Collection;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
27 public class SubstatementValidatorTest {
28 @SuppressWarnings("checkstyle:regexpSinglelineJava")
29 private final PrintStream stdout = System.out;
30 private final ByteArrayOutputStream output = new ByteArrayOutputStream();
33 public void setUp() throws UnsupportedEncodingException {
34 System.setOut(new PrintStream(output, true, "UTF-8"));
38 public void cleanUp() {
39 System.setOut(stdout);
43 public void noException() throws Exception {
44 assertNotNull(TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()));
48 public void undesirableElementException() throws Exception {
50 TestUtils.loadModules(getClass().getResource("/substatement-validator/undesirable-element").toURI());
51 fail("Unexpected success");
52 } catch (ReactorException ex) {
53 assertNotNull(ex.getCause());
54 assertTrue(ex.getCause().getMessage().contains("TYPE is not valid for REVISION"));
59 public void maximalElementCountException() throws Exception {
61 TestUtils.loadModules(getClass().getResource("/substatement-validator/maximal-element").toURI());
62 fail("Unexpected success");
63 } catch (ReactorException ex) {
64 assertNotNull(ex.getCause());
65 assertTrue(ex.getCause().getMessage().contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
70 public void missingElementException() {
71 assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules(
72 SubstatementValidatorTest.class.getResource("/substatement-validator/missing-element").toURI()));
76 public void bug6173Test() throws Exception {
77 final Collection<? extends Module> loadModules = TestUtils.loadModules(getClass()
78 .getResource("/substatement-validator/empty-element").toURI()).getModules();
79 assertEquals(1, loadModules.size());
83 public void bug4310test() throws Exception {
84 assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules(
85 SubstatementValidatorTest.class.getResource("/substatement-validator/bug-4310").toURI()));