Clean up TreeNode API
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / IdentityStmtTest.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.stmt;
9
10 import static org.hamcrest.CoreMatchers.anyOf;
11 import static org.hamcrest.CoreMatchers.is;
12 import static org.hamcrest.CoreMatchers.startsWith;
13 import static org.hamcrest.MatcherAssert.assertThat;
14 import static org.junit.jupiter.api.Assertions.assertEquals;
15 import static org.junit.jupiter.api.Assertions.assertNotNull;
16
17 import org.junit.jupiter.api.Test;
18 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20
21 class IdentityStmtTest extends AbstractYangTest {
22     @Test
23     void selfReferencingIdentityTest() {
24         assertInferenceException(
25             startsWith("Unable to resolve identity (urn:test.identitytest?revision=2014-09-17)test and base identity "
26                 + "(urn:test.identitytest?revision=2014-09-17)test [at "),
27             "/identity/identitytest.yang");
28     }
29
30     @Test
31     void selfReferencingIdentityWithPrefixTest() {
32         assertInferenceException(
33             startsWith("Unable to resolve identity (urn:test.prefixidentitytest?revision=2014-09-24)prefixtest and "
34                 + "base identity (urn:test.prefixidentitytest?revision=2014-09-24)prefixtest [at "),
35             "/identity/prefixidentitytest.yang");
36     }
37
38     @Test
39     void importedIdentityTest() {
40         assertEffectiveModel("/identity/import/dummy.yang", "/identity/import/prefiximportidentitytest.yang");
41     }
42
43     @Test
44     void selfReferencingIdentityThroughChaining() {
45         assertInferenceException(
46             startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at "),
47             "/identity/illegal-chained-identity-test.yang");
48     }
49
50     @Test
51     void chainedIdentityTest() {
52         final var result = assertEffectiveModel("/identity/legal-chained-identity-test.yang");
53
54         Module testModule = result.findModules("legal-chained-identity-test").iterator().next();
55         assertNotNull(testModule);
56
57         var identities = testModule.getIdentities();
58         assertEquals(4, identities.size());
59
60         var identitiesIterator = identities.iterator();
61         IdentitySchemaNode identity = identitiesIterator.next();
62         assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
63             is("third-identity"), is("fourth-identity")));
64
65         identity = identitiesIterator.next();
66         assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
67             is("third-identity"), is("fourth-identity")));
68
69         identity = identitiesIterator.next();
70         assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
71             is("third-identity"), is("fourth-identity")));
72
73         identity = identitiesIterator.next();
74         assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
75             is("third-identity"), is("fourth-identity")));
76     }
77
78     @Test
79     void duplicateIdentityTest() {
80         assertSourceException(startsWith("Duplicate identity definition "), "/identity/duplicate-identity-test.yang");
81     }
82 }