use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class DataTreeCandidateInputOutputTest method assertSerialization.
private static void assertSerialization(final DataTreeCandidate orig) throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final DataOutput dos = new DataOutputStream(bos);
try (NormalizedNodeDataOutput out = NormalizedNodeStreamVersion.current().newDataOutput(dos)) {
DataTreeCandidateInputOutput.writeDataTreeCandidate(out, orig);
}
final DataTreeCandidate read = DataTreeCandidateInputOutput.readDataTreeCandidate(NormalizedNodeDataInput.newDataInput(new DataInputStream(new ByteArrayInputStream(bos.toByteArray()))));
assertEquals(orig.getRootPath(), read.getRootPath());
assertEqualMod(orig.getRootNode(), read.getRootNode());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug3674Test method testDeleteOfNonExistingNode.
@Test
public void testDeleteOfNonExistingNode() throws DataValidationFailedException {
final DataTreeModification mod = tree.takeSnapshot().newModification();
mod.delete(TestModel.OUTER_LIST_PATH);
mod.ready();
final DataTreeCandidate candidate = tree.prepare(mod);
final DataTreeCandidateNode root = candidate.getRootNode();
assertEquals(ModificationType.UNMODIFIED, root.getModificationType());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug4454Test method minMaxListDeleteTest.
@Test
public void minMaxListDeleteTest() throws DataValidationFailedException {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo");
final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz");
final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
modificationTree.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBar);
modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
modificationTree.delete(minMaxLeafFoo);
modificationTree.delete(minMaxLeafBar);
modificationTree.delete(minMaxLeafBaz);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
// Empty list should have disappeared, along with the container, as we are not enforcing root
final NormalizedNode data = inMemoryDataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()).get();
assertTrue(data instanceof ContainerNode);
assertEquals(0, ((ContainerNode) data).size());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug4454Test method minMaxLeafListPass.
@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare1);
DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
DataTreeModification tempMod1 = test1.newModification();
tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
tempMod1.ready();
inMemoryDataTree.validate(tempMod1);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
inMemoryDataTree.commit(prepare2);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.get()).findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
assertEquals(3, leafList.get().size());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug4454Test method minMaxListDeleteWriteTest.
@Test
public void minMaxListDeleteWriteTest() throws DataValidationFailedException {
final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
Map<QName, Object> key = new HashMap<>();
key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, key);
final YangInstanceIdentifier minMaxLeafFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
key.clear();
key.put(MIN_MAX_KEY_LEAF_QNAME, "NON-EXISTING-LEAF");
mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, key);
final YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
final Map<QName, Object> keyTemp = new HashMap<>();
keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
NodeIdentifierWithPredicates mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, keyTemp);
final YangInstanceIdentifier pathToBaz = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
keyTemp.clear();
keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, keyTemp);
final YangInstanceIdentifier pathToBar = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
keyTemp.clear();
keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
final NodeIdentifierWithPredicates mapEntryPathTestKey = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, keyTemp);
final YangInstanceIdentifier pathToKeyFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPathTestKey).node(MIN_MAX_KEY_LEAF_QNAME).build();
final LeafNode<String> newNode = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test");
final LeafNode<String> newNode1 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test1");
final LeafNode<String> newNode2 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test2");
final LeafNode<String> newNodekey = ImmutableNodes.leafNode(MIN_MAX_KEY_LEAF_QNAME, "foo");
assertFalse(inMemoryDataTree.toString().contains("list"));
DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(!minMaxListRead.isPresent());
modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBar);
modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
modificationTree1.write(pathToKeyFoo, newNodekey);
modificationTree1.write(pathToBaz, newNode2);
modificationTree1.write(pathToBaz, newNode1);
modificationTree1.write(pathToBaz, newNode);
modificationTree1.delete(minMaxLeafFoo);
modificationTree1.delete(minMaxLeafNel);
modificationTree1.ready();
inMemoryDataTree.validate(modificationTree1);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree1);
inMemoryDataTree.commit(prepare);
DataTreeSnapshot test = inMemoryDataTree.takeSnapshot();
testLoop(test, "bar", "test");
DataTreeModification tempMod = test.newModification();
tempMod.write(pathToBaz, newNode2);
tempMod.write(pathToBaz, newNode1);
tempMod.merge(pathToBaz, newNode2);
tempMod.write(pathToBaz, newNode1);
tempMod.ready();
inMemoryDataTree.validate(tempMod);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(tempMod);
inMemoryDataTree.commit(prepare1);
DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
testLoop(test1, "bar", "test1");
DataTreeModification tempMod1 = test1.newModification();
tempMod1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
tempMod1.ready();
inMemoryDataTree.validate(tempMod1);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
inMemoryDataTree.commit(prepare2);
DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
assertEquals(3, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
DataTreeModification tempMod2 = test2.newModification();
tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
tempMod2.write(pathToBaz, newNode2);
tempMod2.ready();
inMemoryDataTree.validate(tempMod2);
final DataTreeCandidate prepare3 = inMemoryDataTree.prepare(tempMod2);
inMemoryDataTree.commit(prepare3);
DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
assertEquals(1, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
assertThat(minMaxListRead.get().body().toString(), containsString("test2"));
DataTreeModification tempMod3 = test3.newModification();
tempMod3.merge(MIN_MAX_LIST_PATH, mapNodeBar);
tempMod3.merge(pathToBar, newNode1);
tempMod3.ready();
inMemoryDataTree.validate(tempMod3);
final DataTreeCandidate prepare4 = inMemoryDataTree.prepare(tempMod3);
inMemoryDataTree.commit(prepare4);
DataTreeSnapshot test4 = inMemoryDataTree.takeSnapshot();
testLoop(test4, "test1", "test2");
}
Aggregations