Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug8922Test.java
1 /*
2  * Copyright (c) 2017 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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13
14 import java.util.Optional;
15 import java.util.Set;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
20
21 class Bug8922Test extends AbstractYangTest {
22     private static final QName MY_CON = QName.create("foo", "my-con");
23     private static final QName TARGET = QName.create("foo", "target");
24
25     @Test
26     void testAllFeaturesSupported() {
27         final var context = assertEffectiveModel("/bugs/bug8922/foo.yang");
28         final var findNode = assertInstanceOf(ContainerSchemaNode.class,
29             context.findDataTreeChild(TARGET, MY_CON).orElseThrow());
30         assertEquals(Optional.of("New description"), findNode.getDescription());
31
32         assertEquals(1, context.findModuleStatements("foo").iterator().next()
33             .streamEffectiveSubstatements(FeatureEffectiveStatement.class).count());
34     }
35
36     @Test
37     void testNoFeatureSupported() throws Exception {
38         final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", Set.of());
39         assertNotNull(context);
40         assertEquals(Optional.empty(), context.findDataTreeChild(TARGET, MY_CON));
41         assertEquals(Set.of(), context.getAvailableAugmentations());
42
43         assertEquals(0, context.findModuleStatements("foo").iterator().next()
44             .streamEffectiveSubstatements(FeatureEffectiveStatement.class).count());
45     }
46 }