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.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Optional;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.stmt.TestUtils;
26 import org.xml.sax.SAXException;
28 public class YinFileExtensionStmtTest {
30 private SchemaContext context;
33 public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
34 context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
35 assertEquals(9, context.getModules().size());
39 public void testExtensions() {
40 Module testModule = TestUtils.findModule(context, "config").get();
41 assertNotNull(testModule);
43 List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
44 assertEquals(5, extensions.size());
46 Iterator<ExtensionDefinition> extIterator = extensions.iterator();
47 ExtensionDefinition extension = extIterator.next();
48 assertEquals("name", extension.getArgument());
49 assertEquals("java-class", extension.getQName().getLocalName());
50 assertEquals(Optional.of("YANG language extension carrying the fully-qualified name of\n"
51 + "a Java class. Code generation tools use the provided reference\n"
52 + "to tie a specific construct to its Java representation."), extension.getDescription());
54 extension = extIterator.next();
55 assertEquals("name", extension.getArgument());
56 assertEquals("required-identity", extension.getQName().getLocalName());
57 assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
58 + "leafref, which points to a identityref, should additionally\n"
59 + "require the target node is actually set to a descendant to\n"
60 + "of a particular identity.\n"
62 + "This is a workaround to two YANG deficiencies:\n"
63 + "1) not being able to leafref instances of identityref\n"
64 + "2) not being able to refine an identityref\n"
66 + "This extension takes one argument, name, which MUST be the name\n"
67 + "of an identity. Furthermore, that identity MUST be based,\n"
68 + "directly or indirectly, on the identity, which is referenced by\n"
69 + "the leaf reference, which is annotated with this extension."), extension.getDescription());
71 extension = extIterator.next();
72 assertNull(extension.getArgument());
73 assertEquals("inner-state-bean", extension.getQName().getLocalName());
74 assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
75 + "list located under module's state should be treated as a list\n"
76 + "of child state beans instead of just an ordinary list attribute"), extension.getDescription());
78 extension = extIterator.next();
79 assertEquals("name", extension.getArgument());
80 assertEquals("provided-service", extension.getQName().getLocalName());
81 assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
82 + "module provides certain service. This extension can be placed\n"
83 + "on identities that are based on module-type. Zero or more services\n"
84 + "can be provided.\n"
85 + "This extension takes one argument - name - which MUST be the name\n"
86 + "of an identity. Furthermore, this identity MUST be based on\n"
87 + "service-type."), extension.getDescription());
89 extension = extIterator.next();
90 assertEquals("java-prefix", extension.getArgument());
91 assertEquals("java-name-prefix", extension.getQName().getLocalName());
92 assertEquals(Optional.of("YANG language extension carrying java simple class name prefix\n"
93 + "that will be taken into account when generating java code from\n"
94 + "identities that are based on module-type."), extension.getDescription());