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.assertTrue;
13 import static org.junit.Assert.fail;
15 import java.io.ByteArrayOutputStream;
16 import java.io.PrintStream;
17 import java.io.UnsupportedEncodingException;
18 import java.util.Collection;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Rule;
22 import org.junit.Test;
23 import org.junit.rules.ExpectedException;
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 ExpectedException expectedEx = ExpectedException.none();
37 public void setUp() throws UnsupportedEncodingException {
38 System.setOut(new PrintStream(output, true, "UTF-8"));
42 public void cleanUp() {
43 System.setOut(stdout);
47 public void noException() throws Exception {
48 assertNotNull(TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()));
52 public void undesirableElementException() throws Exception {
54 TestUtils.loadModules(getClass().getResource("/substatement-validator/undesirable-element").toURI());
55 fail("Unexpected success");
56 } catch (ReactorException ex) {
57 assertNotNull(ex.getCause());
58 assertTrue(ex.getCause().getMessage().contains("TYPE is not valid for REVISION"));
63 public void maximalElementCountException() throws Exception {
65 TestUtils.loadModules(getClass().getResource("/substatement-validator/maximal-element").toURI());
66 fail("Unexpected success");
67 } catch (ReactorException ex) {
68 assertNotNull(ex.getCause());
69 assertTrue(ex.getCause().getMessage().contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
74 public void missingElementException() throws Exception {
75 expectedEx.expect(SomeModifiersUnresolvedException.class);
77 TestUtils.loadModules(getClass().getResource("/substatement-validator/missing-element").toURI());
81 public void bug6173Test() throws Exception {
82 final Collection<? extends Module> loadModules = TestUtils.loadModules(getClass()
83 .getResource("/substatement-validator/empty-element").toURI()).getModules();
84 assertEquals(1, loadModules.size());
88 public void bug4310test() throws Exception {
89 expectedEx.expect(SomeModifiersUnresolvedException.class);
90 TestUtils.loadModules(getClass().getResource("/substatement-validator/bug-4310").toURI());