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.assertFalse;
11 import static org.junit.Assert.assertTrue;
13 import java.util.Date;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
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.stmt.ContainerStatement;
22 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ContainerEffectiveStatementImpl;
25 public class Bug4610Test {
28 public void test() throws Exception {
29 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4610");
31 Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2015-12-12");
32 QNameModule foo = QNameModule.create(new URI("foo"), revision);
33 QNameModule bar = QNameModule.create(new URI("bar"), revision);
35 QName g1 = QName.create(bar, "g1");
36 QName g2 = QName.create(bar, "g2");
37 QName c1Bar = QName.create(bar, "c1");
39 QName c1Foo = QName.create(foo, "c1");
40 QName g3 = QName.create(foo, "g3");
41 QName root = QName.create(foo, "root");
43 ContainerEffectiveStatementImpl effectiveContainerStatementG1 = findContainer(context, g1, c1Bar);
44 ContainerEffectiveStatementImpl effectiveContainerStatementG2 = findContainer(context, g2, c1Bar);
45 ContainerEffectiveStatementImpl effectiveContainerStatementG3 = findContainer(context, g3, c1Foo);
46 ContainerEffectiveStatementImpl effectiveContainerStatementRoot = findContainer(context, root, c1Foo);
49 QName originalStatementArgument = effectiveContainerStatementG1.argument();
50 assertTrue(originalStatementArgument.equals(effectiveContainerStatementG2.argument()));
51 assertFalse(originalStatementArgument.equals(effectiveContainerStatementG3.argument()));
52 assertFalse(originalStatementArgument.equals(effectiveContainerStatementRoot.argument()));
54 ContainerStatement originalContainerStatement = effectiveContainerStatementG1.getDeclared();
55 ContainerStatement inGrouping2ContainerStatement = effectiveContainerStatementG2.getDeclared();
56 ContainerStatement inGrouping3ContainerStatement = effectiveContainerStatementG3.getDeclared();
57 ContainerStatement inRootContainerStatement = effectiveContainerStatementRoot.getDeclared();
59 // check declared instances
60 assertTrue(originalContainerStatement == inGrouping2ContainerStatement);
61 assertTrue(originalContainerStatement == inGrouping3ContainerStatement);
62 assertTrue(originalContainerStatement == inRootContainerStatement);
66 private static ContainerEffectiveStatementImpl findContainer(final SchemaContext context, final QName... path) {
67 SchemaNode node = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, path));
68 assertTrue(node instanceof ContainerEffectiveStatementImpl);
69 ContainerEffectiveStatementImpl container = (ContainerEffectiveStatementImpl) node;