Bug 7440: Fix empty parent in deviate "replace"
[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.io.FileNotFoundException;
15 import java.net.URISyntaxException;
16 import java.text.ParseException;
17 import java.util.Date;
18 import java.util.List;
19 import java.util.Set;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
23 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
24 import org.opendaylight.yangtools.yang.model.api.Deviation;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
28 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30
31 public class Bug7440Test {
32
33     @Test
34     public void testRestrictedTypeParentSchemaPathInDeviate() throws ReactorException, FileNotFoundException,
35             URISyntaxException, ParseException {
36         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/bug7440/foo.yang");
37         assertNotNull(schemaContext);
38
39         final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-12-23");
40
41         final Module foo = schemaContext.findModuleByName("foo", revision);
42         assertNotNull(foo);
43
44         final Set<Deviation> deviations = foo.getDeviations();
45         assertEquals(1, deviations.size());
46         final Deviation deviation = deviations.iterator().next();
47
48         final List<DeviateDefinition> deviates = deviation.getDeviates();
49         assertEquals(1, deviates.size());
50         final DeviateDefinition deviateReplace = deviates.iterator().next();
51
52         final SchemaPath deviatedTypePath = SchemaPath.create(true, QName.create(foo.getQNameModule(), "test-leaf"),
53                 QName.create(foo.getQNameModule(), "uint32"));
54
55         final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
56         assertEquals(deviatedTypePath, deviatedType.getPath());
57     }
58 }