34221ace427b76def7628243fafaa36751de3501
[yangtools.git] / yang / yang-parser-impl / 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.Date;
15 import java.util.List;
16 import java.util.Set;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
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 Date revision = QName.parseRevision("2016-12-23");
34
35         final Module foo = schemaContext.findModuleByName("foo", revision);
36         assertNotNull(foo);
37         final Module bar = schemaContext.findModuleByName("bar", revision);
38         assertNotNull(bar);
39
40         final Set<Deviation> deviations = foo.getDeviations();
41         assertEquals(1, deviations.size());
42         final Deviation deviation = deviations.iterator().next();
43
44         final List<DeviateDefinition> deviates = deviation.getDeviates();
45         assertEquals(1, deviates.size());
46         final DeviateDefinition deviateReplace = deviates.iterator().next();
47
48         final SchemaPath deviatedTypePath = SchemaPath.create(true, QName.create(bar.getQNameModule(), "test-leaf"),
49                 QName.create(bar.getQNameModule(), "uint32"));
50
51         final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
52         assertEquals(deviatedTypePath, deviatedType.getPath());
53     }
54 }