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.assertNotNull;
11 import static org.junit.Assert.assertTrue;
13 import java.io.FileNotFoundException;
14 import java.net.URISyntaxException;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
22 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 public class Bug6771Test {
27 private static final String NS = "http://www.example.com/typedef-bug";
28 private static final String REV = "1970-01-01";
29 private static final QName ROOT = QName.create(NS, REV, "root");
30 private static final QName CONT_B = QName.create(NS, REV, "container-b");
31 private static final QName LEAF_CONT_B = QName.create(NS, REV, "leaf-container-b");
32 private static final QName INNER_CONTAINER = QName.create(NS, REV, "inner-container");
35 public void augmentTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
36 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/augment");
37 assertNotNull(context);
39 verifyLeafType(SchemaContextUtil
40 .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
41 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
42 SchemaPath.create(true, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B)));
46 public void choiceCaseTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
47 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/choice-case");
48 assertNotNull(context);
50 final QName myChoice = QName.create(NS, REV, "my-choice");
51 final QName caseOne = QName.create(NS, REV, "one");
52 final QName caseTwo = QName.create(NS, REV, "two");
53 final QName caseThree = QName.create(NS, REV, "three");
54 final QName containerOne = QName.create(NS, REV, "container-one");
55 final QName containerTwo = QName.create(NS, REV, "container-two");
56 final QName containerThree = QName.create(NS, REV, "container-three");
58 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
59 SchemaPath.create(true, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B)));
60 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
61 SchemaPath.create(true, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B)));
62 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
63 SchemaPath.create(true, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B)));
67 public void groupingTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
68 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/grouping");
69 assertNotNull(context);
70 verifyLeafType(SchemaContextUtil
71 .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
74 private static void verifyLeafType(final SchemaNode schemaNode) {
75 assertTrue(schemaNode instanceof LeafSchemaNode);
76 assertTrue(((LeafSchemaNode) schemaNode).getType() instanceof UnsignedIntegerTypeDefinition);