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