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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
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;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
29 public class SubstatementValidatorTest {
31 private final PrintStream stdout = System.out;
32 private final ByteArrayOutputStream output = new ByteArrayOutputStream();
35 public ExpectedException expectedEx = ExpectedException.none();
38 public void setUp() throws UnsupportedEncodingException {
39 System.setOut(new PrintStream(output, true, "UTF-8"));
43 public void cleanUp() {
44 System.setOut(stdout);
48 public void noException() throws Exception {
49 final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
51 assertNotNull(modules);
55 public void undesirableElementException() throws Exception {
57 TestUtils.loadModules(getClass().getResource("/substatement-validator/undesirable-element").toURI());
58 fail("Unexpected success");
59 } catch (ReactorException ex) {
60 assertNotNull(ex.getCause());
61 assertTrue(ex.getCause().getMessage().contains("TYPE is not valid for REVISION"));
66 public void maximalElementCountException() throws Exception {
68 TestUtils.loadModules(getClass().getResource("/substatement-validator/maximal-element").toURI());
69 fail("Unexpected success");
70 } catch (ReactorException ex) {
71 assertNotNull(ex.getCause());
72 assertTrue(ex.getCause().getMessage().contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
77 public void missingElementException() throws Exception {
78 expectedEx.expect(SomeModifiersUnresolvedException.class);
80 TestUtils.loadModules(getClass().getResource("/substatement-validator/missing-element").toURI());
84 public void bug6173Test() throws Exception {
85 final Set<Module> loadModules = TestUtils.loadModules(getClass().getResource(
86 "/substatement-validator/empty-element").toURI());
87 assertEquals(1, loadModules.size());
91 public void bug4310test() throws Exception {
92 expectedEx.expect(SomeModifiersUnresolvedException.class);
93 TestUtils.loadModules(getClass().getResource("/substatement-validator/bug-4310").toURI());