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;
12 import static org.junit.Assert.assertNotNull;
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;
26 public class ElementCountConstraintsTest {
28 public void testElementCountConstraints()
29 throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
30 final var schemaContext = StmtTestUtils.parseYangSource("/constraint-definitions-test/foo.yang");
31 assertNotNull(schemaContext);
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();
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();
44 assertEquals(constraints1.hashCode(), constraints2.hashCode());
45 assertEquals(constraints1, constraints2);
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();
52 assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
53 assertNotEquals(constraints2, constraints3);
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();
60 assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
61 assertNotEquals(constraints3, constraints4);
63 assertEquals("ElementCountConstraint{minElements=50, maxElements=100}", constraints4.toString());