Provide codec Serializer via RibSupport
[bgpcep.git] / bgp / flowspec / src / test / java / org / opendaylight / protocol / bgp / flowspec / FlowspecIpv4RIBSupportTest.java
index 41d3afd9f9e87193a4f3fe68d1d483b0acd5d609..8b162cb72dcecb723ac436d83cc44ae451ba8394 100644 (file)
@@ -50,70 +50,74 @@ import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
 
-public class FlowspecIpv4RIBSupportTest extends AbstractRIBSupportTest {
+public class FlowspecIpv4RIBSupportTest extends AbstractRIBSupportTest<FlowspecRoute> {
 
-    private static final FlowspecIpv4RIBSupport RIB_SUPPORT;
-    private static final FlowspecRoute ROUTE;
-    private static final FlowspecRoutes ROUTES;
-    private static final FlowspecRouteKey ROUTE_KEY;
+    private FlowspecIpv4RIBSupport ribSupport;
+    private FlowspecRoute route;
+    private FlowspecRoutes routes;
+    private FlowspecRouteKey routeKey;
     private static final PathId PATH_ID = new PathId(1L);
 
-    private static final DestinationPrefixCase DEST_PREFIX = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
-    private static final List<Flowspec> FLOW_LIST = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build());
-    private static final DestinationFlowspec DEST_FLOW = new DestinationFlowspecBuilder().setFlowspec(FLOW_LIST).setPathId(PATH_ID).build();
-    private static final DestinationFlowspecCase REACH_NLRI = new DestinationFlowspecCaseBuilder().setDestinationFlowspec(DEST_FLOW).build();
+    private static final DestinationPrefixCase DEST_PREFIX = new DestinationPrefixCaseBuilder()
+            .setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
+    private static final List<Flowspec> FLOW_LIST
+            = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build());
+    private static final DestinationFlowspec DEST_FLOW = new DestinationFlowspecBuilder()
+            .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build();
+    private static final DestinationFlowspecCase REACH_NLRI 
+            = new DestinationFlowspecCaseBuilder().setDestinationFlowspec(DEST_FLOW).build();
     private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update
-        .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update
-        .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder().setDestinationFlowspec(DEST_FLOW).build();
+        .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase UNREACH_NLRI
+            = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update
+        .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder()
+            .setDestinationFlowspec(DEST_FLOW).build();
 
-    static {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
         final FlowspecActivator activator = new FlowspecActivator(fsContext);
         final BGPActivator act = new BGPActivator(activator);
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         act.start(context);
-        RIB_SUPPORT = FlowspecIpv4RIBSupport.getInstance(fsContext);
+        this.ribSupport = FlowspecIpv4RIBSupport.getInstance(fsContext, this.mappingService);
 
         final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-            fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
-
-        ROUTE_KEY = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST));
-        ROUTE = new FlowspecRouteBuilder().setKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
-            .setAttributes(new AttributesBuilder().build()).build();
-        ROUTES = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.singletonList(ROUTE)).build();
-    }
+                fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, 
+                        SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
 
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        setUpTestCustomizer(RIB_SUPPORT);
+        this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST));
+        this.route = new FlowspecRouteBuilder().setKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
+                .setAttributes(new AttributesBuilder().build()).build();
+        this.routes = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.singletonList(this.route)).build();
+        setUpTestCustomizer(this.ribSupport);
     }
 
     @Test
     public void testDeleteRoutes() {
-        RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
-        final InstanceIdentifier<FlowspecRoute> instanceIdentifier = (InstanceIdentifier<FlowspecRoute>) this.deletedRoutes.get(0);
-        assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecRoute.class));
+        this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
+        final InstanceIdentifier<FlowspecRoute> instanceIdentifier = this.deletedRoutes.get(0);
+        assertEquals(this.routeKey, instanceIdentifier.firstKeyOf(FlowspecRoute.class));
     }
 
     @Test
     public void testPutRoutes() {
-        RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
+        this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
         final FlowspecRoute route = (FlowspecRoute) this.insertedRoutes.get(0).getValue();
-        assertEquals(ROUTE, route);
+        assertEquals(this.route, route);
     }
 
     @Test
