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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertNotEquals;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.Revision;
17 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
18 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
20 class ElementCountConstraintsTest extends AbstractYangTest {
22 void testElementCountConstraints() {
23 final var context = assertEffectiveModel("/constraint-definitions-test/foo.yang");
25 final var testModule = context.findModule("foo", Revision.of("2016-09-20")).orElseThrow();
26 final var constraints1 = assertInstanceOf(LeafListSchemaNode.class,
27 testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-1")))
28 .getElementCountConstraint().orElseThrow();
30 var constraints2 = assertInstanceOf(LeafListSchemaNode.class,
31 testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-2")))
32 .getElementCountConstraint().orElseThrow();
34 assertEquals(constraints1.hashCode(), constraints2.hashCode());
35 assertEquals(constraints1, constraints2);
37 var constraints3 = assertInstanceOf(LeafListSchemaNode.class,
38 testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-3")))
39 .getElementCountConstraint().orElseThrow();
41 assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
42 assertNotEquals(constraints2, constraints3);
44 var constraints4 = assertInstanceOf(LeafListSchemaNode.class,
45 testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-4")))
46 .getElementCountConstraint().orElseThrow();
48 assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
49 assertNotEquals(constraints3, constraints4);
51 assertEquals("ElementCountConstraint{minElements=50, maxElements=100}", constraints4.toString());