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.stmt;
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;
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;
21 class IdentityStmtTest extends AbstractYangTest {
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");
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");
39 void importedIdentityTest() {
40 assertEffectiveModel("/identity/import/dummy.yang", "/identity/import/prefiximportidentitytest.yang");
44 void selfReferencingIdentityThroughChaining() {
45 assertInferenceException(
46 startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at "),
47 "/identity/illegal-chained-identity-test.yang");
51 void chainedIdentityTest() {
52 final var result = assertEffectiveModel("/identity/legal-chained-identity-test.yang");
54 Module testModule = result.findModules("legal-chained-identity-test").iterator().next();
55 assertNotNull(testModule);
57 var identities = testModule.getIdentities();
58 assertEquals(4, identities.size());
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")));
65 identity = identitiesIterator.next();
66 assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
67 is("third-identity"), is("fourth-identity")));
69 identity = identitiesIterator.next();
70 assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
71 is("third-identity"), is("fourth-identity")));
73 identity = identitiesIterator.next();
74 assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
75 is("third-identity"), is("fourth-identity")));
79 void duplicateIdentityTest() {
80 assertSourceException(startsWith("Duplicate identity definition "), "/identity/duplicate-identity-test.yang");