Fixup resource loading in yang-parser-rfc7950
[yangtools.git] / yang / 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.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
20 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
25
26 public class ElementCountConstraintsTest {
27     @Test
28     public void testElementCountConstraints()
29             throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
30         final var schemaContext = StmtTestUtils.parseYangSource("/constraint-definitions-test/foo.yang");
31         assertNotNull(schemaContext);
32
33         final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
34         final LeafListSchemaNode constrainedLeafList1 = (LeafListSchemaNode) testModule.getDataChildByName(
35                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
36         assertNotNull(constrainedLeafList1);
37         ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
38
39         final LeafListSchemaNode constrainedLeafList2 = (LeafListSchemaNode) testModule.getDataChildByName(
40                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-2"));
41         assertNotNull(constrainedLeafList2);
42         ElementCountConstraint constraints2 = constrainedLeafList2.getElementCountConstraint().get();
43
44         assertEquals(constraints1.hashCode(), constraints2.hashCode());
45         assertEquals(constraints1, constraints2);
46
47         final LeafListSchemaNode constrainedLeafList3 = (LeafListSchemaNode) testModule.getDataChildByName(
48                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-3"));
49         assertNotNull(constrainedLeafList3);
50         ElementCountConstraint constraints3 = constrainedLeafList3.getElementCountConstraint().get();
51
52         assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
53         assertNotEquals(constraints2, constraints3);
54
55         final LeafListSchemaNode constrainedLeafList4 = (LeafListSchemaNode) testModule.getDataChildByName(
56                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-4"));
57         assertNotNull(constrainedLeafList4);
58         ElementCountConstraint constraints4 = constrainedLeafList4.getElementCountConstraint().get();
59
60         assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
61         assertNotEquals(constraints3, constraints4);
62
63         assertEquals("ElementCountConstraint{minElements=50, maxElements=100}", constraints4.toString());
64     }
65 }