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.junit.Assert.assertTrue;
12 import java.net.URISyntaxException;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.UsesNode;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 public class AugmentToExtensionTest {
25 private Set<Module> modules;
27 @Test(expected = SomeModifiersUnresolvedException.class)
28 public void testIncorrectPath() throws URISyntaxException, SourceException, ReactorException {
29 modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
34 * FIXME: Figure way to determine use case of tail-f:input without hacks
38 public void testCorrectPathIntoUnsupportedTarget() throws URISyntaxException, SourceException, ReactorException {
41 modules = TestUtils.loadModules(getClass().getResource(
42 "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
43 } catch (final Exception e) {
44 StmtTestUtils.log(e, " ");
48 final Module devicesModule = TestUtils.findModule(modules, "augment-module");
50 final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
51 .create(devicesModule.getQNameModule(), "my-container"));
52 final Set<UsesNode> uses = devicesContainer.getUses();
54 for (final UsesNode usesNode : uses) {
55 assertTrue(usesNode.getAugmentations().isEmpty());
61 public void testCorrectAugment() throws URISyntaxException, SourceException, ReactorException {
62 modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
64 final Module devicesModule = TestUtils.findModule(modules, "augment-module");
66 final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
67 .create(devicesModule.getQNameModule(), "my-container"));
68 final Set<UsesNode> uses = devicesContainer.getUses();
70 boolean augmentationIsInContainer = false;
71 for (final UsesNode usesNode : uses) {
72 final Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
73 for (final AugmentationSchema augmentationSchema : augmentations) {
74 augmentationIsInContainer = true;
78 assertTrue(augmentationIsInContainer);