import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
private static final QName BAZ = QName.create(FOO, "baz");
private static final QName XYZZY_LEAF = QName.create(FOO, "xyzzy-leaf");
private static final QName XYZZY_AUGMENT = QName.create(FOO, "xyzzy-augment");
+ private static final QName XYZZY_AUGMENT_CONT = QName.create(FOO, "xyzzy-augment-container");
+ private static final QName XYZZY_AUGMENT_CONT_INNER = QName.create(FOO, "xyzzy-augment-container-inner");
+ private static final QName XYZZY_AUGMENT_CONT_LEAF = QName.create(FOO, "xyzzy-augment-container-leaf");
+ private static final QName BAZ_AUG_CASE_MANDAT_LEAF = QName.create(FOO, "augmented-case-mandatory");
+ private static final QName BAZ_AUG_CASE_NON_MANDAT_LEAF = QName.create(FOO, "augmented-case-non-mandatory");
+ private static final QName NESTED_BAZ_CHOICE = QName.create(FOO, "nested-baz");
+ private static final QName NESTED_BAZ_XYZ_CASE_MANDATORY = QName.create(FOO, "nested-xyz-mandatory");
+ private static final QName NESTED_BAZ_XYZ_CASE_NON_MANDATORY = QName.create(FOO, "nested-xyz-non-mandatory");
private static EffectiveModelContext MODEL;
}
@Test
- public void testBarWithXyzzy() throws DataValidationFailedException {
+ public void testBarWithXyzzyWithSubtree() throws DataValidationFailedException {
applyOperation(mod -> {
mod.write(YangInstanceIdentifier.of(BAR), Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(BAR))
.withNodeIdentifier(new NodeIdentifier(BAZ))
.withChild(ImmutableNodes.leafNode(XYZZY_LEAF, "xyzzy"))
.withChild(Builders.augmentationBuilder()
- .withNodeIdentifier(new AugmentationIdentifier(Set.of(XYZZY_AUGMENT)))
+ .withNodeIdentifier(new AugmentationIdentifier(Set.of(XYZZY_AUGMENT, XYZZY_AUGMENT_CONT)))
.withChild(ImmutableNodes.leafNode(XYZZY_AUGMENT, "xyzzy"))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(XYZZY_AUGMENT_CONT))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(XYZZY_AUGMENT_CONT_INNER))
+ .withChild(ImmutableNodes.leafNode(XYZZY_AUGMENT_CONT_LEAF, "aug-cont-leaf"))
+ .build())
+ .build())
+ .build())
+ .build())
+ .build());
+ });
+ }
+
+ @Test
+ public void testBazWithAugmentedCaseWithMandatoryLeaf() throws DataValidationFailedException {
+ applyOperation(mod -> {
+ mod.write(YangInstanceIdentifier.of(BAR), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAR))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAZ))
+ .withChild(ImmutableNodes.leafNode(BAZ_AUG_CASE_MANDAT_LEAF, "augmentedCaseMandatory"))
+ .withChild(ImmutableNodes.leafNode(BAZ_AUG_CASE_NON_MANDAT_LEAF, "augmentedCaseNonMandatory"))
+ .build())
+ .build());
+ });
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBazWithAugmentedCaseWithoutMandatoryLeaf() throws DataValidationFailedException {
+ applyOperation(mod -> {
+ mod.write(YangInstanceIdentifier.of(BAR), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAR))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAZ))
+ .withChild(ImmutableNodes.leafNode(BAZ_AUG_CASE_NON_MANDAT_LEAF, "augmentedCaseNonMandatory"))
+ .build())
+ .build());
+ });
+ }
+
+ @Test
+ public void testWithAugmentedNestedBazWithMandatoryLeaf() throws DataValidationFailedException {
+ applyOperation(mod -> {
+ mod.write(YangInstanceIdentifier.of(BAR), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAR))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAZ))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(NESTED_BAZ_CHOICE))
+ .withChild(ImmutableNodes.leafNode(NESTED_BAZ_XYZ_CASE_MANDATORY, "nestedMandatory"))
+ .withChild(ImmutableNodes.leafNode(NESTED_BAZ_XYZ_CASE_NON_MANDATORY, "nestedNonMandatory"))
+ .build())
+ .build())
+ .build());
+ });
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWithAugmentedNestedBazWithhoutMandatoryLeaf() throws DataValidationFailedException {
+ applyOperation(mod -> {
+ mod.write(YangInstanceIdentifier.of(BAR), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAR))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(BAZ))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(NESTED_BAZ_CHOICE))
+ .withChild(ImmutableNodes.leafNode(NESTED_BAZ_XYZ_CASE_NON_MANDATORY, "nestedNonMandatory"))
.build())
.build())
.build());
.withNodeIdentifier(new NodeIdentifier(BAZ))
.withChild(ImmutableNodes.leafNode(XYZZY_LEAF, "xyzzy"))
.withChild(ImmutableNodes.leafNode(XYZZY_AUGMENT, "xyzzy"))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(NodeIdentifier.create(XYZZY_AUGMENT_CONT))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(NodeIdentifier.create(XYZZY_AUGMENT_CONT_INNER))
+ .withChild(ImmutableNodes.leafNode(XYZZY_AUGMENT_CONT_LEAF, "aug-cont-leaf"))
+ .build())
+ .build())
.build())
.build());
});
.withChild(Builders.choiceBuilder()
.withNodeIdentifier(new NodeIdentifier(BAZ))
.withChild(Builders.augmentationBuilder()
- .withNodeIdentifier(new AugmentationIdentifier(Set.of(XYZZY_AUGMENT)))
+ .withNodeIdentifier(new AugmentationIdentifier(Set.of(XYZZY_AUGMENT, XYZZY_AUGMENT_CONT)))
.withChild(ImmutableNodes.leafNode(XYZZY_AUGMENT, "xyzzy"))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(NodeIdentifier.create(XYZZY_AUGMENT_CONT))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(NodeIdentifier.create(XYZZY_AUGMENT_CONT_INNER))
+ .withChild(ImmutableNodes.leafNode(XYZZY_AUGMENT_CONT_LEAF, "aug-cont-leaf"))
+ .build())
+ .build())
.build())
.build())
.build());
.build())
.build());
});
- assertEquals("Node (foo)baz is missing mandatory descendant "
- + "/AugmentationIdentifier{childNames=[(foo)xyzzy-augment]}/(foo)xyzzy-augment",
- ex.getMessage());
+ assertEquals("Node (foo)baz is missing mandatory descendant /AugmentationIdentifier{childNames="
+ + "[(foo)xyzzy-augment, (foo)xyzzy-augment-container]}/(foo)xyzzy-augment", ex.getMessage());
}