Replace calls of StmtTestUtils.parseYangSource(String) two
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6871Test.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.rfc7950;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.Revision;
16 import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
19 import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
21 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
22
23 public class Bug6871Test extends AbstractYangTest {
24     @Test
25     public void testValidYang11Model() {
26         final Module foo = assertEffectiveModel("/rfc7950/bug6871/foo.yang")
27             .findModule("foo", Revision.of("2016-12-14")).orElseThrow();
28
29         final var notifications = foo.getNotifications();
30         assertEquals(1, notifications.size());
31         final NotificationDefinition myNotification = notifications.iterator().next();
32         var mustConstraints = myNotification.getMustConstraints();
33         assertEquals(2, mustConstraints.size());
34
35         final var rpcs = foo.getRpcs();
36         assertEquals(1, rpcs.size());
37         final RpcDefinition myRpc = rpcs.iterator().next();
38
39         final InputSchemaNode input = myRpc.getInput();
40         assertNotNull(input);
41         mustConstraints = input.getMustConstraints();
42         assertEquals(2, mustConstraints.size());
43
44         final OutputSchemaNode output = myRpc.getOutput();
45         assertNotNull(output);
46         mustConstraints = output.getMustConstraints();
47         assertEquals(2, mustConstraints.size());
48     }
49
50     @Test
51     public void testInvalidYang10Model() {
52         assertInvalidSubstatementException(startsWith("MUST is not valid for NOTIFICATION"),
53             "/rfc7950/bug6871/foo10.yang");
54         assertInvalidSubstatementException(startsWith("MUST is not valid for INPUT"), "/rfc7950/bug6871/bar10.yang");
55         assertInvalidSubstatementException(startsWith("MUST is not valid for OUTPUT"), "/rfc7950/bug6871/baz10.yang");
56     }
57 }