From 97057a1d88bbb085992799a933fd07315d223138 Mon Sep 17 00:00:00 2001 From: "Filip.Gregor" Date: Tue, 22 Dec 2015 15:31:13 +0100 Subject: [PATCH] Bug 4656: Yang parser does not determine configuration true or false properly minor fix Change-Id: I2e58387fcd3012a70d302323b6bd533c285a0211 Signed-off-by: Filip.Gregor --- .../AbstractEffectiveDataSchemaNode.java | 4 +- .../effective/CaseEffectiveStatementImpl.java | 24 + .../yang/stmt/test/CaseStmtTest.java | 547 ++++++++++++++++++ .../src/test/resources/case-test/bar.yang | 168 ++++++ .../case-test-exceptions/case/foo.yang | 20 + .../case-test-exceptions/choice/foo.yang | 20 + .../src/test/resources/case-test/foo.yang | 206 +++++++ 7 files changed, 986 insertions(+), 3 deletions(-) create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java create mode 100644 yang/yang-parser-impl/src/test/resources/case-test/bar.yang create mode 100644 yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/case/foo.yang create mode 100644 yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/choice/foo.yang create mode 100644 yang/yang-parser-impl/src/test/resources/case-test/foo.yang diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDataSchemaNode.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDataSchemaNode.java index c273cb5862..b8863bda72 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDataSchemaNode.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDataSchemaNode.java @@ -27,9 +27,7 @@ abstract class AbstractEffectiveDataSchemaNode ctx) { super(ctx); this.constraints = EffectiveConstraintDefinitionImpl.forParent(this); - - ConfigEffectiveStatementImpl configStmt = firstEffective(ConfigEffectiveStatementImpl.class); - this.configuration = (configStmt == null) ? true : configStmt.argument(); + this.configuration = ctx.isConfiguration(); // initCopyType List copyTypesFromOriginal = ctx.getCopyHistory(); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java index 36d2a13726..8bfab0a13b 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; import com.google.common.base.Optional; +import java.util.Collection; import java.util.Objects; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; @@ -15,16 +16,34 @@ import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase; public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer implements ChoiceCaseNode, DerivableSchemaNode { private final ChoiceCaseNode original; + private final boolean configuration; public CaseEffectiveStatementImpl( final StmtContext> ctx) { super(ctx); this.original = ctx.getOriginalCtx() == null ? null : (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective(); + + if (ctx.isConfiguration()) { + configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements()) || + isAtLeastOneChildConfiguration(ctx.effectiveSubstatements()); + } else { + configuration = false; + } + } + + private boolean isAtLeastOneChildConfiguration(Collection> substatements) { + for (StatementContextBase substatement : substatements) { + if (substatement.isConfiguration()) { + return true; + } + } + return false; } @Override @@ -32,6 +51,11 @@ public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDat return Optional.fromNullable(original); } + @Override + public boolean isConfiguration() { + return configuration; + } + @Override public int hashCode() { final int prime = 31; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java new file mode 100644 index 0000000000..72c001fa50 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java @@ -0,0 +1,547 @@ +/* + * 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.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ChoiceEffectiveStatementImpl; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ContainerEffectiveStatementImpl; + +public class CaseStmtTest { + private SchemaContext schema; + private Module rootFoo, rootBar; + private QNameModule qnameFoo, qnameBar; + private DataSchemaNode tempChild, tempSecondChild, tempThirdChild; + private ChoiceCaseNode tempChoice; + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Before + public void setup() throws ReactorException, FileNotFoundException, URISyntaxException, ParseException { + schema = StmtTestUtils.parseYangSources("/case-test"); + String date_s = "2015-09-09 00:00:00.0"; + SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + Date date = dt.parse(date_s); + rootFoo = schema.findModuleByName("foo", date); + rootBar = schema.findModuleByName("bar", date); + assertNotNull(rootFoo); + assertNotNull(rootBar); + qnameFoo = QNameModule.create(URI.create("foo"), date); + qnameBar = QNameModule.create(URI.create("bar"), date); + assertNotNull(qnameFoo); + assertNotNull(qnameBar); + } + + @Test + public void caseTest() { + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-fff")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-ffn")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-fnf")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-nff")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-nnf")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-nfn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-fnn")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-ttt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-ttn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-tnt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-ntt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-nnt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-ntn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-tnn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-tff")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-tnf")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-tfn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-ntf")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + } + + @Test + public void shortCaseTest() { + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-fff")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-ffn")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-fnf")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-nff")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-nnf")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-nfn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-fnn")); + assertNotNull(tempChild); + assertFalse(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-ttt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-ttn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-tnt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-ntt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-nnt")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-ntn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-tnn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertTrue(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertTrue(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-tff")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-tnf")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-tfn")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertFalse(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + + tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-ntf")); + assertNotNull(tempChild); + assertTrue(tempChild.isConfiguration()); + tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next(); + assertNotNull(tempSecondChild); + assertTrue(tempSecondChild.isConfiguration()); + tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next(); + assertNotNull(tempChoice); + assertFalse(tempChoice.isConfiguration()); + tempThirdChild = tempChoice.getChildNodes().iterator().next(); + assertNotNull(tempThirdChild); + assertFalse(tempThirdChild.isConfiguration()); + } + + @Test + public void InferenceExceptionChoiceTest() throws ReactorException, FileNotFoundException, URISyntaxException { + expectedEx.expect(InferenceException.class); + schema = StmtTestUtils.parseYangSources("/case-test/case-test-exceptions/choice"); + } + + @Test + public void InferenceExceptionCaseTest() throws ReactorException, FileNotFoundException, URISyntaxException { + expectedEx.expect(InferenceException.class); + schema = StmtTestUtils.parseYangSources("/case-test/case-test-exceptions/case"); + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/case-test/bar.yang b/yang/yang-parser-impl/src/test/resources/case-test/bar.yang new file mode 100644 index 0000000000..d90a570e78 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/case-test/bar.yang @@ -0,0 +1,168 @@ +module bar { + yang-version 1; + namespace "bar"; + prefix "br"; + + revision "2015-09-09" { + reference "NO REF"; + } + + container sh-root-fff { + config false; + choice sh-choice-fff { + config false; + container sh-c-fff { + config false; + } + } + } + + container sh-root-ffn { + config false; + choice sh-choice-ffn { + config false; + container sh-c-ffn { + } + } + } + + container sh-root-fnf { + config false; + choice sh-choice-fnf { + container sh-c-fnf { + config false; + } + } + } + + container sh-root-nff { + choice sh-choice-nff { + config false; + container sh-c-nff { + config false; + } + } + } + + container sh-root-nnf { + choice sh-choice-nnf { + container sh-c-nnf { + config false; + } + } + } + + container sh-root-nfn { + choice sh-choice-nfn { + config false; + container sh-c-nfn { + } + } + } + + container sh-root-fnn { + config false; + choice sh-choice-fnn { + container sh-c-fnn { + } + } + } + + container sh-root-ttt { + config true; + choice sh-choice-ttt { + config true; + container sh-c-ttt { + config true; + } + } + } + + container sh-root-ntt { + choice sh-choice-ntt { + config true; + container sh-c-ntt { + config true; + } + } + } + + container sh-root-tnt { + config true; + choice sh-choice-tnt { + container sh-c-tnt { + config true; + } + } + } + + container sh-root-ttn { + config true; + choice sh-choice-ttt { + config true; + container sh-c-ttt { + } + } + } + + container sh-root-tnn { + config true; + choice sh-choice-tnn { + container sh-c-tnn { + } + } + } + + container sh-root-ntn { + choice sh-choice-ntn { + config true; + container sh-c-ntn { + } + } + } + + container sh-root-nnt { + choice sh-choice-nnt { + container sh-c-nnt { + config true; + } + } + } + + container sh-root-tff { + config true; + choice sh-choice-tff { + config false; + container c-tff { + config false; + } + } + } + + container sh-root-tfn { + config true; + choice sh-choice-tfn { + config false; + container sh-c-tfn { + } + } + } + + container sh-root-tnf { + config true; + choice sh-choice-tnf { + container sh-c-tnf { + config false; + } + } + } + + container sh-root-ntf { + choice sh-choice-ntf { + config true; + container sh-c-ntf { + config false; + } + } + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/case/foo.yang b/yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/case/foo.yang new file mode 100644 index 0000000000..0d33a9b466 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/case/foo.yang @@ -0,0 +1,20 @@ +module foo { + yang-version 1; + namespace "foo"; + prefix "fo"; + + revision "2015-09-09" { + reference "NO REF"; + } + + container root-fnt { + config false; + choice choice-fnt { + case case-fnt { + container c-fnt { + config true; + } + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/choice/foo.yang b/yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/choice/foo.yang new file mode 100644 index 0000000000..febd3adc1f --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/case-test/case-test-exceptions/choice/foo.yang @@ -0,0 +1,20 @@ +module foo { + yang-version 1; + namespace "foo"; + prefix "fo"; + + revision "2015-09-09" { + reference "NO REF"; + } + + container root-ftn { + config false; + choice choice-ftn { + config true; + case case-ftn { + container c-ftn { + } + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/case-test/foo.yang b/yang/yang-parser-impl/src/test/resources/case-test/foo.yang new file mode 100644 index 0000000000..269fee7986 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/case-test/foo.yang @@ -0,0 +1,206 @@ +module foo { + yang-version 1; + namespace "foo"; + prefix "fo"; + + import bar { prefix br; } + + revision "2015-09-09" { + reference "NO REF"; + } + + container root-fff { + config false; + choice choice-fff { + config false; + case case-fff { + container c-fff { + config false; + } + } + } + } + + container root-ffn { + config false; + choice choice-ffn { + config false; + case case-ffn { + container c-ffn { + } + } + } + } + + container root-fnf { + config false; + choice choice-fnf { + case case-fnf { + container c-fnf { + config false; + } + } + } + } + + container root-nff { + choice choice-nff { + config false; + case case-nff { + container c-nff { + config false; + } + } + } + } + + container root-nnf { + choice choice-nnf { + case case-nnf { + container c-nnf { + config false; + } + } + } + } + + container root-nfn { + choice choice-nfn { + config false; + case case-nfn { + container c-nfn { + } + } + } + } + + container root-fnn { + config false; + choice choice-fnn { + case case-fnn { + container c-fnn { + } + } + } + } + + container root-ttt { + config true; + choice choice-ttt { + config true; + case case-ttt { + container c-ttt { + config true; + } + } + } + } + + container root-ntt { + choice choice-ntt { + config true; + case case-ntt { + container c-ntt { + config true; + } + } + } + } + + container root-tnt { + config true; + choice choice-tnt { + case case-tnt { + container c-tnt { + config true; + } + } + } + } + + container root-ttn { + config true; + choice choice-ttt { + config true; + case case-ttt { + container c-ttt { + } + } + } + } + + container root-tnn { + config true; + choice choice-tnn { + case case-tnn { + container c-tnn { + } + } + } + } + + container root-ntn { + choice choice-ntn { + config true; + case case-ntn { + container c-ntn { + } + } + } + } + + container root-nnt { + choice choice-nnt { + case case-nnt { + container c-nnt { + config true; + } + } + } + } + + container root-tff { + config true; + choice choice-tff { + config false; + case case-tff { + container c-tff { + config false; + } + } + } + } + + container root-tfn { + config true; + choice choice-tfn { + config false; + case case-tfn { + container c-tfn { + } + } + } + } + + container root-tnf { + config true; + choice choice-tnf { + case case-tnf { + container c-tnf { + config false; + } + } + } + } + + container root-ntf { + choice choice-ntf { + config true; + case case-ntf { + container c-ntf { + config false; + } + } + } + } +} \ No newline at end of file -- 2.36.6