Bug 3899: Milestone: Increase test coverage for Yangtools 06/34406/2
authorIgor Foltin <ifoltin@cisco.com>
Wed, 10 Feb 2016 15:24:51 +0000 (16:24 +0100)
committerIgor Foltin <ifoltin@cisco.com>
Thu, 11 Feb 2016 14:41:38 +0000 (15:41 +0100)
Added unit test for DomToNormalizedNodeParserFactory.

Added unit test for declared anyxml statement.
More tests for declared yang statements will be added in the future.

Change-Id: If98d5fe6a4ac634c9060d2bbe186e0cb90482a35
Signed-off-by: Igor Foltin <ifoltin@cisco.com>
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java [new file with mode: 0644]
yang/yang-data-impl/src/test/resources/foo.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/DeclaredStatementsTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/declared-statements-test/anyxml-declared-test.yang [new file with mode: 0644]

diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java
new file mode 100644 (file)
index 0000000..fac21ed
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 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.data.impl.schema.transform.dom.parser;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.impl.RetestUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.w3c.dom.Element;
+
+public class DomToNormalizedNodeParserFactoryTest {
+
+    @Test
+    public void testFactoryInstantiation() throws ReactorException {
+        YangStatementSourceImpl foo = new YangStatementSourceImpl("/foo.yang", false);
+
+        SchemaContext schemaContext = RetestUtils.parseYangSources(foo);
+
+        DomToNormalizedNodeParserFactory factory = DomToNormalizedNodeParserFactory.getInstance(
+                DomUtils.defaultValueCodecProvider(), schemaContext,
+                new DomToNormalizedNodeParserFactory.BuildingStrategyProvider() {}, true);
+
+        assertNotNull(factory);
+
+        ToNormalizedNodeParser<Element, LeafSetEntryNode<?>, LeafListSchemaNode> leafSetEntryNodeParser =
+                factory.getLeafSetEntryNodeParser();
+        assertNotNull(leafSetEntryNodeParser);
+
+        ToNormalizedNodeParser<Element, MapEntryNode, ListSchemaNode> mapEntryNodeParser =
+                factory.getMapEntryNodeParser();
+        assertNotNull(mapEntryNodeParser);
+
+        ToNormalizedNodeParser<Element, UnkeyedListEntryNode, ListSchemaNode> unkeyedListEntryNodeParser =
+                factory.getUnkeyedListEntryNodeParser();
+        assertNotNull(unkeyedListEntryNodeParser);
+
+        ToNormalizedNodeParser<Element, OrderedMapNode, ListSchemaNode> orderedListNodeParser =
+                factory.getOrderedListNodeParser();
+        assertNotNull(orderedListNodeParser);
+    }
+}
diff --git a/yang/yang-data-impl/src/test/resources/foo.yang b/yang/yang-data-impl/src/test/resources/foo.yang
new file mode 100644 (file)
index 0000000..2c425b2
--- /dev/null
@@ -0,0 +1,14 @@
+module foo {
+    namespace "foo";
+    prefix "foo";
+
+    container cont {
+        leaf lf1 {
+            type string;
+        }
+
+        leaf lf2 {
+            type string;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/DeclaredStatementsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/DeclaredStatementsTest.java
new file mode 100644 (file)
index 0000000..166a9f4
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2016 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.stmt.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Collection;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AnyXmlEffectiveStatementImpl;
+
+public class DeclaredStatementsTest {
+
+    @Test
+    public void testDeclaredAnyXml() throws ReactorException {
+        YangStatementSourceImpl anyxmlStmtModule =
+                new YangStatementSourceImpl("/declared-statements-test/anyxml-declared-test.yang", false);
+
+        SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
+        assertNotNull(schemaContext);
+
+        Module testModule = schemaContext.findModuleByName("anyxml-declared-test", null);
+        assertNotNull(testModule);
+
+        AnyXmlSchemaNode anyxmlSchemaNode = (AnyXmlSchemaNode) testModule.getDataChildByName(
+                QName.create(testModule.getQNameModule(), "foobar"));
+        assertNotNull(anyxmlSchemaNode);
+        AnyxmlStatement anyxmlStatement = ((AnyXmlEffectiveStatementImpl) anyxmlSchemaNode).getDeclared();
+
+        QName name = anyxmlStatement.getName();
+        assertNotNull(name);
+
+        WhenStatement whenStatement = anyxmlStatement.getWhenStatement();
+        assertNotNull(whenStatement);
+        RevisionAwareXPath whenRevisionAwareXPath = whenStatement.getCondition();
+        assertNotNull(whenRevisionAwareXPath);
+        DescriptionStatement whenStatementDescription = whenStatement.getDescription();
+        assertNotNull(whenStatementDescription);
+        ReferenceStatement whenStatementReference = whenStatement.getReference();
+        assertNotNull(whenStatementReference);
+
+        Collection<? extends IfFeatureStatement> ifFeatureStatements = anyxmlStatement.getIfFeatures();
+        assertNotNull(ifFeatureStatements);
+        assertEquals(1, ifFeatureStatements.size());
+        QName ifFeatureName = ifFeatureStatements.iterator().next().getName();
+        assertNotNull(ifFeatureName);
+
+        Collection<? extends MustStatement> mustStatements = anyxmlStatement.getMusts();
+        assertNotNull(mustStatements);
+        assertEquals(1, mustStatements.size());
+        MustStatement mustStatement = mustStatements.iterator().next();
+        RevisionAwareXPath mustRevisionAwareXPath = mustStatement.getCondition();
+        assertNotNull(mustRevisionAwareXPath);
+        ErrorAppTagStatement errorAppTagStatement = mustStatement.getErrorAppTagStatement();
+        assertNotNull(errorAppTagStatement);
+        ErrorMessageStatement errorMessageStatement = mustStatement.getErrorMessageStatement();
+        assertNotNull(errorMessageStatement);
+        DescriptionStatement mustStatementDescription = mustStatement.getDescription();
+        assertNotNull(mustStatementDescription);
+        ReferenceStatement mustStatementReference = mustStatement.getReference();
+        assertNotNull(mustStatementReference);
+
+        ConfigStatement configStatement = anyxmlStatement.getConfig();
+        assertNotNull(configStatement);
+        assertFalse(configStatement.getValue());
+
+        StatusStatement statusStatement = anyxmlStatement.getStatus();
+        assertNotNull(statusStatement);
+        Status status = statusStatement.getValue();
+        assertNotNull(status);
+
+        DescriptionStatement descriptionStatement = anyxmlStatement.getDescription();
+        assertNotNull(descriptionStatement);
+        assertEquals("anyxml description", descriptionStatement.getText());
+
+        ReferenceStatement referenceStatement = anyxmlStatement.getReference();
+        assertNotNull(referenceStatement);
+        assertEquals("anyxml reference", referenceStatement.getText());
+
+        MandatoryStatement mandatoryStatement = anyxmlStatement.getMandatory();
+        assertNotNull(mandatoryStatement);
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/declared-statements-test/anyxml-declared-test.yang b/yang/yang-parser-impl/src/test/resources/declared-statements-test/anyxml-declared-test.yang
new file mode 100644 (file)
index 0000000..d70ece5
--- /dev/null
@@ -0,0 +1,23 @@
+module anyxml-declared-test {
+    namespace "anyxml-declared-test";
+    prefix "axdt";
+
+    anyxml foobar {
+        when "foo = 'bar'" {
+            description "when description";
+            reference "when reference";
+        }
+        if-feature foobar-feature;
+        must "bar != 'foo'" {
+            description "must description";
+            reference "must reference";
+            error-app-tag "error";
+            error-message "error";
+        }
+        config false;
+        status current;
+        description "anyxml description";
+        reference "anyxml reference";
+        mandatory "false";
+    }
+}
\ No newline at end of file