Fixed methods parseQName and handleUnknownNode in YangParserListenerImpl class. Now if extension contains ":"
as argument value and string before ":" doesn't represent prefix for import the argument will be parsed as ordinary
string and will not throw exception.
Log level in parseQName has been changed from warn to debug.
Tests in yang-parser-impl has been modified since they're lacked of import definitions of extensions in yang modules.
Change-Id: I84debed2bef1a0694a7019c296433b8b089e6d80
Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
}
}
+ /**
+ * Method transforms string representation of yang element (i.e. leaf name, container name etc.) into QName.
+ * The namespace of QName is assigned from parent module same as revision date of module. If String qname parameter
+ * contains ":" the string is evaluated as prefix:name of element. In this case method will look into import map
+ * and extract correct ModuleImport. If such import is not present in import map the method will throw {@link YangParseException}
+ * <br>
+ * If ModuleImport is present but the value of namespace in ModuleImport is <code>null</code> the method wil throw {@link YangParseException}
+ *
+ * @param qnameString QName value as String
+ * @param line line in Yang model document where QName occur.
+ * @return transformed string qname parameter as QName structure.
+ *
+ * @throws YangParseException
+ */
private QName parseQName(final String qnameString, final int line) {
final QName qname;
if (qnameString.indexOf(':') == -1) {
} else {
ModuleImport imp = moduleBuilder.getImport(prefix);
if (imp == null) {
- LOG.warn("Error in module {} at line {}: No import found with prefix {}", moduleName, line, prefix);
- return QName.create(name);
+ LOG.debug("Error in module {} at line {}: No import found with prefix {}", moduleName, line, prefix);
+ throw new YangParseException(moduleName, line, "Error in module " + moduleName
+ + " No import found with prefix " + prefix + " not found.");
}
Date revision = imp.getRevision();
TreeMap<Date, URI> namespaces = namespaceContext.get(imp.getModuleName());
QName qname = null;
try {
+ //FIXME: rewrite whole method to handle unknown nodes properly.
+ // This should be bugfix for bug https://bugs.opendaylight.org/show_bug.cgi?id=1539
+ // After this fix bug https://bugs.opendaylight.org/show_bug.cgi?id=1538 MUST be fixed since
+ // they are dependent!!!
if (Strings.isNullOrEmpty(nodeParameter)) {
qname = nodeType;
} else {
qname = QName.create(moduleQName, it.next());
}
}
- } catch (IllegalArgumentException e) {
+ } catch (IllegalArgumentException | YangParseException ex) {
qname = nodeType;
}
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
/**
- * Test antlr grammar capability to parse description statement in unknown node.
+ * Test ANTLR4 grammar capability to parse description statement in unknown node.
*
- * Not that everything under unknown node is unknown node.
+ * Note: Everything under unknown node is unknown node.
*/
public class Bug1412Test {
Date revision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-25");
QNameModule qm = QNameModule.create(URI.create("urn:test:bug1412"), revision);
- QName expectedNodeType = new QName(null, null, null, "action");
- assertEquals(QName.create(null, (Date) null, "action"), action.getNodeType());
+ QName expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action");
+ assertEquals(expectedNodeType, action.getNodeType());
assertEquals("hello", action.getNodeParameter());
QName expectedQName = QName.create(qm, "hello");
assertEquals(expectedQName, action.getQName());
assertNotNull(actionPoint);
assertNotNull(output);
- expectedNodeType = new QName(null, null, null, "info");
+ expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info");
assertEquals(expectedNodeType, info.getNodeType());
assertEquals("greeting", info.getNodeParameter());
assertEquals(expectedNodeType, description.getNodeType());
assertEquals("say greeting", description.getNodeParameter());
- expectedNodeType = new QName(null, null, null, "actionpoint");
+ expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint");
assertEquals(expectedNodeType, actionPoint.getNodeType());
assertEquals("entry", actionPoint.getNodeParameter());
import org.opendaylight.yangtools.yang.model.api.Module;
/**
- * Test antlr grammar capability to parse unknown node in extension argument
+ * Test ANTLR4 grammar capability to parse unknown node in extension argument
* declaration.
*
- * Not that everything under unknown node is unknown node.
+ * Note: Everything under unknown node is unknown node.
*/
public class Bug1413Test {
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Module;
+
+/**
+ * Test for testing of extensions and their arguments.
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class ParsingExtensionValueTest {
+
+ private Set<Module> modules;
+
+ @Before
+ public void init() throws Exception {
+ DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+ modules = TestUtils.loadModules(getClass().getResource("/extensions").toURI());
+ assertEquals(2, modules.size());
+ }
+
+ @Test
+ public void parsingExtensionArgsTest() {
+
+ }
+}
namespace "urn:test:bug1412";
prefix "b1412";
+ import extensions {
+ prefix ext;
+ revision-date "2014-07-25";
+ }
+
revision "2014-07-25" {
}
--- /dev/null
+module extensions {
+ yang-version 1;
+ namespace "urn:test:bug1412:ext:definitions";
+ prefix "ext";
+
+ revision "2014-07-25" {
+ }
+
+ extension action {
+ argument hello {
+
+ }
+ }
+
+ extension info {
+ argument string;
+ }
+
+ extension actionpoint {
+ argument entry {
+
+ }
+ }
+
+ extension internal {
+
+ }
+}
\ No newline at end of file
namespace "odl:test:bug1413";
prefix "b1413";
- revision "2014-07-25" {
+ import extensions {
+ prefix ext;
+ revision-date "2014-07-25";
}
+ revision "2014-07-25" {
+ }
extension info {
argument text {
--- /dev/null
+module extensions {
+ yang-version 1;
+ namespace "urn:test:bug1412:ext:definitions";
+ prefix "ext";
+
+ revision "2014-07-25" {
+ }
+
+ extension arg-type {
+
+ }
+}
\ No newline at end of file
--- /dev/null
+module ext-typedef {
+ yang-version 1;
+ namespace "urn:simple.extension.typedefs";
+ prefix "ext";
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ description "Model for testing and resolving of extension typedefs.";
+
+ revision "2014-08-07" {
+ reference "Initial revision.";
+ }
+
+ extension simple-ext-w-arg {
+ argument "ext-arg";
+ description "Extension with single argument definition.";
+ }
+}
\ No newline at end of file
--- /dev/null
+module ext-use {
+ yang-version 1;
+ namespace "urn:simple.extension.use";
+ prefix "ext-use";
+
+ import ext-typedef { prefix "ext"; }
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ description "Model for testing of used extensions across model.";
+
+ revision "2014-08-07" {
+ reference "Initial revision.";
+ }
+
+ leaf value {
+ ext:simple-ext-w-arg "key:value";
+ type uint32;
+ description "value";
+ }
+
+ grouping inner-ext {
+ ext:simple-ext-w-arg "value:test";
+
+ leaf inner-value {
+ ext:simple-ext-w-arg "key:inner-value";
+ type uint32;
+ description "value";
+ }
+ }
+
+ container cont-ext {
+ ext:simple-ext-w-arg "value:test";
+
+ leaf inner-value {
+ ext:simple-ext-w-arg "value:test";
+ type string;
+ }
+ }
+}
\ No newline at end of file