BUG-4688: eliminate SimpleDateFormatUtil.DEFAULT_DATE_REV
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / IfFeatureResolutionTest.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.assertNull;
14 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
15
16 import com.google.common.collect.ImmutableSet;
17 import java.util.Set;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
27 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
29
30 public class IfFeatureResolutionTest {
31
32     private static final StatementStreamSource FOO_MODULE = sourceForResource("/if-feature-resolution-test/foo.yang");
33     private static final StatementStreamSource BAR_MODULE = sourceForResource("/if-feature-resolution-test/bar.yang");
34
35     @Test
36     public void testSomeFeaturesSupported() throws ReactorException {
37         final Set<QName> supportedFeatures = ImmutableSet.of(
38                 QName.create("foo-namespace", "test-feature-1"),
39                 QName.create("foo-namespace", "test-feature-2"),
40                 QName.create("foo-namespace", "test-feature-3"),
41                 QName.create("bar-namespace", "imp-feature"));
42
43         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
44         reactor.addSources(FOO_MODULE, BAR_MODULE);
45         reactor.setSupportedFeatures(supportedFeatures);
46
47         final SchemaContext schemaContext = reactor.buildEffective();
48         assertNotNull(schemaContext);
49
50         final Module testModule = schemaContext.findModule("foo", null).get();
51         assertEquals(9, testModule.getChildNodes().size());
52
53         final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
54                 QName.create(testModule.getQNameModule(), "test-container-a"));
55         assertNull(testContainerA);
56
57         final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
58                 QName.create(testModule.getQNameModule(), "test-container-b"));
59         assertNotNull(testContainerB);
60         final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
61                 QName.create(testModule.getQNameModule(), "test-leaf-b"));
62         assertNotNull(testLeafB);
63
64         final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
65                 QName.create(testModule.getQNameModule(), "test-container-c"));
66         assertNotNull(testContainerC);
67         final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
68                 QName.create(testModule.getQNameModule(), "test-leaf-c"));
69         assertNotNull(testLeafC);
70
71         final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
72                 QName.create(testModule.getQNameModule(), "test-container-d"));
73         assertNull(testContainerD);
74
75         final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
76                 QName.create(testModule.getQNameModule(), "test-container-e"));
77         assertNotNull(testContainerE);
78         final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
79                 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
80         assertNotNull(testSubContainerE);
81         final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
82                 QName.create(testModule.getQNameModule(), "test-leaf-e"));
83         assertNull(testLeafE);
84
85         final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
86                 QName.create(testModule.getQNameModule(), "test-container-f"));
87         assertNotNull(testContainerF);
88         final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
89                 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
90         assertNull(testSubContainerF);
91
92         final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
93                 QName.create(testModule.getQNameModule(), "test-container-g"));
94         assertNotNull(testContainerG);
95         assertEquals(1, testContainerG.getAvailableAugmentations().size());
96         final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
97                 QName.create(testModule.getQNameModule(), "test-leaf-g"));
98         assertNotNull(testLeafG);
99         final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
100                 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
101         assertNull(augmentingTestLeafG);
102         final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
103                 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
104         assertNotNull(augmentingTestAnyxmlG);
105
106         final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
107                 QName.create(testModule.getQNameModule(), "test-container-h"));
108         assertNotNull(testContainerH);
109         assertEquals(0, testContainerH.getChildNodes().size());
110         assertEquals(0, testContainerH.getUses().size());
111
112         final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
113                 QName.create(testModule.getQNameModule(), "test-container-i"));
114         assertNotNull(testContainerI);
115         assertEquals(1, testContainerI.getUses().size());
116         ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
117                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
118         assertNotNull(testGroupingSubContainer);
119         final LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
120                 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
121         assertNull(testGroupingLeaf);
122
123         final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
124                 QName.create(testModule.getQNameModule(), "test-container-j"));
125         assertNotNull(testContainerJ);
126         final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
127                 QName.create(testModule.getQNameModule(), "test-leaf-j"));
128         assertNotNull(testLeafJ);
129
130         final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
131                 QName.create(testModule.getQNameModule(), "test-container-k"));
132         assertNotNull(testContainerK);
133         assertEquals(1, testContainerK.getUses().size());
134         testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
135                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
136         assertNotNull(testGroupingSubContainer);
137         assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
138         final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
139                 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
140         assertNotNull(augmentingTestGroupingLeaf);
141         final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
142                 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
143         assertNull(augmentingTestGroupingLeaf2);
144     }
145
146     @Test
147     public void testAllFeaturesSupported() throws ReactorException {
148         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
149         reactor.addSources(FOO_MODULE, BAR_MODULE);
150
151         final SchemaContext schemaContext = reactor.buildEffective();
152         assertNotNull(schemaContext);
153
154         final Module testModule = schemaContext.findModules("foo").iterator().next();
155         assertNotNull(testModule);
156
157         assertEquals(11, testModule.getChildNodes().size());
158
159         final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
160                 QName.create(testModule.getQNameModule(), "test-container-a"));
161         assertNotNull(testContainerA);
162         final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
163                 QName.create(testModule.getQNameModule(), "test-leaf-a"));
164         assertNotNull(testLeafA);
165
166
167         final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
168                 QName.create(testModule.getQNameModule(), "test-container-b"));
169         assertNotNull(testContainerB);
170         final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
171                 QName.create(testModule.getQNameModule(), "test-leaf-b"));
172         assertNotNull(testLeafB);
173
174         final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
175                 QName.create(testModule.getQNameModule(), "test-container-c"));
176         assertNotNull(testContainerC);
177         final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
178                 QName.create(testModule.getQNameModule(), "test-leaf-c"));
179         assertNotNull(testLeafC);
180
181         final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
182                 QName.create(testModule.getQNameModule(), "test-container-d"));
183         assertNotNull(testContainerD);
184         final LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
185                 QName.create(testModule.getQNameModule(), "test-leaf-d"));
186         assertNotNull(testLeafD);
187
188         final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
189                 QName.create(testModule.getQNameModule(), "test-container-e"));
190         assertNotNull(testContainerE);
191         final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
192                 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
193         assertNotNull(testSubContainerE);
194         final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
195                 QName.create(testModule.getQNameModule(), "test-leaf-e"));
196         assertNotNull(testLeafE);
197
198         final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
199                 QName.create(testModule.getQNameModule(), "test-container-f"));
200         assertNotNull(testContainerF);
201         final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
202                 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
203         assertNotNull(testSubContainerF);
204         final ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
205                 QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
206         assertNotNull(testSubSubContainerF);
207         final LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
208                 QName.create(testModule.getQNameModule(), "test-leaf-f"));
209         assertNotNull(testLeafF);
210
211         final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
212                 QName.create(testModule.getQNameModule(), "test-container-g"));
213         assertNotNull(testContainerG);
214         assertEquals(2, testContainerG.getAvailableAugmentations().size());
215         final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
216                 QName.create(testModule.getQNameModule(), "test-leaf-g"));
217         assertNotNull(testLeafG);
218         final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
219                 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
220         assertNotNull(augmentingTestLeafG);
221         final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
222                 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
223         assertNotNull(augmentingTestAnyxmlG);
224
225         final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
226                 QName.create(testModule.getQNameModule(), "test-container-h"));
227         assertNotNull(testContainerH);
228         assertEquals(1, testContainerH.getUses().size());
229         ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerH.getDataChildByName(
230                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
231         assertNotNull(testGroupingSubContainer);
232         LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
233                 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
234         assertNotNull(testGroupingLeaf);
235
236         final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
237                 QName.create(testModule.getQNameModule(), "test-container-i"));
238         assertNotNull(testContainerI);
239         assertEquals(1, testContainerI.getUses().size());
240         testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
241                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
242         assertNotNull(testGroupingSubContainer);
243         testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
244                 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
245         assertNotNull(testGroupingLeaf);
246
247         final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
248                 QName.create(testModule.getQNameModule(), "test-container-j"));
249         assertNotNull(testContainerJ);
250         final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
251                 QName.create(testModule.getQNameModule(), "test-leaf-j"));
252         assertNotNull(testLeafJ);
253
254         final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
255                 QName.create(testModule.getQNameModule(), "test-container-k"));
256         assertNotNull(testContainerK);
257         assertEquals(1, testContainerK.getUses().size());
258         testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
259                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
260         assertNotNull(testGroupingSubContainer);
261         assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
262         final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
263                 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
264         assertNotNull(augmentingTestGroupingLeaf);
265         final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
266                 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
267         assertNotNull(augmentingTestGroupingLeaf2);
268         testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
269                 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
270         assertNotNull(testGroupingLeaf);
271     }
272
273     @Test
274     public void testNoFeaturesSupported() throws ReactorException {
275         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
276         reactor.addSources(FOO_MODULE, BAR_MODULE);
277         reactor.setSupportedFeatures(ImmutableSet.of());
278
279         final SchemaContext schemaContext = reactor.buildEffective();
280         assertNotNull(schemaContext);
281
282         final Module testModule = schemaContext.findModules("foo").iterator().next();
283         assertNotNull(testModule);
284
285         assertEquals(6, testModule.getChildNodes().size());
286
287         final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
288                 QName.create(testModule.getQNameModule(), "test-container-e"));
289         assertNotNull(testContainerE);
290         final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
291                 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
292         assertNotNull(testSubContainerE);
293         final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
294                 QName.create(testModule.getQNameModule(), "test-leaf-e"));
295         assertNull(testLeafE);
296
297         final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
298                 QName.create(testModule.getQNameModule(), "test-container-f"));
299         assertNotNull(testContainerF);
300         final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
301                 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
302         assertNull(testSubContainerF);
303
304         final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
305                 QName.create(testModule.getQNameModule(), "test-container-g"));
306         assertNotNull(testContainerG);
307         assertEquals(1, testContainerG.getAvailableAugmentations().size());
308         final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
309                 QName.create(testModule.getQNameModule(), "test-leaf-g"));
310         assertNotNull(testLeafG);
311         final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
312                 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
313         assertNull(augmentingTestLeafG);
314         final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
315                 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
316         assertNotNull(augmentingTestAnyxmlG);
317
318         final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
319                 QName.create(testModule.getQNameModule(), "test-container-h"));
320         assertNotNull(testContainerH);
321         assertEquals(0, testContainerH.getChildNodes().size());
322         assertEquals(0, testContainerH.getUses().size());
323
324         final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
325                 QName.create(testModule.getQNameModule(), "test-container-i"));
326         assertNotNull(testContainerI);
327         assertEquals(1, testContainerI.getUses().size());
328         ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
329                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
330         assertNotNull(testGroupingSubContainer);
331         LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
332                 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
333         assertNull(testGroupingLeaf);
334
335         final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
336                 QName.create(testModule.getQNameModule(), "test-container-k"));
337         assertNotNull(testContainerK);
338         assertEquals(1, testContainerK.getUses().size());
339         testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
340                 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
341         assertNotNull(testGroupingSubContainer);
342         assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
343         final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
344                 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
345         assertNull(augmentingTestGroupingLeaf);
346         final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
347                 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
348         assertNull(augmentingTestGroupingLeaf2);
349         testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
350                 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
351         assertNull(testGroupingLeaf);
352     }
353 }