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.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import com.google.common.base.VerifyException;
15 import java.io.ByteArrayOutputStream;
16 import java.io.PrintStream;
17 import java.io.UnsupportedEncodingException;
18 import java.net.URISyntaxException;
19 import java.util.NoSuchElementException;
21 import org.junit.After;
22 import org.junit.Before;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
28 import org.opendaylight.yangtools.yang.stmt.TestUtils;
30 public class SubstatementValidatorTest {
32 private final PrintStream stdout = System.out;
33 private final ByteArrayOutputStream output = new ByteArrayOutputStream();
34 private String testLog;
37 public ExpectedException expectedEx = ExpectedException.none();
40 public void setUp() throws UnsupportedEncodingException {
41 System.setOut(new PrintStream(output, true, "UTF-8"));
45 public void cleanUp() {
46 System.setOut(stdout);
50 public void noException() throws URISyntaxException, ReactorException {
51 Set<Module> modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI());
52 assertNotNull(modules);
56 public void undesirableElementException() throws URISyntaxException, ReactorException {
57 Set<Module> modules = TestUtils.loadModules(getClass().getResource
58 ("/substatement-validator/undesirable-element").toURI());
59 testLog = output.toString();
60 assertTrue(testLog.contains("TYPE is not valid for REVISION"));
64 public void maximalElementCountException() throws URISyntaxException, ReactorException {
65 Set<Module> modules = TestUtils.loadModules(getClass().getResource
66 ("/substatement-validator/maximal-element").toURI());
67 testLog = output.toString();
68 assertTrue(testLog.contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
72 public void missingElementException() throws URISyntaxException, ReactorException {
73 expectedEx.expect(VerifyException.class);
75 Set<Module> modules = TestUtils.loadModules(getClass().getResource
76 ("/substatement-validator/missing-element").toURI());
80 public void emptyElementException() throws URISyntaxException, ReactorException {
81 expectedEx.expect(NoSuchElementException.class);
83 Set<Module> modules = TestUtils.loadModules(getClass().getResource
84 ("/substatement-validator/empty-element").toURI());
88 public void bug4310test() throws URISyntaxException, ReactorException {
89 expectedEx.expect(IllegalArgumentException.class);
91 Set<Module> modules = TestUtils.loadModules(getClass().getResource
92 ("/substatement-validator/bug-4310").toURI());