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.parser.stmt.rfc6020.effective;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.Revision;
16 import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
17 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
21 public class ElementCountConstraintsTest extends AbstractYangTest {
23 public void testElementCountConstraints() {
24 final var context = assertEffectiveModel("/constraint-definitions-test/foo.yang");
26 final Module testModule = context.findModule("foo", Revision.of("2016-09-20")).get();
27 final LeafListSchemaNode constrainedLeafList1 = (LeafListSchemaNode) testModule.getDataChildByName(
28 QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
29 ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
31 final LeafListSchemaNode constrainedLeafList2 = (LeafListSchemaNode) testModule.getDataChildByName(
32 QName.create(testModule.getQNameModule(), "constrained-leaf-list-2"));
33 ElementCountConstraint constraints2 = constrainedLeafList2.getElementCountConstraint().get();
35 assertEquals(constraints1.hashCode(), constraints2.hashCode());
36 assertEquals(constraints1, constraints2);
38 final LeafListSchemaNode constrainedLeafList3 = (LeafListSchemaNode) testModule.getDataChildByName(
39 QName.create(testModule.getQNameModule(), "constrained-leaf-list-3"));
40 ElementCountConstraint constraints3 = constrainedLeafList3.getElementCountConstraint().get();
42 assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
43 assertNotEquals(constraints2, constraints3);
45 final LeafListSchemaNode constrainedLeafList4 = (LeafListSchemaNode) testModule.getDataChildByName(
46 QName.create(testModule.getQNameModule(), "constrained-leaf-list-4"));
47 ElementCountConstraint constraints4 = constrainedLeafList4.getElementCountConstraint().get();
49 assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
50 assertNotEquals(constraints3, constraints4);
52 assertEquals("ElementCountConstraint{minElements=50, maxElements=100}", constraints4.toString());