Do not mask single exceptions
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / AugmentToExtensionTest.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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.junit.Assert.assertTrue;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.UsesNode;
19
20 public class AugmentToExtensionTest extends AbstractYangTest {
21     @Test
22     public void testIncorrectPath() throws Exception {
23         assertInferenceExceptionDir("/augment-to-extension-test/incorrect-path",
24             startsWith("Augment target "
25             + "'Descendant{qnames=[(uri:augment-module?revision=2014-10-07)my-extension-name-a, input]}'"
26             + " not found [at "));
27     }
28
29     /*
30      * FIXME: Figure way to determine use case of tail-f:input without hacks
31      */
32     @Test
33     public void testCorrectPathIntoUnsupportedTarget() throws Exception {
34         final Module devicesModule =
35             assertEffectiveModelDir("/augment-to-extension-test/correct-path-into-unsupported-target")
36             .findModules("augment-module").iterator().next();
37         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
38             QName.create(devicesModule.getQNameModule(), "my-container"));
39         for (final UsesNode usesNode : devicesContainer.getUses()) {
40             assertTrue(usesNode.getAugmentations().isEmpty());
41         }
42     }
43
44     @Test
45     public void testCorrectAugment() throws Exception {
46         final Module devicesModule = assertEffectiveModelDir("/augment-to-extension-test/correct-augment")
47             .findModules("augment-module").iterator().next();
48
49         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
50                 .create(devicesModule.getQNameModule(), "my-container"));
51         boolean augmentationIsInContainer = false;
52         for (final UsesNode usesNode : devicesContainer.getUses()) {
53             for (final AugmentationSchemaNode augmentationSchema : usesNode.getAugmentations()) {
54                 augmentationIsInContainer = true;
55             }
56         }
57
58         assertTrue(augmentationIsInContainer);
59     }
60 }