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