fix: virtual packet provider test

Change-Id: I03d7ac079a99be5c193f757c2d024f5e97c3a18d
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProvider.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProvider.java
index e2aa5bd..2187be4 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProvider.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProvider.java
@@ -35,6 +35,7 @@
 import org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider;
 import org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider;
 import org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService;
+import org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -71,9 +72,6 @@
     private final Logger log = getLogger(getClass());
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected VirtualPacketProviderService virtualPacketProviderService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected PacketService packetService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -85,6 +83,8 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected VirtualNetworkAdminService virtualNetworkAdminService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected VirtualProviderRegistryService providerRegistryService;
 
     ApplicationId appId;
     InternalPacketProcessor processor;
@@ -104,6 +104,7 @@
     public void activate() {
         appId = coreService.registerApplication(
                 "org.onosproject.provider.virtual-packet-provider");
+        providerRegistryService.registerProvider(this);
 
         processor = new InternalPacketProcessor();
         packetService.addProcessor(processor, PACKET_PROCESSOR_PRIORITY);
@@ -263,9 +264,14 @@
         @Override
         public void process(PacketContext context) {
             Set<VirtualPacketContext> vContexts = virtualize(context);
-            vContexts.forEach(vpc -> virtualPacketProviderService
-                                              .processPacket(vpc.getNetworkId(),
-                                                             vpc));
+
+            vContexts.forEach(vpc -> {
+                                  VirtualPacketProviderService service =
+                                          (VirtualPacketProviderService) providerRegistryService
+                                                  .getProviderService(vpc.getNetworkId(),
+                                                                      VirtualPacketProvider.class);
+                                  service.processPacket(vpc);
+                              });
         }
     }
 }
diff --git a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProviderTest.java b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProviderTest.java
index af4f760..6d6d7c7 100644
--- a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProviderTest.java
+++ b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/provider/DefaultVirtualPacketProviderTest.java
@@ -39,6 +39,7 @@
 import org.onosproject.incubator.net.virtual.VirtualNetwork;
 import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
 import org.onosproject.incubator.net.virtual.VirtualPort;
+import org.onosproject.incubator.net.virtual.provider.AbstractVirtualProviderService;
 import org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider;
 import org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService;
 import org.onosproject.net.ConnectPoint;
@@ -129,7 +130,9 @@
 
     protected DefaultVirtualPacketProvider virtualProvider;
     protected TestPacketService testPacketService;
-    protected TestVirtualPacketProivderService providerService;
+    protected TestVirtualPacketProviderService providerService;
+
+    private VirtualProviderManager providerManager;
 
     private ApplicationId vAppId;
 
@@ -141,12 +144,15 @@
         virtualProvider.virtualNetworkAdminService =
                 new TestVirtualNetworkAdminService();
 
-        providerService = new TestVirtualPacketProivderService();
-        virtualProvider.virtualPacketProviderService = providerService;
+        providerService = new TestVirtualPacketProviderService();
 
         testPacketService = new TestPacketService();
         virtualProvider.packetService = testPacketService;
 
+        providerManager = new VirtualProviderManager();
+        virtualProvider.providerRegistryService = providerManager;
+        providerManager.registerProviderService(VNET_ID, providerService);
+
         virtualProvider.activate();
         vAppId = new TestApplicationId(0, "Virtual App");
     }
@@ -212,9 +218,6 @@
 
         testPacketService.sendTestPacketContext(pContext);
 
-        assertEquals("The virtual network Id should be 1", VNET_ID,
-                     providerService.getRequestedNetworkId(0));
-
         PacketContext vContext = providerService.getRequestedPacketContext(0);
         InboundPacket vInPacket = vContext.inPacket();
 
@@ -292,6 +295,11 @@
         }
 
         @Override
+        public ApplicationId getVirtualNetworkApplicationId(NetworkId networkId) {
+            return null;
+        }
+
+        @Override
         public void registerTenantId(TenantId tenantId) {
 
         }
@@ -375,7 +383,8 @@
         }
     }
 
-    private static class TestVirtualPacketProivderService
+    private static class TestVirtualPacketProviderService
+            extends AbstractVirtualProviderService<VirtualPacketProvider>
             implements VirtualPacketProviderService {
         static List<PacketContext> requestedContext = new LinkedList();
         static List<NetworkId> requestedNetworkId = new LinkedList();
@@ -385,18 +394,17 @@
             return null;
         }
 
-        @Override
-        public void processPacket(NetworkId networkId, PacketContext context) {
-            requestedNetworkId.add(networkId);
-            requestedContext.add(context);
-        }
-
         public NetworkId getRequestedNetworkId(int index) {
-            return requestedNetworkId.get(0);
+            return requestedNetworkId.get(index);
         }
 
         public PacketContext getRequestedPacketContext(int index) {
-            return requestedContext.get(0);
+            return requestedContext.get(index);
+        }
+
+        @Override
+        public void processPacket(PacketContext context) {
+            requestedContext.add(context);
         }
     }