0f4c8fd22d4a124e45ee26d65c4e9c653d9c0c01
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / AugmentArgumentParsingTest.java
1 /*
2  * Copyright (c) 2016 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;
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.Ignore;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
23
24 public class AugmentArgumentParsingTest {
25
26     private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
27             "/semantic-statement-parser/augment-arg-parsing/imported.yang", false);
28     private static final YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
29             "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang", false);
30     private static final YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
31             "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang", false);
32     private static final YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
33             "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang", false);
34     private static final YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
35             "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang", false);
36     private static final YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
37             "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang", false);
38     private static final YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
39             "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang", false);
40     private static final YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
41             "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang", false);
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     @Ignore
111     public void invalidAugEmptyTest() throws SourceException {
112
113         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
114         addSources(reactor, INVALID_EMPTY);
115
116         try {
117             reactor.build();
118             fail("reactor.process should fail due to empty path");
119         } catch (Exception e) {
120             assertEquals(IllegalArgumentException.class, e.getClass());
121         }
122     }
123
124     @Test
125     @Ignore
126     public void invalidAugXPathTest() throws SourceException {
127
128         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
129         addSources(reactor, INVALID_XPATH);
130
131         try {
132             reactor.build();
133             fail("reactor.process should fail due to invalid XPath");
134         } catch (Exception e) {
135             assertEquals(IllegalArgumentException.class, e.getClass());
136         }
137     }
138
139     private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
140         for (YangStatementSourceImpl source : sources) {
141             reactor.addSource(source);
142         }
143     }
144 }