Bug 2366: new parser API extensions support implemented
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / AugmentTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.stmt.test;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.fail;
14
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;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
22
23 public class AugmentTest {
24
25     private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
26             "/semantic-statement-parser/augment-arg-parsing/imported.yang");
27
28     private static YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
29             "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
30     private static YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
31             "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
32     private static YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
33             "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
34     private static YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
35             "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
36     private static YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
37             "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
38     private static YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
39             "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
40     private static YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
41             "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
42
43     @Test
44     public void validAugAbsTest() throws SourceException, ReactorException {
45
46         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
47         addSources(reactor, IMPORTED, VALID_ARGS);
48
49         final EffectiveModelContext result = reactor.build();
50         assertNotNull(result);
51     }
52
53     @Test
54     public void invalidAugRel1Test() throws SourceException, ReactorException {
55
56         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
57         addSources(reactor, INVALID_REL1);
58
59         try {
60             reactor.build();
61             fail("reactor.process should fail due to invalid relative path");
62         } catch (Exception e) {
63             assertEquals(IllegalArgumentException.class, e.getClass());
64         }
65     }
66
67     @Test
68     public void invalidAugRel2Test() throws SourceException, ReactorException {
69
70         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
71         addSources(reactor, INVALID_REL2);
72
73         try {
74             reactor.build();
75             fail("reactor.process should fail due to invalid relative path");
76         } catch (Exception e) {
77             assertEquals(IllegalArgumentException.class, e.getClass());
78         }
79     }
80
81     @Test
82     public void invalidAugAbs() throws SourceException, ReactorException {
83
84         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
85         addSources(reactor, INVALID_ABS);
86
87         try {
88             reactor.build();
89             fail("reactor.process should fail due to invalid absolute path");
90         } catch (Exception e) {
91             assertEquals(IllegalArgumentException.class, e.getClass());
92         }
93     }
94
95     @Test
96     public void invalidAugAbsPrefixedNoImp() throws SourceException, ReactorException {
97
98         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
99         addSources(reactor, INVALID_ABS_PREFIXED_NO_IMP);
100
101         try {
102             reactor.build();
103             fail("reactor.process should fail due to missing import from augment path");
104         } catch (Exception e) {
105             assertEquals(IllegalArgumentException.class, e.getClass());
106         }
107     }
108
109     @Test
110     public void invalidAugEmptyTest() throws SourceException {
111
112         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
113         addSources(reactor, INVALID_EMPTY);
114
115         try {
116             reactor.build();
117             fail("reactor.process should fail due to empty path");
118         } catch (Exception e) {
119             assertEquals(IllegalArgumentException.class, e.getClass());
120         }
121     }
122
123     @Test
124     public void invalidAugXPathTest() throws SourceException {
125
126         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
127         addSources(reactor, INVALID_XPATH);
128
129         try {
130             reactor.build();
131             fail("reactor.process should fail due to invalid XPath");
132         } catch (Exception e) {
133             assertEquals(IllegalArgumentException.class, e.getClass());
134         }
135     }
136
137     private void addSources(BuildAction reactor, YangStatementSourceImpl... sources) {
138         for (YangStatementSourceImpl source : sources) {
139             reactor.addSource(source);
140         }
141     }
142 }