--- /dev/null
+/*
+ * Copyright (c) 2015 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.assertNotNull;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class ChoiceStmtTest {
+
+ private static final YangStatementSourceImpl CHOICE_MODULE = new YangStatementSourceImpl("/model/foo.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_MODULE1 = new YangStatementSourceImpl("/model/bar.yang",
+ false);
+ private static final YangStatementSourceImpl IMPORTED_MODULE2 = new YangStatementSourceImpl("/model/baz.yang",
+ false);
+ private static final YangStatementSourceImpl INCLUDED_MODULE = new YangStatementSourceImpl("/model/subfoo.yang",
+ false);
+
+ @Test
+ public void choiceAndCaseTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("foo", null);
+ assertNotNull(testModule);
+
+ ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
+ assertNotNull(container);
+
+ ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName("how");
+ assertNotNull(choice);
+ assertEquals(5, choice.getCases().size());
+
+ ChoiceCaseNode caseNode = choice.getCaseNodeByName("input");
+ assertNotNull(caseNode);
+ caseNode = choice.getCaseNodeByName("output");
+ assertNotNull(caseNode);
+ caseNode = choice.getCaseNodeByName("interval");
+ assertNotNull(caseNode);
+ caseNode = choice.getCaseNodeByName("daily");
+ assertNotNull(caseNode);
+ caseNode = choice.getCaseNodeByName("manual");
+ assertNotNull(caseNode);
+ assertEquals("interval", choice.getDefaultCase());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class ExtensionStmtTest {
+
+ private static final YangStatementSourceImpl EXT_DEF_MODULE = new YangStatementSourceImpl("/model/bar.yang",
+ false);
+ private static final YangStatementSourceImpl EXT_DEF_MODULE2 = new YangStatementSourceImpl
+ ("/semantic-statement-parser/ext-typedef.yang",
+ false);
+ private static final YangStatementSourceImpl EXT_USE_MODULE = new YangStatementSourceImpl
+ ("/semantic-statement-parser/ext-use.yang",
+ false);
+
+ @Test
+ public void testExtensionDefinition() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, EXT_DEF_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("bar", null);
+ assertNotNull(testModule);
+
+ assertEquals(1, testModule.getExtensionSchemaNodes().size());
+
+ List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
+ ExtensionDefinition extension = extensions.get(0);
+ assertEquals("opendaylight", extension.getQName().getLocalName());
+ assertEquals("name", extension.getArgument());
+ assertTrue(extension.isYinElement());
+ }
+
+ @Test
+ public void testExtensionUsage() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, EXT_DEF_MODULE2, EXT_USE_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule1 = result.findModuleByName("ext-typedef", null);
+ assertNotNull(testModule1);
+
+ assertEquals(1, testModule1.getExtensionSchemaNodes().size());
+
+ List<ExtensionDefinition> extensions = testModule1.getExtensionSchemaNodes();
+ ExtensionDefinition extensionDefinition = extensions.get(0);
+
+ Module testModule2 = result.findModuleByName("ext-use", null);
+ assertNotNull(testModule2);
+
+ LeafSchemaNode leaf = (LeafSchemaNode) testModule2.getDataChildByName("value");
+ assertNotNull(leaf);
+
+ assertEquals(1, leaf.getUnknownSchemaNodes().size());
+ List<UnknownSchemaNode> unknownNodes = leaf.getUnknownSchemaNodes();
+ UnknownSchemaNode extensionUse = unknownNodes.get(0);
+ assertEquals(extensionDefinition.getQName().getLocalName(), extensionUse.getExtensionDefinition().getQName()
+ .getLocalName());
+ assertEquals(extensionDefinition.getArgument(), extensionUse.getExtensionDefinition().getArgument());
+
+ assertEquals("key:value", extensionUse.getNodeParameter());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class GroupingAndUsesStmtTest {
+
+ private static final YangStatementSourceImpl MODULE = new YangStatementSourceImpl("/model/bar.yang", false);
+ private static final YangStatementSourceImpl SUBMODULE = new YangStatementSourceImpl("/model/subfoo.yang", false);
+ private static final YangStatementSourceImpl GROUPING_MODULE = new YangStatementSourceImpl("/model/baz.yang",
+ false);
+ private static final YangStatementSourceImpl USES_MODULE = new YangStatementSourceImpl("/model/foo.yang", false);
+
+ @Test
+ public void groupingTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, MODULE, GROUPING_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("baz", null);
+ assertNotNull(testModule);
+
+ Set<GroupingDefinition> groupings = testModule.getGroupings();
+ assertEquals(1, groupings.size());
+
+ Iterator<GroupingDefinition> groupingsIterator = groupings.iterator();
+ GroupingDefinition grouping = groupingsIterator.next();
+ assertEquals("target", grouping.getQName().getLocalName());
+ assertEquals(5, grouping.getChildNodes().size());
+
+ AnyXmlSchemaNode anyXmlNode = (AnyXmlSchemaNode) grouping.getDataChildByName("data");
+ assertNotNull(anyXmlNode);
+ ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) grouping.getDataChildByName("how");
+ assertNotNull(choiceNode);
+ LeafSchemaNode leafNode = (LeafSchemaNode) grouping.getDataChildByName("address");
+ assertNotNull(leafNode);
+ ContainerSchemaNode containerNode = (ContainerSchemaNode) grouping.getDataChildByName("port");
+ assertNotNull(containerNode);
+ ListSchemaNode listNode = (ListSchemaNode) grouping.getDataChildByName("addresses");
+ assertNotNull(listNode);
+
+ assertEquals(1, grouping.getGroupings().size());
+ assertEquals("target-inner", grouping.getGroupings().iterator().next().getQName().getLocalName());
+
+ assertEquals(1, grouping.getTypeDefinitions().size());
+ assertEquals("group-type", grouping.getTypeDefinitions().iterator().next().getQName().getLocalName());
+
+ List<UnknownSchemaNode> unknownSchemaNodes = grouping.getUnknownSchemaNodes();
+ assertEquals(1, unknownSchemaNodes.size());
+ UnknownSchemaNode extensionUse = unknownSchemaNodes.get(0);
+ assertEquals("opendaylight", extensionUse.getExtensionDefinition().getQName().getLocalName());
+ }
+
+ @Test
+ public void usesAndRefinesTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, MODULE, SUBMODULE, GROUPING_MODULE, USES_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("foo", null);
+ assertNotNull(testModule);
+
+ Set<UsesNode> usesNodes = testModule.getUses();
+ assertEquals(1, usesNodes.size());
+
+ UsesNode usesNode = usesNodes.iterator().next();
+ assertEquals("target", usesNode.getGroupingPath().getLastComponent().getLocalName());
+ assertEquals(1, usesNode.getAugmentations().size());
+
+ ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+ assertNotNull(container);
+ container = (ContainerSchemaNode) container.getDataChildByName("destination");
+ assertEquals(1, container.getUses().size());
+
+ usesNode = container.getUses().iterator().next();
+ assertEquals("target", usesNode.getGroupingPath().getLastComponent().getLocalName());
+
+ Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
+ assertEquals(4, refines.size());
+
+ Iterator<SchemaPath> refinesKeysIterator = refines.keySet().iterator();
+ SchemaPath path = refinesKeysIterator.next();
+ assertThat(path.getLastComponent().getLocalName(), anyOf(is("port"), is("address"), is("addresses"), is("id")));
+ path = refinesKeysIterator.next();
+ assertThat(path.getLastComponent().getLocalName(), anyOf(is("port"), is("address"), is("addresses"), is("id")));
+ path = refinesKeysIterator.next();
+ assertThat(path.getLastComponent().getLocalName(), anyOf(is("port"), is("address"), is("addresses"), is("id")));
+ path = refinesKeysIterator.next();
+ assertThat(path.getLastComponent().getLocalName(), anyOf(is("port"), is("address"), is("addresses"), is("id")));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+import java.util.Iterator;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class IdentityStmtTest {
+
+ private static final YangStatementSourceImpl ILLEGAL_IDENTITY_MODULE = new YangStatementSourceImpl
+ ("/identity/identitytest.yang", false);
+ private static final YangStatementSourceImpl ILLEGAL_IDENTITY_MODULE2 = new YangStatementSourceImpl
+ ("/identity/prefixidentitytest.yang", false);
+ private static final YangStatementSourceImpl LEGAL_IDENTITY_MODULE = new YangStatementSourceImpl
+ ("/identity/import/dummy.yang", false);
+ private static final YangStatementSourceImpl LEGAL_IDENTITY_MODULE2 = new YangStatementSourceImpl
+ ("/identity/import/prefiximportidentitytest.yang", false);
+ private static final YangStatementSourceImpl ILLEGAL_IDENTITY_MODULE3 = new YangStatementSourceImpl
+ ("/identity/illegal-chained-identity-test.yang", false);
+ private static final YangStatementSourceImpl LEGAL_IDENTITY_MODULE3 = new YangStatementSourceImpl
+ ("/identity/legal-chained-identity-test.yang", false);
+ private static final YangStatementSourceImpl DUPLICATE_IDENTITY_MODULE = new YangStatementSourceImpl
+ ("/identity/duplicate-identity-test.yang", false);
+
+ @Test(expected = SomeModifiersUnresolvedException.class)
+ public void selfReferencingIdentityTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ILLEGAL_IDENTITY_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+ }
+
+ @Test(expected = SomeModifiersUnresolvedException.class)
+ public void selfReferencingIdentityWithPrefixTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ILLEGAL_IDENTITY_MODULE2);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void importedIdentityTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, LEGAL_IDENTITY_MODULE, LEGAL_IDENTITY_MODULE2);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+ }
+
+ @Test(expected = SomeModifiersUnresolvedException.class)
+ public void selfReferencingIdentityThroughChaining() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ILLEGAL_IDENTITY_MODULE3);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void chainedIdentityTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, LEGAL_IDENTITY_MODULE3);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("legal-chained-identity-test", null);
+ assertNotNull(testModule);
+
+ Set<IdentitySchemaNode> identities = testModule.getIdentities();
+ assertEquals(4, identities.size());
+
+ Iterator<IdentitySchemaNode> identitiesIterator = identities.iterator();
+ IdentitySchemaNode identity = identitiesIterator.next();
+ assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
+ ("third-identity"), is("fourth-identity")));
+
+ identity = identitiesIterator.next();
+ assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
+ ("third-identity"), is("fourth-identity")));
+
+ identity = identitiesIterator.next();
+ assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
+ ("third-identity"), is("fourth-identity")));
+
+ identity = identitiesIterator.next();
+ assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
+ ("third-identity"), is("fourth-identity")));
+ }
+
+ @Test
+ public void duplicateIdentityTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, DUPLICATE_IDENTITY_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("duplicate-identity-test", null);
+ Set<IdentitySchemaNode> identities = testModule.getIdentities();
+ assertEquals(1, identities.size());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.assertNotNull;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+public class ImportRevisionsTest {
+
+ private static final YangStatementSourceImpl ROOT_WITH_EQUAL_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/root-with-equal-revision-date.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_WITH_EQUAL_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/imported-module-with-equal-revision-date.yang", false);
+ private static final YangStatementSourceImpl ROOT_WITH_UNEQUAL_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/root-with-unequal-revision-date.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_WITH_UNEQUAL_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/imported-module-with-unequal-revision-date.yang", false);
+ private static final YangStatementSourceImpl ROOT_WITH_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/root-with-revision-date.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_WITHOUT_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/imported-module-without-revision-date.yang", false);
+ private static final YangStatementSourceImpl ROOT_WITHOUT_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/root-without-revision-date.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_WITH_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/imported-module-with-revision-date.yang", false);
+ private static final YangStatementSourceImpl ROOT_WITH_1970_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/root-with-1970-revision-date.yang", false);
+ private static final YangStatementSourceImpl ROOT_WITH_NO_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/root-with-no-revision-date.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_WITH_NO_DATE = new YangStatementSourceImpl
+ ("/import-revision-date-test/imported-module-with-no-revision-date.yang", false);
+
+ @Test
+ public void equalRevisionDatesTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_WITH_EQUAL_DATE, IMPORTED_WITH_EQUAL_DATE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test(expected = SomeModifiersUnresolvedException.class)
+ public void unequalRevisionDatesTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_WITH_UNEQUAL_DATE, IMPORTED_WITH_UNEQUAL_DATE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+
+ }
+
+ @Test(expected = SomeModifiersUnresolvedException.class)
+ public void revisionDatesInRootOnlyTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_WITH_DATE, IMPORTED_WITHOUT_DATE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revisionDatesInImportedOnlyTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_WITHOUT_DATE, IMPORTED_WITH_DATE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revision1970InRootOnlyTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_WITH_1970_DATE, IMPORTED_WITHOUT_DATE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void noRevisionInRootAndImportedTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_WITH_NO_DATE, IMPORTED_WITH_NO_DATE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Iterator;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class IncludedStmtsTest {
+
+ private static final YangStatementSourceImpl ROOT_MODULE = new YangStatementSourceImpl
+ ("/included-statements-test/root-module.yang", false);
+ private static final YangStatementSourceImpl CHILD_MODULE = new YangStatementSourceImpl
+ ("/included-statements-test/child-module.yang", false);
+
+ @Test
+ public void includedTypedefsTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_MODULE, CHILD_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("root-module", null);
+ assertNotNull(testModule);
+
+ Set<TypeDefinition<?>> typedefs = testModule.getTypeDefinitions();
+ assertEquals(2, typedefs.size());
+
+ Iterator<TypeDefinition<?>> typedefsIterator = typedefs.iterator();
+ TypeDefinition<?> typedef = typedefsIterator.next();
+ assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
+ assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
+ typedef = typedefsIterator.next();
+ assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
+ assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
+ }
+
+ @Test
+ public void includedFeaturesTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_MODULE, CHILD_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("root-module", null);
+ assertNotNull(testModule);
+
+ Set<FeatureDefinition> features = testModule.getFeatures();
+ assertEquals(2, features.size());
+
+ Iterator<FeatureDefinition> featuresIterator = features.iterator();
+ FeatureDefinition feature = featuresIterator.next();
+ assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
+ feature = featuresIterator.next();
+ assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
+ }
+
+ @Test
+ public void includedContainersAndListsTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_MODULE, CHILD_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("root-module", null);
+ assertNotNull(testModule);
+
+ ContainerSchemaNode cont = (ContainerSchemaNode) testModule.getDataChildByName("parent-container");
+ assertNotNull(cont);
+ cont = (ContainerSchemaNode) cont.getDataChildByName("child-container");
+ assertNotNull(cont);
+ assertEquals(2, cont.getChildNodes().size());
+
+ LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName("autumn-leaf");
+ assertNotNull(leaf);
+ leaf = (LeafSchemaNode) cont.getDataChildByName("winter-snow");
+ assertNotNull(leaf);
+ }
+
+ @Test
+ public void submoduleNamespaceTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, ROOT_MODULE, CHILD_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("root-module", null);
+ assertNotNull(testModule);
+
+ Module subModule = testModule.getSubmodules().iterator().next();
+ assertEquals("urn:opendaylight.org/root-module", subModule.getNamespace().toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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 static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class ListTest {
+
+ private static final YangStatementSourceImpl LIST_MODULE = new YangStatementSourceImpl("/list-test/list-test.yang",
+ false);
+
+ @Test
+ public void listAndLeavesTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, LIST_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("list-test", null);
+ assertNotNull(testModule);
+
+ ListSchemaNode list = (ListSchemaNode) testModule.getDataChildByName("simple-list");
+ assertNotNull(list);
+
+ assertTrue(list.isUserOrdered());
+ assertTrue(list.isConfiguration());
+ List<QName> keys = list.getKeyDefinition();
+ assertEquals(2, keys.size());
+
+ assertEquals("key1", keys.get(0).getLocalName());
+ assertEquals("key2", keys.get(1).getLocalName());
+
+ assertEquals(1, list.getConstraints().getMinElements().intValue());
+ assertEquals(10, list.getConstraints().getMaxElements().intValue());
+
+ assertEquals(5, list.getChildNodes().size());
+
+ LeafSchemaNode leaf = (LeafSchemaNode) list.getDataChildByName("key1");
+ assertNotNull(leaf);
+ assertTrue(leaf.getConstraints().isMandatory());
+ assertEquals("int32", leaf.getType().getQName().getLocalName());
+
+ leaf = (LeafSchemaNode) list.getDataChildByName("key2");
+ assertNotNull(leaf);
+ assertTrue(leaf.getConstraints().isMandatory());
+ assertEquals("int16", leaf.getType().getQName().getLocalName());
+
+ leaf = (LeafSchemaNode) list.getDataChildByName("old-leaf");
+ assertNotNull(leaf);
+ assertFalse(leaf.getConstraints().isMandatory());
+ assertEquals("string", leaf.getType().getQName().getLocalName());
+
+ leaf = (LeafSchemaNode) list.getDataChildByName("young-leaf");
+ assertNotNull(leaf);
+ assertFalse(leaf.getConstraints().isMandatory());
+ assertEquals("string", leaf.getType().getQName().getLocalName());
+ assertEquals("default-value", leaf.getDefault());
+
+ LeafListSchemaNode leafList = (LeafListSchemaNode) list.getDataChildByName("list-of-leaves");
+ assertNotNull(leafList);
+ assertFalse(leafList.getConstraints().isMandatory());
+ assertTrue(leafList.isUserOrdered());
+ assertEquals(2, leafList.getConstraints().getMinElements().intValue());
+ assertEquals(20, leafList.getConstraints().getMaxElements().intValue());
+ assertEquals("string", leafList.getType().getQName().getLocalName());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class MustAndWhenStmtTest {
+
+ private static final YangStatementSourceImpl MUST_MODULE = new YangStatementSourceImpl
+ ("/must-when-stmt-test/must-test.yang", false);
+ private static final YangStatementSourceImpl WHEN_MODULE = new YangStatementSourceImpl("/must-when-stmt-test/" +
+ "when-test.yang", false);
+
+ @Test
+ public void mustStmtTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, MUST_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("must-test", null);
+ assertNotNull(testModule);
+
+ ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("interface");
+ assertNotNull(container);
+ assertTrue(container.isPresenceContainer());
+
+ Set<MustDefinition> musts = container.getConstraints().getMustConstraints();
+ assertEquals(2, musts.size());
+
+ Iterator<MustDefinition> mustsIterator = musts.iterator();
+ MustDefinition mustStmt = mustsIterator.next();
+ assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and " +
+ "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
+ assertThat(mustStmt.getErrorMessage(), anyOf(is("An ethernet MTU must be 1500"), is("An atm MTU must be 64 " +
+ ".. 17966")));
+ assertThat(mustStmt.getErrorAppTag(), anyOf(is("An ethernet error"), is("An atm error")));
+ mustStmt = mustsIterator.next();
+ assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and " +
+ "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
+ assertThat(mustStmt.getErrorMessage(), anyOf(is("An ethernet MTU must be 1500"), is("An atm MTU must be 64 " +
+ ".. 17966")));
+ assertThat(mustStmt.getErrorAppTag(), anyOf(is("An ethernet error"), is("An atm error")));
+ }
+
+ @Test
+ public void whenStmtTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, WHEN_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("when-test", null);
+ assertNotNull(testModule);
+
+ ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("test-container");
+ assertNotNull(container);
+ assertEquals("conditional-leaf = 'autumn-leaf'", container.getConstraints().getWhenCondition().toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.assertNotNull;
+
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class NotificationStmtTest {
+
+ private static final YangStatementSourceImpl NOTIFICATION_MODULE = new YangStatementSourceImpl("/model/baz.yang",
+ false);
+ private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl("/model/bar.yang",
+ false);
+
+ @Test
+ public void notificationTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, NOTIFICATION_MODULE, IMPORTED_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("baz", null);
+ assertNotNull(testModule);
+
+ Set<NotificationDefinition> notifications = testModule.getNotifications();
+ assertEquals(1, notifications.size());
+
+ NotificationDefinition notification = notifications.iterator().next();
+ assertEquals("event", notification.getQName().getLocalName());
+ assertEquals(3, notification.getChildNodes().size());
+
+ LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName("event-class");
+ assertNotNull(leaf);
+ leaf = (LeafSchemaNode) notification.getDataChildByName("severity");
+ assertNotNull(leaf);
+ AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) notification.getDataChildByName("reporting-entity");
+ assertNotNull(anyXml);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.assertNotNull;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class RpcStmtTest {
+
+ private static final YangStatementSourceImpl RPC_MODULE = new YangStatementSourceImpl("/model/baz.yang", false);
+ private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl("/model/bar.yang",
+ false);
+
+ @Test
+ public void rpcTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, RPC_MODULE, IMPORTED_MODULE);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Module testModule = result.findModuleByName("baz", null);
+ assertNotNull(testModule);
+
+ assertEquals(1, testModule.getRpcs().size());
+
+ RpcDefinition rpc = testModule.getRpcs().iterator().next();
+ assertEquals("get-config", rpc.getQName().getLocalName());
+
+ ContainerSchemaNode input = rpc.getInput();
+ assertNotNull(input);
+ assertEquals(2, input.getChildNodes().size());
+
+ ContainerSchemaNode container = (ContainerSchemaNode) input.getDataChildByName("source");
+ assertNotNull(container);
+ AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) input.getDataChildByName("filter");
+ assertNotNull(anyXml);
+
+ ContainerSchemaNode output = rpc.getOutput();
+ assertNotNull(output);
+ assertEquals(1, output.getChildNodes().size());
+
+ anyXml = (AnyXmlSchemaNode) output.getDataChildByName("data");
+ assertNotNull(anyXml);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.assertNotNull;
+
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class TypedefSubStmtsTest {
+
+ private static final YangStatementSourceImpl FOOBAR = new YangStatementSourceImpl
+ ("/typedef-substmts-test/typedef-substmts-test.yang", false);
+
+ @Test
+ public void typedefSubStmtsTest() throws ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ StmtTestUtils.addSources(reactor, FOOBAR);
+
+ EffectiveSchemaContext result = reactor.buildEffective();
+ assertNotNull(result);
+
+ Set<TypeDefinition<?>> typedefs = result.getTypeDefinitions();
+ assertEquals(1, typedefs.size());
+
+ TypeDefinition<?> typedef = typedefs.iterator().next();
+ assertEquals("time-of-the-day", typedef.getQName().getLocalName());
+ assertEquals("string", typedef.getBaseType().getQName().getLocalName());
+ assertEquals("24-hour-clock", typedef.getUnits());
+ assertEquals("1am", typedef.getDefaultValue().toString());
+ }
+}
--- /dev/null
+module duplicate-identity-test {
+ namespace "urn:opendaylight.org/duplicate-identity-test";
+ prefix "didt";
+
+ identity first-identity {
+ description "this identity is not unique";
+ }
+
+ identity first-identity {
+ description "this identity is not unique";
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module illegal-chained-identity-test {
+ namespace "urn:opendaylight.org/illegal-chained-identity-test";
+ prefix icidt;
+
+ identity first-identity {
+ base second-identity;
+ }
+
+ identity second-identity {
+ base third-identity;
+ }
+
+ identity third-identity {
+ base first-identity;
+ }
+}
\ No newline at end of file
--- /dev/null
+module legal-chained-identity-test {
+ namespace "urn:opendaylight.org/legal-chained-identity-test";
+ prefix lcidt;
+
+ identity first-identity {
+ base second-identity;
+ }
+
+ identity second-identity {
+ base third-identity;
+ }
+
+ identity third-identity {
+ base fourth-identity;
+ }
+
+ identity fourth-identity {
+ description "the highest identity";
+ }
+}
\ No newline at end of file
--- /dev/null
+module imported-module-with-equal-revision-date {
+ namespace "urn:opendaylight.org/imported-module-with-equal-revision-date";
+ prefix "imported-equal-date";
+
+ revision "2010-10-25" {
+ description "Initial revision";
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module imported-module-with-no-revision-date {
+ namespace "urn:opendaylight.org/imported-module-with-no-revision-date";
+ prefix "imported-no-date";
+}
\ No newline at end of file
--- /dev/null
+module imported-module-with-revision-date {
+ namespace "urn:opendaylight.org/imported-module-with-revision-date";
+ prefix "imported-with-date";
+
+ revision "2012-04-14" {
+ description "Initial revision";
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module imported-module-with-unequal-revision-date {
+ namespace "urn:opendaylight.org/imported-module-with-unequal-revision-date";
+ prefix "imported-unequal-date";
+
+ revision "2012-10-26" {
+ description "Initial revision";
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module imported-module-without-revision-date {
+ namespace "urn:opendaylight.org/imported-module-without-revision-date";
+ prefix "imported-without-date";
+
+}
\ No newline at end of file
--- /dev/null
+module root-with-1970-revision-date {
+ namespace "urn:opendaylight.org/root-with-1970-revision-date";
+ prefix "root-1970-date";
+
+ import imported-module-without-revision-date {
+ prefix "imported-without-date";
+ revision-date "1970-01-01";
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module root-with-equal-revision-date {
+ namespace "urn:opendaylight.org/root-with-equal-revision-date";
+ prefix "root-equal-date";
+
+ import imported-module-with-equal-revision-date {
+ prefix "imported-equal-date";
+ revision-date 2010-10-25;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module root-with-no-revision-date {
+ namespace "urn:opendaylight.org/root-with-no-revision-date";
+ prefix "root-no-date";
+
+ import imported-module-with-no-revision-date {
+ prefix "imported-no-date";
+ }
+}
\ No newline at end of file
--- /dev/null
+module root-with-revision-date {
+ namespace "urn:opendaylight.org/root-with-revision-date";
+ prefix "root-with-date";
+
+ import imported-module-without-revision-date {
+ prefix "imported-without-date";
+ revision-date "2010-06-15";
+ }
+}
\ No newline at end of file
--- /dev/null
+module root-with-unequal-revision-date {
+ namespace "urn:opendaylight.org/root-with-unequal-revision-date";
+ prefix "root-unequal-date";
+
+ import imported-module-with-unequal-revision-date {
+ prefix "imported-unequal-date";
+ revision-date 2012-10-25;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module root-without-revision-date {
+ namespace "urn:opendaylight.org/root-without-revision-date";
+ prefix "root-without-date";
+
+ import imported-module-with-revision-date {
+ prefix "imported-with-date";
+ }
+
+}
\ No newline at end of file
--- /dev/null
+submodule child-module {
+
+ belongs-to "root-module" {
+ prefix "root";
+ }
+
+ typedef new-string-type {
+ type string {
+ pattern "[abc]{3}";
+ }
+ }
+
+ typedef new-int32-type {
+ type int32 {
+ range "1..4 | 10..20";
+ }
+ }
+
+ feature new-feature1 {
+ description "a new feature";
+ }
+
+ feature new-feature2 {
+ description "another new feature";
+ }
+
+ container parent-container {
+ container child-container {
+ leaf autumn-leaf {
+ type string;
+ }
+ leaf winter-snow {
+ type string;
+ }
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module root-module {
+ namespace "urn:opendaylight.org/root-module";
+ prefix "rtm";
+
+ include child-module;
+
+ leaf new-leaf {
+ type new-string-type;
+ }
+
+ leaf old-leaf {
+ type new-int32-type;
+ }
+}
\ No newline at end of file
--- /dev/null
+module list-test {
+ namespace "urn:opendaylight.org/list-test";
+ prefix "lt";
+
+ list simple-list {
+ key "key1 key2";
+ ordered-by user;
+ min-elements 1;
+ max-elements 10;
+ config true;
+
+ leaf key1 {
+ type int32;
+ mandatory true;
+ }
+
+ leaf key2 {
+ type int16;
+ mandatory true;
+ }
+
+ leaf old-leaf {
+ type string;
+ }
+
+ leaf young-leaf {
+ type string;
+ default "default-value";
+ }
+
+ leaf-list list-of-leaves {
+ type string;
+ ordered-by user;
+ min-elements 2;
+ max-elements 20;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module must-test {
+ namespace "urn:opendaylight.org/must-test";
+ prefix "mt";
+
+ container interface {
+ presence "some text";
+
+ leaf ifType {
+ type enumeration {
+ enum ethernet;
+ enum atm;
+ }
+ }
+ leaf ifMTU {
+ type uint32;
+ }
+ must "ifType != 'ethernet' or " +
+ "(ifType = 'ethernet' and ifMTU = 1500)" {
+ error-app-tag "An ethernet error";
+ error-message "An ethernet MTU must be 1500";
+ }
+ must "ifType != 'atm' or " +
+ "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
+ error-app-tag "An atm error";
+ error-message "An atm MTU must be 64 .. 17966";
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module when-test {
+ namespace "urn:opendaylight.org/when-test";
+ prefix "wt";
+
+ container test-container {
+ when "conditional-leaf = 'autumn-leaf'";
+ leaf conditional-leaf {
+ type string;
+ }
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module typedef-substmts-test {
+ namespace "urn:opendaylight.org/typedef-substmts-test";
+ prefix "tdst";
+
+ typedef time-of-the-day {
+ type string;
+ units 24-hour-clock;
+ default 1am;
+ }
+
+}
\ No newline at end of file