Adjust test suite parser update to conform with API changes
[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 java.text.ParseException;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
21 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
25 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
29
30 public class ElementCountConstraintsTest {
31
32     @Test
33     public void testElementCountConstraints() throws ParseException, ReactorException, URISyntaxException, IOException,
34             YangSyntaxErrorException {
35         final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
36                 .addSource(YangStatementStreamSource.create(
37                     YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")))
38                 .buildEffective();
39         assertNotNull(schemaContext);
40
41         final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
42         final LeafListSchemaNode constrainedLeafList1 = (LeafListSchemaNode) testModule.getDataChildByName(
43                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
44         assertNotNull(constrainedLeafList1);
45         ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
46
47         final LeafListSchemaNode constrainedLeafList2 = (LeafListSchemaNode) testModule.getDataChildByName(
48                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-2"));
49         assertNotNull(constrainedLeafList2);
50         ElementCountConstraint constraints2 = constrainedLeafList2.getElementCountConstraint().get();
51
52         assertEquals(constraints1.hashCode(), constraints2.hashCode());
53         assertEquals(constraints1, constraints2);
54
55         final LeafListSchemaNode constrainedLeafList3 = (LeafListSchemaNode) testModule.getDataChildByName(
56                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-3"));
57         assertNotNull(constrainedLeafList3);
58         ElementCountConstraint constraints3 = constrainedLeafList3.getElementCountConstraint().get();
59
60         assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
61         assertNotEquals(constraints2, constraints3);
62
63         final LeafListSchemaNode constrainedLeafList4 = (LeafListSchemaNode) testModule.getDataChildByName(
64                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-4"));
65         assertNotNull(constrainedLeafList4);
66         ElementCountConstraint constraints4 = constrainedLeafList4.getElementCountConstraint().get();
67
68         assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
69         assertNotEquals(constraints3, constraints4);
70
71         assertEquals("ElementCountConstraint{minElements=50, maxElements=100}", constraints4.toString());
72     }
73 }