-    public void testEmptyRoute() throws Exception {
+    public void testEmptyRoute() {
         final Routes empty = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(
             new FlowspecRoutesBuilder().setFlowspecRoute(Collections.emptyList()).build()).build();
-        final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes();
+        final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes();
         assertEquals(createRoutes(empty), emptyRoutes);
     }
 
     @Test
     public void testBuildMpUnreachNlriUpdate() {
-        final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES);
+        final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(routes), ATTRIBUTES);
         assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class)
             .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
         assertNull(update.getAttributes().getAugmentation(Attributes1.class));
@@ -121,68 +125,73 @@ public class FlowspecIpv4RIBSupportTest extends AbstractRIBSupportTest {
 
     @Test
     public void testBuildMpReachNlriUpdate() {
-        final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES);
-        assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType());
+        final Update update = this.ribSupport.buildUpdate(createRoutes(routes), Collections.emptyList(), ATTRIBUTES);
+        assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri()
+                .getAdvertizedRoutes().getDestinationType());
         assertNull(update.getAttributes().getAugmentation(Attributes2.class));
     }
 
     @Test
     public void testCacheableNlriObjects() {
-        Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects());
+        assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
     }
 
     @Test
     public void testCacheableAttributeObjects() {
-        Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects());
+        assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
     }
 
     @Test
     public void testRouteIdAddPath() {
-        Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey()));
+        assertEquals(this.routeKey, this.ribSupport.createRouteListKey(1L, this.routeKey.getRouteKey()));
     }
 
     @Test
     public void testRoutePath() {
-        final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES);
-        Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii));
+        final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(this.routes);
+        assertEquals(getRoutePath().node(prefixNii),
+                this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii));
     }
 
     @Test
     public void testRouteAttributesIdentifier() {
-        Assert.assertEquals(new NodeIdentifier(QName.create(FlowspecRoutes.QNAME,
-            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())),
-            RIB_SUPPORT.routeAttributesIdentifier());
+        assertEquals(new NodeIdentifier(QName.create(FlowspecRoutes.QNAME,
+            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables
+                    .Attributes.QNAME.getLocalName().intern())),
+            this.ribSupport.routeAttributesIdentifier());
     }
 
     @Test
     public void testRoutesCaseClass() {
-        Assert.assertEquals(FlowspecRoutesCase.class, RIB_SUPPORT.routesCaseClass());
+        assertEquals(FlowspecRoutesCase.class, this.ribSupport.routesCaseClass());
     }
 
     @Test
     public void testRoutesContainerClass() {
-        Assert.assertEquals(FlowspecRoutes.class, RIB_SUPPORT.routesContainerClass());
+        assertEquals(FlowspecRoutes.class, this.ribSupport.routesContainerClass());
     }
 
     @Test
     public void testRoutesListClass() {
-        Assert.assertEquals(FlowspecRoute.class, RIB_SUPPORT.routesListClass());
+        assertEquals(FlowspecRoute.class, this.ribSupport.routesListClass());
     }
 
     @Test
     public void testChangedRoutes() {
         final Routes emptyCase = new FlowspecRoutesCaseBuilder().build();
-        DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
-        Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
+        DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), 
+                createRoutes(emptyCase)).getRootNode();
+        Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
 
-        final Routes emptyRoutes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().build()).build();
+        final Routes emptyRoutes 
+                = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().build()).build();
         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
-        Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
+        Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
 
         final Routes routes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder()
-            .setFlowspecRoute(Collections.singletonList(ROUTE)).build()).build();
+            .setFlowspecRoute(Collections.singletonList(this.route)).build()).build();
         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
-        final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
+        final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
         Assert.assertFalse(result.isEmpty());
     }
 }
\ No newline at end of file