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