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