bf8edd5e59426a7eaa0d349e40e2438b73938f69
[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.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertTrue;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.UsesNode;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
22
23 public class AugmentToExtensionTest extends AbstractYangTest {
24     @Test
25     public void testIncorrectPath() throws Exception {
26         // FIXME: this should not be here, or why do we need encapsulation? Add asserts for that
27         final var cause = assertInferenceExceptionDir("/augment-to-extension-test/incorrect-path",
28             startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at "));
29
30         final var firstCause = cause.getCause();
31         assertThat(firstCause, instanceOf(InferenceException.class));
32         assertThat(firstCause.getMessage(), startsWith("Augment target "
33             + "'Descendant{qnames=[(uri:augment-module?revision=2014-10-07)my-extension-name-a, input]}'"
34             + " not found [at "));
35     }
36
37     /*
38      * FIXME: Figure way to determine use case of tail-f:input without hacks
39      */
40     @Test
41     public void testCorrectPathIntoUnsupportedTarget() throws Exception {
42         final Module devicesModule =
43             assertEffectiveModelDir("/augment-to-extension-test/correct-path-into-unsupported-target")
44             .findModules("augment-module").iterator().next();
45         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
46             QName.create(devicesModule.getQNameModule(), "my-container"));
47         for (final UsesNode usesNode : devicesContainer.getUses()) {
48             assertTrue(usesNode.getAugmentations().isEmpty());
49         }
50     }
51
52     @Test
53     public void testCorrectAugment() throws Exception {
54         final Module devicesModule = assertEffectiveModelDir("/augment-to-extension-test/correct-augment")
55             .findModules("augment-module").iterator().next();
56
57         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
58                 .create(devicesModule.getQNameModule(), "my-container"));
59         boolean augmentationIsInContainer = false;
60         for (final UsesNode usesNode : devicesContainer.getUses()) {
61             for (final AugmentationSchemaNode augmentationSchema : usesNode.getAugmentations()) {
62                 augmentationIsInContainer = true;
63             }
64         }
65
66         assertTrue(augmentationIsInContainer);
67     }
68 }