2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
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;
23 public class AugmentToExtensionTest extends AbstractYangTest {
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 "));
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 "));
38 * FIXME: Figure way to determine use case of tail-f:input without hacks
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());
53 public void testCorrectAugment() throws Exception {
54 final Module devicesModule = assertEffectiveModelDir("/augment-to-extension-test/correct-augment")
55 .findModules("augment-module").iterator().next();
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;
66 assertTrue(augmentationIsInContainer);