use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class AbstractDOMStoreTreeChangePublisher method lookupAndNotify.
private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate) {
if (args.size() != offset) {
final PathArgument arg = args.get(offset);
final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg);
if (exactChild != null) {
lookupAndNotify(args, offset + 1, exactChild, candidate);
}
for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) {
lookupAndNotify(args, offset + 1, c, candidate);
}
} else {
notifyNode(candidate.getRootPath(), node, candidate.getRootNode());
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class AbstractEntityOwnershipTest method getMapEntryNodeChild.
protected MapEntryNode getMapEntryNodeChild(final DataContainerNode<? extends PathArgument> parent, final QName childMap, final QName child, final Object key, final boolean expectPresent) {
Optional<DataContainerChild<? extends PathArgument, ?>> childNode = parent.getChild(new NodeIdentifier(childMap));
assertEquals("Missing " + childMap.toString(), true, childNode.isPresent());
MapNode entityTypeMapNode = (MapNode) childNode.get();
Optional<MapEntryNode> entityTypeEntry = entityTypeMapNode.getChild(new NodeIdentifierWithPredicates(childMap, child, key));
if (expectPresent && !entityTypeEntry.isPresent()) {
fail("Missing " + childMap.toString() + " entry for " + key + ". Actual: " + entityTypeMapNode.getValue());
} else if (!expectPresent && entityTypeEntry.isPresent()) {
fail("Found unexpected " + childMap.toString() + " entry for " + key);
}
return entityTypeEntry.isPresent() ? entityTypeEntry.get() : null;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class AbstractShardTest method testRecovery.
protected void testRecovery(final Set<Integer> listEntryKeys) throws Exception {
// Create the actor and wait for recovery complete.
final int nListEntries = listEntryKeys.size();
final CountDownLatch recoveryComplete = new CountDownLatch(1);
final Creator<Shard> creator = () -> new Shard(newShardBuilder()) {
@Override
protected void onRecoveryComplete() {
try {
super.onRecoveryComplete();
} finally {
recoveryComplete.countDown();
}
}
};
final TestActorRef<Shard> shard = TestActorRef.create(getSystem(), Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testRecovery");
assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS));
// Verify data in the data store.
final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable", outerList.getValue() instanceof Iterable);
for (final Object entry : (Iterable<?>) outerList.getValue()) {
assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode", entry instanceof MapEntryNode);
final MapEntryNode mapEntry = (MapEntryNode) entry;
final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf = mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
final Object value = idLeaf.get().getValue();
assertTrue("Unexpected value for leaf " + TestModel.ID_QNAME.getLocalName() + ": " + value, listEntryKeys.remove(value));
}
if (!listEntryKeys.isEmpty()) {
fail("Missing " + TestModel.OUTER_LIST_QNAME.getLocalName() + " entries with keys: " + listEntryKeys);
}
assertEquals("Last log index", nListEntries, shard.underlyingActor().getShardMBean().getLastLogIndex());
assertEquals("Commit index", nListEntries, shard.underlyingActor().getShardMBean().getCommitIndex());
assertEquals("Last applied", nListEntries, shard.underlyingActor().getShardMBean().getLastApplied());
shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class AbstractShardTest method verifyOuterListEntry.
@SuppressWarnings("unchecked")
static void verifyOuterListEntry(final TestActorRef<Shard> shard, final Object expIDValue) throws Exception {
final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable", outerList.getValue() instanceof Iterable);
final Object entry = ((Iterable<Object>) outerList.getValue()).iterator().next();
assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode", entry instanceof MapEntryNode);
final MapEntryNode mapEntry = (MapEntryNode) entry;
final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf = mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
assertEquals(TestModel.ID_QNAME.getLocalName() + " value", expIDValue, idLeaf.get().getValue());
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class NormalizedNodeStreamReaderWriterTest method testAnyXmlStreaming.
@Test
public void testAnyXmlStreaming() throws Exception {
String xml = "<foo xmlns=\"http://www.w3.org/TR/html4/\" x=\"123\"><bar>one</bar><bar>two</bar></foo>";
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Node xmlNode = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))).getDocumentElement();
assertEquals("http://www.w3.org/TR/html4/", xmlNode.getNamespaceURI());
NormalizedNode<?, ?> anyXmlContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)).withValue(new DOMSource(xmlNode)).build()).build();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
nnout.writeNormalizedNode(anyXmlContainer);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bos.toByteArray()));
ContainerNode deserialized = (ContainerNode) nnin.readNormalizedNode();
Optional<DataContainerChild<? extends PathArgument, ?>> child = deserialized.getChild(new NodeIdentifier(TestModel.ANY_XML_QNAME));
assertEquals("AnyXml child present", true, child.isPresent());
StreamResult xmlOutput = new StreamResult(new StringWriter());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(((AnyXmlNode) child.get()).getValue(), xmlOutput);
assertEquals("XML", xml, xmlOutput.getWriter().toString());
assertEquals("http://www.w3.org/TR/html4/", ((AnyXmlNode) child.get()).getValue().getNode().getNamespaceURI());
}
Aggregations