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.yin;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.stmt.TestUtils;
22 public class YinFileExtensionStmtTest extends AbstractYinModulesTest {
25 public void testExtensions() {
26 Module testModule = TestUtils.findModule(context, "config").get();
27 assertNotNull(testModule);
29 List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
30 assertEquals(5, extensions.size());
32 Iterator<ExtensionDefinition> extIterator = extensions.iterator();
33 ExtensionDefinition extension = extIterator.next();
34 assertEquals("name", extension.getArgument());
35 assertEquals("java-class", extension.getQName().getLocalName());
36 assertEquals(Optional.of("YANG language extension carrying the fully-qualified name of\n"
37 + "a Java class. Code generation tools use the provided reference\n"
38 + "to tie a specific construct to its Java representation."), extension.getDescription());
40 extension = extIterator.next();
41 assertEquals("name", extension.getArgument());
42 assertEquals("required-identity", extension.getQName().getLocalName());
43 assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
44 + "leafref, which points to a identityref, should additionally\n"
45 + "require the target node is actually set to a descendant to\n"
46 + "of a particular identity.\n"
48 + "This is a workaround to two YANG deficiencies:\n"
49 + "1) not being able to leafref instances of identityref\n"
50 + "2) not being able to refine an identityref\n"
52 + "This extension takes one argument, name, which MUST be the name\n"
53 + "of an identity. Furthermore, that identity MUST be based,\n"
54 + "directly or indirectly, on the identity, which is referenced by\n"
55 + "the leaf reference, which is annotated with this extension."), extension.getDescription());
57 extension = extIterator.next();
58 assertNull(extension.getArgument());
59 assertEquals("inner-state-bean", extension.getQName().getLocalName());
60 assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
61 + "list located under module's state should be treated as a list\n"
62 + "of child state beans instead of just an ordinary list attribute"), extension.getDescription());
64 extension = extIterator.next();
65 assertEquals("name", extension.getArgument());
66 assertEquals("provided-service", extension.getQName().getLocalName());
67 assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
68 + "module provides certain service. This extension can be placed\n"
69 + "on identities that are based on module-type. Zero or more services\n"
70 + "can be provided.\n"
71 + "This extension takes one argument - name - which MUST be the name\n"
72 + "of an identity. Furthermore, this identity MUST be based on\n"
73 + "service-type."), extension.getDescription());
75 extension = extIterator.next();
76 assertEquals("java-prefix", extension.getArgument());
77 assertEquals("java-name-prefix", extension.getQName().getLocalName());
78 assertEquals(Optional.of("YANG language extension carrying java simple class name prefix\n"
79 + "that will be taken into account when generating java code from\n"
80 + "identities that are based on module-type."), extension.getDescription());