2 * Copyright (c) 2015 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.test.augment;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.fail;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 public class AugmentTest {
24 private static final TestAugmentSource IMPORTED = new TestAugmentSource("imp", "/a");
25 private static final TestAugmentSource VALID_ABS = new TestAugmentSource("root", "/aug1/aug11/aug111");
26 private static final TestAugmentSource VALID_ABS_PREFIXED = new TestAugmentSource("root",
27 "/imp:aug1/imp:aug11/imp:aug111", "imp");
28 private static final TestAugmentSource VALID_REL = new TestAugmentSource("root", "aug1/aug11");
29 private static final TestAugmentSource VALID_REL_PREFIXED = new TestAugmentSource("root",
30 "imp:aug1/imp:aug11/imp:aug111", "imp");
31 private static final TestAugmentSource INVALID_REL_WHITE_SPACE = new TestAugmentSource("root", ".. /aug1/aug11");
32 private static final TestAugmentSource INVALID_REL1 = new TestAugmentSource("root", "./aug1/aug11");
33 private static final TestAugmentSource INVALID_REL2 = new TestAugmentSource("root", "../aug1/aug11");
34 private static final TestAugmentSource INVALID_ABS = new TestAugmentSource("root", "//aug1/aug11/aug111");
35 private static final TestAugmentSource INVALID_ABS_PREFIXED_NO_IMP = new TestAugmentSource("root",
36 "imp:aug1/imp:aug11/imp:aug111");
37 private static final TestAugmentSource INVALID_EMPTY = new TestAugmentSource("root", "");
38 private static final TestAugmentSource INVALID_XPATH = new TestAugmentSource("root", "/aug1/-");
41 public void validAugAbsTest() throws SourceException, ReactorException {
43 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
44 addSources(reactor, VALID_ABS);
48 } catch (Exception e) {
49 // if augment argument is correct we only catch an exception that it cannot be found in mock model
50 assertEquals(NullPointerException.class, e.getClass());
55 public void validAugAbsPrefixedTest() throws SourceException, ReactorException {
57 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
58 addSources(reactor, IMPORTED, VALID_ABS_PREFIXED);
62 } catch (Exception e) {
63 // if augment argument is correct we only catch an exception that it cannot be found in mock model
64 assertEquals(NullPointerException.class, e.getClass());
69 public void validAugRelTest() throws SourceException, ReactorException {
71 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
72 addSources(reactor, VALID_REL);
76 } catch (Exception e) {
77 // if augment argument is correct we only catch an exception that it cannot be found in mock model
78 assertEquals(NullPointerException.class, e.getClass());
83 public void validAugRelPrefixedTest() throws SourceException, ReactorException {
85 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
86 addSources(reactor, IMPORTED, VALID_REL_PREFIXED);
90 } catch (Exception e) {
91 // if augment argument is correct we only catch an exception that it cannot be found in mock model
92 assertEquals(NullPointerException.class, e.getClass());
97 public void validAugRelWhiteSpaceTest() throws SourceException, ReactorException {
99 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
100 addSources(reactor, INVALID_REL_WHITE_SPACE);
104 fail("reactor.process should fail due to invalid relative path");
105 } catch (Exception e) {
106 assertEquals(IllegalArgumentException.class, e.getClass());
111 public void invalidAugRel1Test() throws SourceException, ReactorException {
113 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
114 addSources(reactor, INVALID_REL1);
118 fail("reactor.process should fail due to invalid relative path");
119 } catch (Exception e) {
120 assertEquals(IllegalArgumentException.class, e.getClass());
125 public void invalidAugRel2Test() throws SourceException, ReactorException {
127 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
128 addSources(reactor, INVALID_REL2);
132 fail("reactor.process should fail due to invalid relative path");
133 } catch (Exception e) {
134 assertEquals(IllegalArgumentException.class, e.getClass());
139 public void invalidAugAbs() throws SourceException, ReactorException {
141 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
142 addSources(reactor, INVALID_ABS);
146 fail("reactor.process should fail due to invalid absolute path");
147 } catch (Exception e) {
148 assertEquals(IllegalArgumentException.class, e.getClass());
153 public void invalidAugAbsPrefixedNoImp() throws SourceException, ReactorException {
155 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
156 addSources(reactor, INVALID_ABS_PREFIXED_NO_IMP);
160 fail("reactor.process should fail due to missing import from augment path");
161 } catch (Exception e) {
162 assertEquals(IllegalArgumentException.class, e.getClass());
167 public void invalidAugEmptyTest() throws SourceException {
169 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
170 addSources(reactor, INVALID_EMPTY);
174 fail("reactor.process should fail due to empty path");
175 } catch (Exception e) {
176 assertEquals(IllegalArgumentException.class, e.getClass());
181 public void invalidAugXPathTest() throws SourceException {
183 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
184 addSources(reactor, INVALID_XPATH);
188 fail("reactor.process should fail due to invalid XPath");
189 } catch (Exception e) {
190 assertEquals(IllegalArgumentException.class, e.getClass());
194 private void addSources(BuildAction reactor, TestAugmentSource... sources) {
195 for (TestAugmentSource source : sources) {
196 reactor.addSource(source);