YangStmtMapping.UNITS, YangStmtMapping.CONFIG, YangStmtMapping.MANDATORY,
YangStmtMapping.MIN_ELEMENTS, YangStmtMapping.MAX_ELEMENTS);
+ private static final Set<YangStmtMapping> IMPLICIT_STATEMENTS = ImmutableSet.of(YangStmtMapping.CONFIG,
+ YangStmtMapping.MANDATORY, YangStmtMapping.MAX_ELEMENTS, YangStmtMapping.MIN_ELEMENTS);
+
public Definition() {
super(YangStmtMapping.DEVIATE);
}
}
}
+ // This is a special case when deviate replace of a config/mandatory/max/min-elements substatement targets
+ // a node which does not contain an explicitly declared config/mandatory/max/min-elements.
+ // However, according to RFC6020/RFC7950, these properties are always implicitly present.
+ if (IMPLICIT_STATEMENTS.contains(stmtToBeReplaced)) {
+ addStatement(stmtCtxToBeReplaced, targetCtx);
+ return;
+ }
+
throw new InferenceException(stmtCtxToBeReplaced.getStatementSourceReference(), "Deviation cannot " +
"replace substatement %s in target node %s because it does not exist in target node.",
stmtToBeReplaced.getStatementName(), targetCtx.getStatementArgument());
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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;
+
+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.Date;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class Bug9244Test {
+
+ @Test
+ public void testDeviateReplaceOfImplicitSubstatements() throws Exception {
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9244/");
+ assertNotNull(schemaContext);
+
+ final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2017-10-13");
+
+ final Module barModule = schemaContext.findModuleByName("bar", revision);
+ assertNotNull(barModule);
+
+ final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName(
+ QName.create(barModule.getQNameModule(), "bar-cont"));
+ assertNotNull(barCont);
+ assertFalse(barCont.isConfiguration());
+
+ final LeafListSchemaNode barLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
+ QName.create(barModule.getQNameModule(), "bar-leaf-list"));
+ assertNotNull(barLeafList);
+ assertEquals(5, barLeafList.getConstraints().getMinElements().intValue());
+ assertEquals(10, barLeafList.getConstraints().getMaxElements().intValue());
+
+ final LeafSchemaNode barLeaf = (LeafSchemaNode) barModule.getDataChildByName(
+ QName.create(barModule.getQNameModule(), "bar-leaf"));
+ assertNotNull(barLeaf);
+ assertTrue(barLeaf.getConstraints().isMandatory());
+ }
+}