import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
public class Bug2690Test extends AbstractTestModelTest {
- private static final YangInstanceIdentifier NAME_PATH = YangInstanceIdentifier.of(TestModel.NON_PRESENCE_QNAME)
- .node(TestModel.NAME_QNAME);
-
private DataTree inMemoryDataTree;
@Before
private DataTreeModification setupTestDeleteStructuralAndWriteChild() {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
- modificationTree.delete(YangInstanceIdentifier.of(TestModel.NON_PRESENCE_QNAME));
- modificationTree.write(NAME_PATH, Builders.leafBuilder()
- .withNodeIdentifier(new NodeIdentifier(TestModel.NAME_QNAME)).withValue("abc").build());
+ modificationTree.delete(TestModel.NON_PRESENCE_PATH);
+ modificationTree.write(TestModel.NAME_PATH, ImmutableNodes.leafNode(TestModel.NAME_QNAME, "abc"));
return modificationTree;
}
private static void verifyTestDeleteStructuralAndWriteChild(final DataTreeSnapshot snapshot) {
- final Optional<NormalizedNode<?, ?>> readNode = snapshot.readNode(NAME_PATH);
+ final Optional<NormalizedNode<?, ?>> readNode = snapshot.readNode(TestModel.NAME_PATH);
assertTrue(readNode.isPresent());
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
+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.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
.withValue("testing-value")
.build();
- final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) innerDataTree.takeSnapshot()
- .newModification();
+ final DataTreeModification modification = innerDataTree.takeSnapshot().newModification();
modification.write(TestModel.VALUE_PATH, leaf);
modification.ready();
final LeafNode<?> readLeaf = (LeafNode<?>) newModification.readNode(TestModel.INNER_VALUE_PATH).get();
assertEquals(readLeaf, leaf);
}
+
+ @Test
+ public void testEmptyMergeOnContainer() throws DataValidationFailedException {
+ DataTreeModification modification = dataTree.takeSnapshot().newModification();
+ modification.merge(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
+ modification.ready();
+ dataTree.validate(modification);
+
+ // The entire transaction needs to fizzle to a no-op
+ DataTreeCandidate candidate = dataTree.prepare(modification);
+ DataTreeCandidateNode node = candidate.getRootNode();
+ assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+
+ // 'test'
+ assertUnmodified(1, node.getChildNodes());
+ }
+
+ @Test
+ public void testEmptyWriteOnContainer() throws DataValidationFailedException {
+ DataTreeModification modification = dataTree.takeSnapshot().newModification();
+ modification.write(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
+ modification.ready();
+ dataTree.validate(modification);
+
+ // The entire transaction needs to fizzle to a no-op
+ DataTreeCandidate candidate = dataTree.prepare(modification);
+ DataTreeCandidateNode node = candidate.getRootNode();
+ assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+
+ // 'test'
+ assertUnmodified(1, node.getChildNodes());
+ }
+
+ @Test
+ public void testEmptyMergesOnDeleted() throws DataValidationFailedException {
+ DataTreeModification modification = dataTree.takeSnapshot().newModification();
+ modification.delete(TestModel.NON_PRESENCE_PATH);
+ modification.merge(TestModel.DEEP_CHOICE_PATH, ImmutableNodes.choiceNode(TestModel.DEEP_CHOICE_QNAME));
+ modification.ready();
+ dataTree.validate(modification);
+
+ final DataTreeCandidate candidate = dataTree.prepare(modification);
+ assertEquals(YangInstanceIdentifier.EMPTY, candidate.getRootPath());
+ final DataTreeCandidateNode node = candidate.getRootNode();
+ assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+
+ // 'test'
+ assertUnmodified(1, node.getChildNodes());
+ }
+
+ @Test
+ public void testEmptyMergesOnExisting() throws DataValidationFailedException {
+ // Make sure 'non-presence' is present
+ DataTreeModification modification = dataTree.takeSnapshot().newModification();
+ modification.write(TestModel.NAME_PATH, ImmutableNodes.leafNode(TestModel.NAME_QNAME, "foo"));
+ modification.ready();
+ dataTree.validate(modification);
+ dataTree.commit(dataTree.prepare(modification));
+
+ // Issue an empty merge on it and a child choice
+ modification = dataTree.takeSnapshot().newModification();
+ modification.merge(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
+ modification.merge(TestModel.DEEP_CHOICE_PATH, ImmutableNodes.choiceNode(TestModel.DEEP_CHOICE_QNAME));
+ modification.ready();
+ dataTree.validate(modification);
+
+ // The entire transaction needs to fizzle to a no-op
+ final DataTreeCandidate candidate = dataTree.prepare(modification);
+ assertEquals(YangInstanceIdentifier.EMPTY, candidate.getRootPath());
+ final DataTreeCandidateNode node = candidate.getRootNode();
+ assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+
+ // 'non-presence' and 'test'
+ assertUnmodified(2, node.getChildNodes());
+ }
+
+ private static void assertUnmodified(final int expSize, final Collection<DataTreeCandidateNode> nodes) {
+ assertEquals(expSize, nodes.size());
+ nodes.forEach(node -> assertEquals(ModificationType.UNMODIFIED, node.getModificationType()));
+ }
}
public void testNestedStrucutralNodes() throws DataValidationFailedException {
final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();
- final YangInstanceIdentifier path = YangInstanceIdentifier.create(
- getNId(TestModel.NON_PRESENCE_QNAME),
- getNId(TestModel.DEEP_CHOICE_QNAME),
- getNId(TestModel.A_LIST_QNAME),
- getNId(TestModel.A_LIST_QNAME, TestModel.A_NAME_QNAME, "1")
- );
+ final YangInstanceIdentifier path = TestModel.DEEP_CHOICE_PATH.node(TestModel.A_LIST_QNAME)
+ .node(getNId(TestModel.A_LIST_QNAME, TestModel.A_NAME_QNAME, "1"));
addListEntryModification.write(path,
Builders.mapEntryBuilder()
// Check parent structure auto created
assertNodeExistence(path, true);
- assertNodeExistence(YangInstanceIdentifier.create(getNId(TestModel.NON_PRESENCE_QNAME)), true);
- assertNodeExistence(YangInstanceIdentifier.create(
- getNId(TestModel.NON_PRESENCE_QNAME), getNId(TestModel.DEEP_CHOICE_QNAME)), true);
+ assertNodeExistence(TestModel.NON_PRESENCE_PATH, true);
+ assertNodeExistence(TestModel.DEEP_CHOICE_PATH, true);
}
private void assertNodeExistence(final YangInstanceIdentifier outerListParentPath, final boolean shouldBePresent) {