use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class NormalizedNodeAggregatorTest method getRootNode.
public static NormalizedNode<?, ?> getRootNode(NormalizedNode<?, ?> moduleNode, SchemaContext schemaContext) throws ReadFailedException, ExecutionException, InterruptedException {
try (InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", Executors.newSingleThreadExecutor())) {
store.onGlobalContextUpdated(schemaContext);
DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction();
writeTransaction.merge(YangInstanceIdentifier.of(moduleNode.getNodeType()), moduleNode);
DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready();
ready.canCommit().get();
ready.preCommit().get();
ready.commit().get();
DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction();
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = readTransaction.read(YangInstanceIdentifier.EMPTY);
Optional<NormalizedNode<?, ?>> nodeOptional = read.checkedGet();
return nodeOptional.get();
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DeleteModificationTest method testApply.
@Test
public void testApply() throws Exception {
// Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
// Check if it's in the datastore
Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
Assert.assertTrue(data.isPresent());
// Delete stuff from the datastore
DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
DeleteModification deleteModification = new DeleteModification(TestModel.TEST_PATH);
deleteModification.apply(deleteTransaction);
commitTransaction(deleteTransaction);
data = readData(TestModel.TEST_PATH);
Assert.assertFalse(data.isPresent());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class MergeModificationTest method testApply.
@Test
public void testApply() throws Exception {
// TODO : Need to write a better test for this
// Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
MergeModification writeModification = new MergeModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
// Check if it's in the datastore
Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
Assert.assertTrue(data.isPresent());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class MutableCompositeModificationTest method testApply.
@Test
public void testApply() throws Exception {
MutableCompositeModification compositeModification = new MutableCompositeModification();
compositeModification.addModification(new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)));
DOMStoreReadWriteTransaction transaction = store.newReadWriteTransaction();
compositeModification.apply(transaction);
commitTransaction(transaction);
Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
assertNotNull(data.get());
assertEquals(TestModel.TEST_QNAME, data.get().getNodeType());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ShardDataTreeSnapshotTest method testShardDataTreeSnapshotWithNoMetadata.
@Test
public void testShardDataTreeSnapshotWithNoMetadata() throws Exception {
NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
snapshot.serialize(out);
}
ShardDataTreeSnapshot deserialized;
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
deserialized = ShardDataTreeSnapshot.deserialize(in);
}
Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
assertEquals("rootNode present", true, actualNode.isPresent());
assertEquals("rootNode", expectedNode, actualNode.get());
assertEquals("Deserialized type", MetadataShardDataTreeSnapshot.class, deserialized.getClass());
assertEquals("Metadata size", 0, ((MetadataShardDataTreeSnapshot) deserialized).getMetadata().size());
}
Aggregations