YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug7440Test.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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.util.List;
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
20 import org.opendaylight.yangtools.yang.model.api.Deviation;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
25
26 public class Bug7440Test {
27
28     @Test
29     public void testRestrictedTypeParentSchemaPathInDeviate() throws Exception {
30         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug7440");
31         assertNotNull(schemaContext);
32
33         final Revision revision = Revision.of("2016-12-23");
34         final Module foo = schemaContext.findModule("foo", revision).get();
35         final Module bar = schemaContext.findModule("bar", revision).get();
36
37         final Set<Deviation> deviations = foo.getDeviations();
38         assertEquals(1, deviations.size());
39         final Deviation deviation = deviations.iterator().next();
40
41         final List<DeviateDefinition> deviates = deviation.getDeviates();
42         assertEquals(1, deviates.size());
43         final DeviateDefinition deviateReplace = deviates.iterator().next();
44
45         final SchemaPath deviatedTypePath = SchemaPath.create(true, QName.create(bar.getQNameModule(), "test-leaf"),
46                 QName.create(bar.getQNameModule(), "uint32"));
47
48         final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
49         assertEquals(deviatedTypePath, deviatedType.getPath());
50     }
51 }