Define a feature-parent
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ElementCountConstraintsTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
9
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;
13
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;
19
20 class ElementCountConstraintsTest extends AbstractYangTest {
21     @Test
22     void testElementCountConstraints() {
23         final var context = assertEffectiveModel("/constraint-definitions-test/foo.yang");
24
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();
29
30         var constraints2 = assertInstanceOf(LeafListSchemaNode.class,
31             testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-2")))
32             .getElementCountConstraint().orElseThrow();
33
34         assertEquals(constraints1.hashCode(), constraints2.hashCode());
35         assertEquals(constraints1, constraints2);
36
37         var constraints3 = assertInstanceOf(LeafListSchemaNode.class,
38             testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-3")))
39             .getElementCountConstraint().orElseThrow();
40
41         assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
42         assertNotEquals(constraints2, constraints3);
43
44         var constraints4 = assertInstanceOf(LeafListSchemaNode.class,
45             testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "constrained-leaf-list-4")))
46             .getElementCountConstraint().orElseThrow();
47
48         assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
49         assertNotEquals(constraints3, constraints4);
50
51         assertEquals("ElementCountConstraint{minElements=50, maxElements=100}", constraints4.toString());
52     }
53 }