use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project bgpcep by opendaylight.
the class LabeledUnicastIpv6RIBSupportTest method testChangedRoutes.
@Test
public void testChangedRoutes() {
final Routes emptyCase = new LabeledUnicastIpv6RoutesCaseBuilder().build();
DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
final Routes emptyRoutes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build();
tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
final Routes routes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(ROUTES).build();
tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
Assert.assertFalse(result.isEmpty());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project bgpcep by opendaylight.
the class AbstractRIBSupport method changedRoutes.
@Override
public final Collection<DataTreeCandidateNode> changedRoutes(final DataTreeCandidateNode routes) {
final DataTreeCandidateNode myRoutes = routes.getModifiedChild(this.routesContainerIdentifier);
if (myRoutes == null) {
return Collections.emptySet();
}
final DataTreeCandidateNode routesMap = myRoutes.getModifiedChild(routeNid());
if (routesMap == null) {
return Collections.emptySet();
}
// to make sure the type matches what routeType() reports.
return routesMap.getChildNodes();
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project bgpcep by opendaylight.
the class LinkstateRIBSupportTest method testChangedRoutes.
@Test
public void testChangedRoutes() {
final Routes emptyCase = new LinkstateRoutesCaseBuilder().build();
DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
final Routes emptyRoutes = new LinkstateRoutesCaseBuilder().setLinkstateRoutes(new LinkstateRoutesBuilder().build()).build();
tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
final Routes routes = new LinkstateRoutesCaseBuilder().setLinkstateRoutes(ROUTES).build();
tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
Assert.assertFalse(result.isEmpty());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project bgpcep by opendaylight.
the class MultiPathAbstractRIBSupportTest method setUp.
@Before
public void setUp() {
this.routesMap = new HashMap<>();
MockitoAnnotations.initMocks(this);
this.emptyTree = Mockito.mock(DataTreeCandidateNode.class);
this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class);
this.subTree = Mockito.mock(DataTreeCandidateNode.class);
final DataTreeCandidateNode emptyNode = Mockito.mock(DataTreeCandidateNode.class);
final DataTreeCandidateNode node = Mockito.mock(DataTreeCandidateNode.class);
doReturn(null).when(this.emptyTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
doReturn(emptyNode).when(this.emptySubTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
doReturn(null).when(emptyNode).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
doReturn(node).when(this.subTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
doReturn(node).when(node).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
final Collection<DataTreeCandidateNode> emptyCollection = new HashSet<>();
doReturn(emptyCollection).when(node).getChildNodes();
this.tx = Mockito.mock(DOMDataWriteTransaction.class);
this.nlri = Mockito.mock(ContainerNode.class);
this.attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern()))).build();
final ContainerNode destination = Mockito.mock(ContainerNode.class);
final ChoiceNode destinations = Mockito.mock(ChoiceNode.class);
final ContainerNode route = Mockito.mock(ContainerNode.class);
final Optional<?> optional = Optional.of(destination);
final Optional<?> destinationOptional = Optional.of(destinations);
final Optional<?> destinationsOptional = Optional.of(route);
doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(WithdrawnRoutes.QNAME));
doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(AdvertizedRoutes.QNAME));
doReturn(destinationOptional).when(destination).getChild(new NodeIdentifier(DestinationType.QNAME));
doReturn(destinationsOptional).when(destinations).getChild(new NodeIdentifier(Ipv4Prefixes.QNAME));
doReturn(emptyCollection).when(route).getValue();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
MultiPathAbstractRIBSupportTest.this.routesMap.remove(args[1]);
return args[1];
}).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
final NormalizedNode<?, ?> node1 = (NormalizedNode<?, ?>) args[2];
MultiPathAbstractRIBSupportTest.this.routesMap.put((YangInstanceIdentifier) args[1], node1);
return args[1];
}).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
this.mapEntryNode = Mockito.mock(MapEntryNode.class);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class LazyDataObjectModification method getModifiedChild.
@Override
public DataObjectModification<? extends DataObject> getModifiedChild(final PathArgument arg) {
final List<YangInstanceIdentifier.PathArgument> domArgumentList = new ArrayList<>();
final BindingCodecTreeNode<?> childCodec = codec.bindingPathArgumentChild(arg, domArgumentList);
final Iterator<YangInstanceIdentifier.PathArgument> toEnter = domArgumentList.iterator();
DataTreeCandidateNode current = domData;
while (toEnter.hasNext() && current != null) {
current = current.getModifiedChild(toEnter.next());
}
if (current != null) {
return create(childCodec, current);
}
return null;
}
Aggregations