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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
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;
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;
31 public class Bug7440Test {
34 public void testRestrictedTypeParentSchemaPathInDeviate() throws ReactorException, FileNotFoundException,
35 URISyntaxException, ParseException {
36 final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/bug7440/foo.yang");
37 assertNotNull(schemaContext);
39 final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-12-23");
41 final Module foo = schemaContext.findModuleByName("foo", revision);
44 final Set<Deviation> deviations = foo.getDeviations();
45 assertEquals(1, deviations.size());
46 final Deviation deviation = deviations.iterator().next();
48 final List<DeviateDefinition> deviates = deviation.getDeviates();
49 assertEquals(1, deviates.size());
50 final DeviateDefinition deviateReplace = deviates.iterator().next();
52 final SchemaPath deviatedTypePath = SchemaPath.create(true, QName.create(foo.getQNameModule(), "test-leaf"),
53 QName.create(foo.getQNameModule(), "uint32"));
55 final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
56 assertEquals(deviatedTypePath, deviatedType.getPath());