BUG 4263: No test coverage for SfcProviderSfEntryDataListener 47/26547/9
authorReinaldo Penno <[email protected]>
Sat, 5 Sep 2015 05:28:33 +0000 (22:28 -0700)
committerReinaldo Penno <[email protected]>
Wed, 9 Sep 2015 00:28:12 +0000 (17:28 -0700)
In the process of providing coverage for SF listener I had to fix
or improve a series of minor to medium things.

- Change a couple of IIDs to private static final in Opendaylight class
- Fixed identation in SfcProviderSfEntryDataListener.java
- Removed unused method in SfcDataStoreAPI.java
- Fixed Javadocs in SfcProviderRenderedPathAPI.java
- Introduced a new API in SfcProviderServiceForwarderAPI.java
- Fixed Javadocs and Introduced new APIs in SfcProviderServiceFunctionAPI.java
- Fixed Javadocs and Introduced new APIs in SfcProviderServiceTypeAPI.java
- Fixed LOG object instantiation in AbstractSfcRendererServicePathAPITest.java
- Fixed a problem in an existing test SfcProviderRenderedPathAPITest.java

Change-Id: Ie25a92b75b06e627818950c3c851b3ece79c0451
Signed-off-by: Reinaldo Penno <[email protected]>
sfc-provider/src/main/java/org/opendaylight/sfc/provider/OpendaylightSfc.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/SfcProviderSfEntryDataListener.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcDataStoreAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderRenderedPathAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceForwarderAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceFunctionAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderServiceTypeAPI.java
sfc-provider/src/test/java/org/opendaylight/sfc/provider/SfcProviderSfEntryDataListenerTest.java [new file with mode: 0644]
sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/AbstractSfcRendererServicePathAPITest.java
sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcProviderRenderedPathAPITest.java

index 09c9595c16ace8e0cd5f6d1237be713a29f7f773..e89e60d1b3116a3fffc364f26b1e22fdb23d8f22 100755 (executable)
@@ -78,6 +78,9 @@ public class OpendaylightSfc implements AutoCloseable {
     public static final InstanceIdentifier<RenderedServicePath> RSP_ENTRY_IID = InstanceIdentifier
             .builder(RenderedServicePaths.class).child(RenderedServicePath.class).build();
 
+    public static final InstanceIdentifier<ServiceFunctionSchedulerType> SFST_ENTRY_IID = InstanceIdentifier
+            .builder(ServiceFunctionSchedulerTypes.class).child(ServiceFunctionSchedulerType.class).build();
+
     public static final InstanceIdentifier<ServiceFunctionChains> SFC_IID = InstanceIdentifier.builder(
             ServiceFunctionChains.class).build();
 
@@ -90,8 +93,11 @@ public class OpendaylightSfc implements AutoCloseable {
     public static final InstanceIdentifier<ServiceFunctionForwarders> SFF_IID = InstanceIdentifier.builder(
             ServiceFunctionForwarders.class).build();
 
-    public static final InstanceIdentifier<ServiceFunctionSchedulerType> SFST_ENTRY_IID = InstanceIdentifier
-            .builder(ServiceFunctionSchedulerTypes.class).child(ServiceFunctionSchedulerType.class).build();
+    public static final InstanceIdentifier<ServiceFunctions> SF_IID = InstanceIdentifier
+            .builder(ServiceFunctions.class).build();
+
+    public static final InstanceIdentifier<ServiceFunctionPaths> SFP_IID = InstanceIdentifier
+            .builder(ServiceFunctionPaths.class).build();
 
     public static final int EXECUTOR_THREAD_POOL_SIZE = 100;
 
@@ -150,15 +156,9 @@ public class OpendaylightSfc implements AutoCloseable {
             final InstanceIdentifier<ServiceFunctionClassifiers> SCF_IID = InstanceIdentifier.builder(
                     ServiceFunctionClassifiers.class).build();
 
-            final InstanceIdentifier<ServiceFunctions> SF_IID = InstanceIdentifier.builder(ServiceFunctions.class)
-                    .build();
-
             final InstanceIdentifier<ServiceFunctionGroups> SFG_IID = InstanceIdentifier.builder(ServiceFunctionGroups.class)
                     .build();
 
-            final InstanceIdentifier<ServiceFunctionPaths> SFP_IID = InstanceIdentifier.builder(
-                    ServiceFunctionPaths.class).build();
-
             final InstanceIdentifier<RenderedServicePaths> rspIid = InstanceIdentifier.builder(
                     RenderedServicePaths.class).build();
 
index 20d3102f043ce325c27f124da1c88e1e0b9a8225..04996d0b0723859ffe5c8e8c63f568fef0511748 100755 (executable)
@@ -63,7 +63,6 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener {
 
                 // SF ORIGINAL
                 Map<InstanceIdentifier<?>, DataObject> dataOriginalDataObject = change.getOriginalData();
-
                 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataOriginalDataObject.entrySet()) {
                     if (entry.getValue() instanceof ServiceFunction) {
                         ServiceFunction originalServiceFunction = (ServiceFunction) entry.getValue();
@@ -74,7 +73,6 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener {
 
                 // SF CREATION
                 Map<InstanceIdentifier<?>, DataObject> dataCreatedObject = change.getCreatedData();
-
                 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataCreatedObject.entrySet()) {
                     if (entry.getValue() instanceof ServiceFunction) {
                         ServiceFunction createdServiceFunction = (ServiceFunction) entry.getValue();
@@ -96,9 +94,9 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener {
                             LOG.error("Failed to delete Service Function Type for SF: {}", originalServiceFunction.getName());
                         }
 
-                /* Before removing RSPs used by this Service Function, we need to remove all
-                 * references in the SFF/SF operational trees
-                 */
+                        /* Before removing RSPs used by this Service Function, we need to remove all
+                         * references in the SFF/SF operational trees
+                         */
                         String sfName = originalServiceFunction.getName();
                         List<String> rspList = SfcProviderServiceFunctionAPI.
                                 readServiceFunctionStateAsStringListExecutor(sfName);
@@ -116,14 +114,10 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener {
                     }
                 }
 
-
                 // SF UPDATE
-                Map<InstanceIdentifier<?>, DataObject> dataUpdatedConfigurationObject
-                        = change.getUpdatedData();
+                Map<InstanceIdentifier<?>, DataObject> dataUpdatedConfigurationObject = change.getUpdatedData();
                 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dataUpdatedConfigurationObject.entrySet()) {
                     if ((entry.getValue() instanceof ServiceFunction) && (!(dataCreatedObject.containsKey(entry.getKey())))) {
-
-
                         DataObject dataObject = dataOriginalDataObject.get(entry.getKey());
                         ServiceFunction originalServiceFunction = (ServiceFunction) dataObject;
                         Object[] serviceFunctionObj = {originalServiceFunction};
@@ -152,9 +146,9 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener {
                                     .getCreateServiceFunctionTypeEntry(serviceFunctionObj, serviceFunctionClass));
                         }
 
-                /* Before removing RSPs used by this Service Function, we need to remove all
-                 * references in the SFF/SF operational trees
-                 */
+                        /* Before removing RSPs used by this Service Function, we need to remove all
+                         * references in the SFF/SF operational trees
+                         */
                         String sfName = originalServiceFunction.getName();
                         List<SfServicePath> sfServicePathList = SfcProviderServiceFunctionAPI.
                                 readServiceFunctionStateExecutor(sfName);
@@ -172,9 +166,9 @@ public class SfcProviderSfEntryDataListener implements DataChangeListener {
                             }
                             SfcProviderRenderedPathAPI.deleteRenderedServicePathsExecutor(rspList);
                         }
-                /* We do not update the SFF dictionary. Since the user configured it in the first place,
-                 * (s)he is also responsible for updating it.
-                 */
+                        /* We do not update the SFF dictionary. Since the user configured it in the first place,
+                         * (s)he is also responsible for updating it.
+                         */
                     }
                 }
             } finally {
index 884f5b12dc7da86e975332fd5bdb0efeb789480e..86d0be27439a7f132d5813c3e233751bd3e202e5 100644 (file)
@@ -108,15 +108,4 @@ public class SfcDataStoreAPI {
         }
         return ret;
     }
-
-    public static <U extends org.opendaylight.yangtools.yang.binding.DataObject> boolean writeSynchPutTransactionAPI
-            (InstanceIdentifier<U> addIID, U data, LogicalDatastoreType logicalDatastoreType)  {
-        boolean ret;
-        WriteTransaction writeTx = OpendaylightSfc.getOpendaylightSfcObj().getDataProvider().newWriteOnlyTransaction();
-        writeTx.put(logicalDatastoreType, addIID, data, true);
-        writeTx.commit();
-        ret = true;
-        return ret;
-    }
-
 }
index c2f908f4e8c331773433b49c1d071481879aba92..b711526a595d8d319a5fdb08c58d3dd6bacbf51a 100644 (file)
@@ -8,9 +8,6 @@
 
 package org.opendaylight.sfc.provider.api;
 
-import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
-import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
-
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.sfc.provider.OpendaylightSfc;
 import org.opendaylight.sfc.provider.SfcReflection;
@@ -38,14 +35,10 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev1407
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.*;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.VxlanGpe;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.data.plane.locator.locator.type.Ip;
+import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.*;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ServiceFunctionSchedulerTypeIdentity;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.Random;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.RoundRobin;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.LoadBalance;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ShortestPath;
 
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -55,6 +48,9 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
+import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
+
 //import javax.ws.rs.HttpMethod;
 
 /**
@@ -188,7 +184,7 @@ public class SfcProviderRenderedPathAPI extends SfcProviderAbstractAPI {
         Future futureCreateRSP = ODL_SFC.getExecutor().submit(sfcProviderRenderedPathAPI);
         try {
             ret = (RenderedServicePath) futureCreateRSP.get();
-            LOG.debug("getCreateRenderedServicePathEntryAPI: {}", futureCreateRSP.get());
+            LOG.debug("createRenderedServicePathEntryExecutor: {}", ret);
         } catch (InterruptedException e) {
             LOG.warn(FAILED_TO_STR , e);
         } catch (ExecutionException e) {
@@ -379,9 +375,9 @@ public class SfcProviderRenderedPathAPI extends SfcProviderAbstractAPI {
     /**
      * Given a list of Service Functions, create a RenderedServicePath Hop List
      *
-     * @param serviceFunctionNameList
-     * @param sfgNameList
-     * @param serviceIndex
+     * @param serviceFunctionNameList List of ServiceFunctions
+     * @param sfgNameList List of ServiceFunctionGroups
+     * @param serviceIndex Starting index
      * @return
      */
     protected List<RenderedServicePathHop> createRenderedServicePathHopList(List<String> serviceFunctionNameList, List<String> sfgNameList, int serviceIndex) {
index aea60bf2c3506a5f1ad70e7b65bda1e2535a617e..e66fd632546296ca44ba948a0de49c7c764d5e8d 100755 (executable)
@@ -11,6 +11,7 @@ package org.opendaylight.sfc.provider.api;
 
 import com.google.common.base.Preconditions;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.sfc.provider.OpendaylightSfc;
 import org.opendaylight.sfc.provider.SfcReflection;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.rendered.service.path.RenderedServicePathHop;
@@ -325,18 +326,44 @@ public class SfcProviderServiceForwarderAPI extends SfcProviderAbstractAPI {
 
     /**
      * Put all Service Function Forwarders in the data store
-     * devices
+     *
      * <p>
      * @return true is all SFFs were created, false otherwise
      */
     protected boolean putAllServiceFunctionForwarders(ServiceFunctionForwarders sffs) {
-        boolean ret = false;
+        boolean ret;
         printTraceStart(LOG);
-        if (dataBroker != null) {
-            InstanceIdentifier<ServiceFunctionForwarders> sffsIID =
-                    InstanceIdentifier.builder(ServiceFunctionForwarders.class).build();
 
-            ret = SfcDataStoreAPI.writePutTransactionAPI(sffsIID, sffs, LogicalDatastoreType.CONFIGURATION);
+        ret = SfcDataStoreAPI.writePutTransactionAPI(OpendaylightSfc.SFF_IID, sffs, LogicalDatastoreType.CONFIGURATION);
+
+        printTraceStop(LOG);
+        return ret;
+    }
+
+    /**
+     * Creates a wrapper executor around a method to add a ServiceFunctionForwarder
+     * object to into DataStore
+     *
+     * <p>
+     * @param serviceFunctionForwarders Service Function Forwarders Object
+     * @return Nothing.
+     */
+    public static boolean putAllServiceFunctionForwardersExecutor(ServiceFunctionForwarders serviceFunctionForwarders) {
+
+        printTraceStart(LOG);
+        boolean ret = false;
+        Object[] servicePathObj = {serviceFunctionForwarders};
+        Class[] servicePathClass = {ServiceFunctionForwarders.class};
+        SfcProviderServiceForwarderAPI sfcProviderServiceForwarderAPI = SfcProviderServiceForwarderAPI
+                .getPutAll(servicePathObj, servicePathClass);
+        Future future = ODL_SFC.getExecutor().submit(sfcProviderServiceForwarderAPI);
+        try {
+            ret = (boolean) future.get();
+            LOG.debug("putAllServiceFunctionForwardersExecutor: {}", ret);
+        } catch (InterruptedException e) {
+            LOG.warn("failed to ...." , e);
+        } catch (ExecutionException e) {
+            LOG.warn("failed to ...." , e);
         }
         printTraceStop(LOG);
         return ret;
index acb8e5470a77292c0790cd14ab8a2cdbd7df2f8d..31ae388265b09cd5258e1f51bb7ee286160bc6b1 100755 (executable)
@@ -9,6 +9,7 @@
 package org.opendaylight.sfc.provider.api;
 
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.sfc.provider.OpendaylightSfc;
 import org.opendaylight.sfc.provider.SfcReflection;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.rendered.service.path.RenderedServicePathHop;
@@ -128,11 +129,8 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         } else {
             LOG.warn("readServiceFunctionState() Service Function {} has no operational state", serviceFunctionName);
         }
-
-
         printTraceStop(LOG);
         return ret;
-
     }
 
 
@@ -258,11 +256,8 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         } else {
             LOG.warn("readServiceFunctionDescriptionMonitor() Service Function {} has no operational state", serviceFunctionName);
         }
-
-
         printTraceStop(LOG);
         return ret;
-
     }
 
     /**
@@ -529,21 +524,27 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
     }
 
 
-    protected static boolean putServiceFunction(ServiceFunction sf) {
+    /**
+     * This method puts a SF to data store.
+     * <p>
+     * @param sf Service Function
+     * @return true if SF was added, false otherwise
+     */
+    public static boolean putServiceFunction(ServiceFunction sf) {
         boolean ret;
         printTraceStart(LOG);
 
         InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
-                child(ServiceFunction.class, sf.getKey()).toInstance();
+                child(ServiceFunction.class, sf.getKey()).build();
 
-        ret = SfcDataStoreAPI.writePutTransactionAPI(sfEntryIID, sf, LogicalDatastoreType.CONFIGURATION);
+        ret = SfcDataStoreAPI.writeMergeTransactionAPI(sfEntryIID, sf, LogicalDatastoreType.CONFIGURATION);
 
         printTraceStop(LOG);
         return ret;
     }
 
     /**
-     * This method puts a SF to data store.
+     * Wrapper executor method adds a SF to the data store.
      * <p>
      * @param sf Service Function
      * @return true if SF was added, false otherwise
@@ -559,7 +560,7 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         Future future  = ODL_SFC.getExecutor().submit(sfcProviderServiceFunctionAPI);
         try {
             ret = (boolean) future.get();
-            LOG.debug("getAddPathToServiceFunctionState: {}", future.get());
+            LOG.debug("putServiceFunctionExecutor: {}", ret);
         } catch (InterruptedException | ExecutionException e) {
             LOG.warn("failed to ...." , e);
         }
@@ -567,6 +568,12 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         return ret;
     }
 
+    /**
+     * Add ServiceFunctionState to datastore
+     * <p>
+     * @param sfState ServiceFunctionState Object
+     * @return true if state was added, false otherwise
+     */
     public static boolean putServiceFunctionState(ServiceFunctionState sfState) {
         boolean ret;
         printTraceStart(LOG);
@@ -677,7 +684,7 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         printTraceStart(LOG);
         ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName);
         InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class)
-                .child(ServiceFunction.class, serviceFunctionKey).toInstance();
+                .child(ServiceFunction.class, serviceFunctionKey).build();
 
         if (SfcDataStoreAPI.deleteTransactionAPI(sfEntryIID, LogicalDatastoreType.CONFIGURATION)) {
             ret = true;
@@ -688,12 +695,50 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         return ret;
     }
 
+    /**
+     * This method deletes a SF from the datastore
+     * <p>
+     * @param serviceFunctionName SF name
+     * @return true if SF was deleted, false otherwise
+     */
+    @SuppressWarnings("unused")
+    public static boolean deleteServiceFunctionExecutor(String serviceFunctionName) {
+        boolean ret = false;
+        printTraceStart(LOG);
+        Object[] servicePathObj = {serviceFunctionName};
+        Class[] servicePathClass = {String.class};
+        SfcProviderServiceFunctionAPI sfcProviderServiceFunctionAPI = SfcProviderServiceFunctionAPI
+                .getDelete(servicePathObj, servicePathClass);
+        Future future  = ODL_SFC.getExecutor().submit(sfcProviderServiceFunctionAPI);
+        try {
+            ret = (boolean) future.get();
+            LOG.debug("getRead: {}", future.get());
+        } catch (InterruptedException e) {
+            LOG.warn("failed to ...." , e);
+        } catch (ExecutionException e) {
+            LOG.warn("failed to ...." , e);
+        } catch (Exception e) {
+            LOG.error("Unexpected exception", e);
+        }
+        printTraceStop(LOG);
+        return ret;
+    }
+
+
+    /**
+     * This method adds a ServiceFunctions Object (collection of SFs) to the data store
+     *
+     * <p>
+     * @param  sfs Object holding ServiceFunctions
+     * @return true is ServiceFunctions added to the datatore, false otherwise
+     */
     @SuppressWarnings("unused")
+    @SfcReflection
     protected boolean putAllServiceFunctions(ServiceFunctions sfs) {
         boolean ret = false;
         printTraceStart(LOG);
-        InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).toInstance();
-        if (SfcDataStoreAPI.writeSynchPutTransactionAPI(sfsIID, sfs, LogicalDatastoreType.CONFIGURATION)) {
+        //InstanceIdentifier<ServiceFunctions> sfsIID = InstanceIdentifier.builder(ServiceFunctions.class).build();
+        if (SfcDataStoreAPI.writePutTransactionAPI(OpendaylightSfc.SF_IID, sfs, LogicalDatastoreType.CONFIGURATION)) {
             ret = true;
         } else {
             LOG.error("Could not add all Service Functions: {}", sfs.toString());
@@ -702,6 +747,35 @@ public class SfcProviderServiceFunctionAPI extends SfcProviderAbstractAPI {
         return ret;
     }
 
+    /**
+     * This method creates an executor wrapper that adds the ServiceFunctions to
+     * the datastore
+     *
+     * <p>
+     * @param  serviceFunctions Object holding ServiceFunctions
+     * @return true is ServiceFunctions added to the datatore, false otherwise
+     */
+    public static boolean putAllServiceFunctionsExecutor(ServiceFunctions serviceFunctions) {
+        printTraceStart(LOG);
+        boolean ret = false;
+        Object[] servicePathObj = {serviceFunctions};
+        Class[] servicePathClass = {ServiceFunctions.class};
+        SfcProviderServiceFunctionAPI sfcProviderServiceFunctionAPI = SfcProviderServiceFunctionAPI
+                .getPutAll(servicePathObj, servicePathClass);
+        Future future  = ODL_SFC.getExecutor().submit(sfcProviderServiceFunctionAPI);
+        try {
+            ret = (boolean) future.get();
+            LOG.debug("getPutAll: {}", future.get());
+        } catch (InterruptedException e) {
+            LOG.warn("failed to ...." , e);
+        } catch (ExecutionException e) {
+            LOG.warn("failed to ...." , e);
+        }
+        printTraceStop(LOG);
+        return ret;
+    }
+
+
     protected ServiceFunctions readAllServiceFunctions() {
         ServiceFunctions sfs = null;
         printTraceStart(LOG);
index b656f46fe077ecd3e0bee41c545eb034b315cabd..bad34be71341f757ac4384d5e81820f3a748bfc5 100755 (executable)
@@ -155,6 +155,15 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
         return ret;
     }
 
+
+    /**
+     * Wrapper method that creates an executor that will execute a method to add a
+     * SFType to the datatore
+     * <p/>
+     *
+     * @param serviceFunction Service Function Object
+     * @return Nothing.
+     */
     public static boolean createServiceFunctionTypeEntryExecutor(ServiceFunction serviceFunction) {
         boolean ret = false;
         Object[] serviceTypeObj = {serviceFunction};
@@ -164,13 +173,57 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
         Future future = ODL_SFC.getExecutor().submit(sfcProviderServiceTypeAPI);
         try {
             ret = (boolean) future.get();
-            LOG.debug("getCreateRenderedServicePathEntryAPI: {}", future.get());
+            LOG.debug("createServiceFunctionTypeEntryExecutor: {}", future.get());
         } catch (InterruptedException | ExecutionException e) {
             LOG.warn(FAILED_TO_STR, e);
         }
         return ret;
     }
 
+    /**
+     * This method creates a Service function Type entry from a Service
+     * Function.
+     * <p/>
+     *
+     * @param serviceFunction Service Function Object
+     * @return true if service type was created, false otherwise
+     */
+    public static boolean createServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
+
+        printTraceStart(LOG);
+
+        boolean ret = false;
+        Class<? extends ServiceFunctionTypeIdentity> sfkey = serviceFunction.getType();
+        ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(sfkey);
+
+        //Build the instance identifier all the way down to the bottom child
+
+        SftServiceFunctionNameKey sftServiceFunctionNameKey =
+                new SftServiceFunctionNameKey(serviceFunction.getName());
+
+        InstanceIdentifier<SftServiceFunctionName> sftentryIID;
+        sftentryIID = InstanceIdentifier.builder(ServiceFunctionTypes.class)
+                .child(ServiceFunctionType.class, serviceFunctionTypeKey)
+                .child(SftServiceFunctionName.class, sftServiceFunctionNameKey).build();
+
+        // Create a item in the list keyed by service function name
+        SftServiceFunctionNameBuilder sftServiceFunctionNameBuilder =
+                new SftServiceFunctionNameBuilder();
+        sftServiceFunctionNameBuilder = sftServiceFunctionNameBuilder
+                .setName(serviceFunction.getName());
+        SftServiceFunctionName sftServiceFunctionName =
+                sftServiceFunctionNameBuilder.build();
+
+        if (SfcDataStoreAPI.writeMergeTransactionAPI(sftentryIID, sftServiceFunctionName, LogicalDatastoreType.CONFIGURATION)) {
+            ret = true;
+        } else {
+            LOG.error("Failed to create Service Function Type for Service Function: {}", serviceFunction.getName());
+        }
+        printTraceStop(LOG);
+        return ret;
+    }
+
+
     protected boolean putServiceFunctionType(ServiceFunctionType sft) {
         boolean ret;
         printTraceStart(LOG);
@@ -192,7 +245,7 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
      * @param serviceFunctionType Service Function Type abstract class
      * @return Service Function Type Object which contains a list of SF of this type
      */
-    protected ServiceFunctionType readServiceFunctionType(Class<? extends ServiceFunctionTypeIdentity> serviceFunctionType) {
+    public static ServiceFunctionType readServiceFunctionType(Class<? extends ServiceFunctionTypeIdentity> serviceFunctionType) {
         printTraceStart(LOG);
         ServiceFunctionType sft;
         InstanceIdentifier<ServiceFunctionType> sftIID;
@@ -217,7 +270,7 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
      * @param serviceFunction Service Function object
      * @return Service Function Type Object
      */
-    public boolean deleteServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
+    public static boolean deleteServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
 
         printTraceStart(LOG);
         boolean ret = false;
@@ -261,7 +314,7 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
      * @param serviceFunctionType Service Function Type abstract class
      * @return Service Function Type Object
      */
-    public boolean deleteServiceFunctionType(Class<? extends ServiceFunctionTypeIdentity> serviceFunctionType) {
+    public static boolean deleteServiceFunctionType(Class<? extends ServiceFunctionTypeIdentity> serviceFunctionType) {
         printTraceStart(LOG);
         boolean ret = false;
 
@@ -329,15 +382,17 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
         return ret;
     }
 
+
+
     /**
-     * This method creates a Service function Type entry from a Service
+     * This method reads a Service function Type entry from a Service
      * Function.
      * <p/>
      *
      * @param serviceFunction Service Function Object
      * @return Nothing.
      */
-    public boolean createServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
+    public static SftServiceFunctionName readServiceFunctionTypeEntry(ServiceFunction serviceFunction) {
 
         printTraceStart(LOG);
 
@@ -345,16 +400,6 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
         Class<? extends ServiceFunctionTypeIdentity> sfkey = serviceFunction.getType();
         ServiceFunctionTypeKey serviceFunctionTypeKey = new ServiceFunctionTypeKey(sfkey);
 
-        //if (readAllServiceFunctionTypes() == null) {
-        //    InstanceIdentifier<ServiceFunctionTypes> sftIID;
-        //    sftIID = InstanceIdentifier.builder(ServiceFunctionTypes.class).build();
-        //    ServiceFunctionTypesBuilder serviceFunctionTypesBuilder = new ServiceFunctionTypesBuilder();
-        //    if (!SfcDataStoreAPI.writePutTransactionAPI(sftIID, serviceFunctionTypesBuilder.build(),
-        //            LogicalDatastoreType.CONFIGURATION)) {
-        //        LOG.error("Failed to create top level Service Function Type object");
-        //    }
-        //
-        //}
         //Build the instance identifier all the way down to the bottom child
 
         SftServiceFunctionNameKey sftServiceFunctionNameKey =
@@ -365,22 +410,7 @@ public class SfcProviderServiceTypeAPI extends SfcProviderAbstractAPI {
                 .child(ServiceFunctionType.class, serviceFunctionTypeKey)
                 .child(SftServiceFunctionName.class, sftServiceFunctionNameKey).build();
 
-        // Create a item in the list keyed by service function name
-        SftServiceFunctionNameBuilder sftServiceFunctionNameBuilder =
-                new SftServiceFunctionNameBuilder();
-        sftServiceFunctionNameBuilder = sftServiceFunctionNameBuilder
-                .setName(serviceFunction.getName());
-        SftServiceFunctionName sftServiceFunctionName =
-                sftServiceFunctionNameBuilder.build();
-
-        if (SfcDataStoreAPI.writeMergeTransactionAPI(sftentryIID, sftServiceFunctionName, LogicalDatastoreType.CONFIGURATION)) {
-            ret = true;
-        } else {
-            LOG.error("Failed to create Service Function Type for Service Function: {}", serviceFunction.getName());
-        }
         printTraceStop(LOG);
-        return ret;
+        return (SfcDataStoreAPI.readTransactionAPI(sftentryIID, LogicalDatastoreType.CONFIGURATION));
     }
-
-
 }
diff --git a/sfc-provider/src/test/java/org/opendaylight/sfc/provider/SfcProviderSfEntryDataListenerTest.java b/sfc-provider/src/test/java/org/opendaylight/sfc/provider/SfcProviderSfEntryDataListenerTest.java
new file mode 100644 (file)
index 0000000..3071c1d
--- /dev/null
@@ -0,0 +1,606 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.sfc.provider;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.sfc.provider.api.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.CreateRenderedPathInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctions;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.function.entry.SfDataPlaneLocator;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.function.entry.SfDataPlaneLocatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionKey;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChain;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChainBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChainKey;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunction;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionKey;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.Open;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.ServiceFunctionForwardersBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarderBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarderKey;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.service.function.forwarder.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.service.function.forwarder.service.function.dictionary.SffSfDataPlaneLocator;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.service.function.forwarder.service.function.dictionary.SffSfDataPlaneLocatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.service.function.forwarder.sff.data.plane.locator.DataPlaneLocatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.*;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.service.function.type.SftServiceFunctionName;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.VxlanGpe;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.data.plane.locator.locator.type.IpBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+
+
+/**
+ * SfcProviderSfEntryDataListener Tester.
+ *
+ * @author Reinaldo Penno ([email protected])
+ * @version 1.0
+ * @since 2015-09-02
+ */
+public class SfcProviderSfEntryDataListenerTest extends AbstractDataStoreManager {
+
+    private static final SfcProviderSfEntryDataListener sfEntryDataListener = new SfcProviderSfEntryDataListener();
+    private static ListenerRegistration<DataChangeListener> sfEntryDataListenerRegistration;
+
+    Logger LOG = LoggerFactory.getLogger(SfcProviderSfEntryDataListenerTest.class);
+
+    public ListenerRegistration<DataChangeListener> registerAsDataChangeListener() {
+        return dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+            OpendaylightSfc.SF_ENTRY_IID, sfEntryDataListener,DataBroker.DataChangeScope.SUBTREE);
+    }
+
+    @Before
+    public void before() throws Exception {
+        setOdlSfc();
+        //sfEntryDataListenerRegistration = registerAsDataChangeListener();
+    }
+
+    @After
+    public void after() throws Exception {
+        //sfEntryDataListenerRegistration.close();
+    }
+
+    /**
+     * Creates SF object, call listeners explicitly, verify that SF Type was created,
+     * cleans up
+     *
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testOnDataChanged_CreateData() throws Exception {
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+        Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Set<InstanceIdentifier<?>> removedPaths = new HashSet<InstanceIdentifier<?>>();
+        Map<InstanceIdentifier<?>, DataObject> updatedData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Map<InstanceIdentifier<?>, DataObject> originalData = new HashMap<InstanceIdentifier<?>, DataObject>();
+
+        ServiceFunction serviceFunction = build_service_function();
+
+        InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                child(ServiceFunction.class, serviceFunction.getKey()).build();
+
+        createdData.put(sfEntryIID, serviceFunction);
+
+        when(dataChangeEvent.getCreatedData()).thenReturn(createdData);
+        // Empty MAPs below
+        when(dataChangeEvent.getRemovedPaths()).thenReturn(removedPaths);
+        when(dataChangeEvent.getOriginalData()).thenReturn(originalData);
+        when(dataChangeEvent.getUpdatedData()).thenReturn(updatedData);
+
+        sfEntryDataListener.onDataChanged(dataChangeEvent);
+        Thread.sleep(500);
+        SftServiceFunctionName sftServiceFunctionName = SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(serviceFunction);
+        assertNotNull(sftServiceFunctionName);
+        assertEquals(sftServiceFunctionName.getName(), serviceFunction.getName());
+        /* clean up */
+        assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(serviceFunction));
+    }
+
+
+    /**
+     * In order to simulate a removal from the data store this test does the following:
+     * - creates SF object and inserts it into an MAP data structure representing the original data
+     * - creates a IID and add to removedPaths data structure. This IID points to the SF objects stored in the
+     *   original data
+     * - Call listener explicitly.
+     * - Cleans up
+     *
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testOnDataChanged_RemoveData() throws Exception {
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+        Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Set<InstanceIdentifier<?>> removedPaths = new HashSet<InstanceIdentifier<?>>();
+        Map<InstanceIdentifier<?>, DataObject> updatedData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Map<InstanceIdentifier<?>, DataObject> originalData = new HashMap<InstanceIdentifier<?>, DataObject>();
+
+        ServiceFunction serviceFunction = build_service_function();
+
+        /* First we create a Service Function Type Entry */
+        assertTrue(SfcProviderServiceTypeAPI.createServiceFunctionTypeEntry(serviceFunction));
+
+        /* Now we prepare to remove the entry through the listener */
+        InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                child(ServiceFunction.class, serviceFunction.getKey()).build();
+
+        originalData.put(sfEntryIID, serviceFunction);
+        removedPaths.add(sfEntryIID);
+        when(dataChangeEvent.getRemovedPaths()).thenReturn(removedPaths);
+        when(dataChangeEvent.getOriginalData()).thenReturn(originalData);
+        // Empty MAPs below
+        when(dataChangeEvent.getCreatedData()).thenReturn(createdData);
+        when(dataChangeEvent.getUpdatedData()).thenReturn(updatedData);
+        /* The listener will remove the Service Function Type Entry */
+        sfEntryDataListener.onDataChanged(dataChangeEvent);
+        Thread.sleep(500);
+        assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(serviceFunction));
+    }
+
+    /**
+     * In order to simulate an update from the data store this test does the following:
+     * - creates SF object and commits to data store
+     * - Creates a copy of the original SF and updates the type and management address
+     * - Feeds the original and updated SFs to the listener
+     * - Asserts that the listener has removed the original and created a new entry
+     * - Cleans up
+     *
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testOnDataChanged_UpdateSFData() throws Exception {
+        String UPDATED_IP_MGMT_ADDRESS = "196.168.55.102";
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+        Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Set<InstanceIdentifier<?>> removedPaths = new HashSet<InstanceIdentifier<?>>();
+        Map<InstanceIdentifier<?>, DataObject> updatedData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Map<InstanceIdentifier<?>, DataObject> originalData = new HashMap<InstanceIdentifier<?>, DataObject>();
+
+        /* Create and commit SF */
+        ServiceFunction originalServiceFunction = build_service_function();
+        InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                child(ServiceFunction.class, originalServiceFunction.getKey()).build();
+        assertTrue(SfcProviderServiceFunctionAPI.putServiceFunctionExecutor(originalServiceFunction));
+        /* Since there is no listener we need to create a Service Function Type Entry */
+        assertTrue(SfcProviderServiceTypeAPI.createServiceFunctionTypeEntry(originalServiceFunction));
+
+        originalData.put(sfEntryIID, originalServiceFunction);
+
+        /* Now we prepare the updated data. We change mgmt address and type */
+
+        ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction);
+        IpAddress updatedIpMgmtAddress = new IpAddress(new Ipv4Address(UPDATED_IP_MGMT_ADDRESS));
+        Class<? extends ServiceFunctionTypeIdentity> updatedType = Dpi.class;
+        updatedServiceFunctionBuilder.setIpMgmtAddress(updatedIpMgmtAddress).setType(updatedType);
+        ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build();
+        updatedData.put(sfEntryIID, updatedServiceFunction);
+
+
+        when(dataChangeEvent.getUpdatedData()).thenReturn(updatedData);
+        when(dataChangeEvent.getOriginalData()).thenReturn(originalData);
+        // Empty MAPs below
+        when(dataChangeEvent.getCreatedData()).thenReturn(createdData);
+        when(dataChangeEvent.getRemovedPaths()).thenReturn(removedPaths);
+
+        /* The listener will remove the Original Service Function Type Entry and create a new one
+         * with the new type
+         */
+        sfEntryDataListener.onDataChanged(dataChangeEvent);
+        Thread.sleep(500);
+        assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction));
+        assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction));
+
+        //Clean-up
+        assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction));
+        assertTrue(SfcProviderServiceFunctionAPI.deleteServiceFunctionExecutor(originalServiceFunction.getName()));
+        Thread.sleep(500);
+        assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction));
+
+
+    }
+
+    /**
+     * In this test we create a RSP and remove a SF used by it. This will trigger a more complete
+     * code coverage within the listener.
+     * In order to simulate a removal from the data store this test does the following:
+     *
+     * - Create RSP
+     * - Remove first SF used by RSP by explicitly calling the listener
+     * - creates a IID and add to removedPaths data structure. This IID points to the SF objects stored in the
+     *   original data
+     * - Call listener explicitly.
+     * - Cleans up
+     *
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testOnDataChanged_RemoveDataWithRSP() throws Exception {
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+        Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Set<InstanceIdentifier<?>> removedPaths = new HashSet<InstanceIdentifier<?>>();
+        Map<InstanceIdentifier<?>, DataObject> updatedData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Map<InstanceIdentifier<?>, DataObject> originalData = new HashMap<InstanceIdentifier<?>, DataObject>();
+
+        RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path();
+        assertNotNull(renderedServicePath);
+
+        // Prepare to remove the first SF used by the RSP.
+        String sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName();
+        ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(sfName);
+        assertNotNull(serviceFunction);
+
+        // Now we prepare to remove the entry through the listener
+
+        InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                child(ServiceFunction.class, serviceFunction.getKey()).build();
+
+        originalData.put(sfEntryIID, serviceFunction);
+        removedPaths.add(sfEntryIID);
+        when(dataChangeEvent.getRemovedPaths()).thenReturn(removedPaths);
+        when(dataChangeEvent.getOriginalData()).thenReturn(originalData);
+        // Empty MAPs below
+        when(dataChangeEvent.getCreatedData()).thenReturn(createdData);
+        when(dataChangeEvent.getUpdatedData()).thenReturn(updatedData);
+        // The listener will remove the Service Function Type Entry
+
+        sfEntryDataListener.onDataChanged(dataChangeEvent);
+        Thread.sleep(500);
+        assertNull(SfcProviderRenderedPathAPI.readRenderedServicePathExecutor(renderedServicePath.getName()));
+        List<String> sfpNameList = SfcProviderServiceFunctionAPI.
+                readServiceFunctionStateAsStringList(serviceFunction.getName());
+        if (sfpNameList != null) {
+            for (String sfpName : sfpNameList) {
+                assertNotEquals(sfpName, renderedServicePath.getName());
+            }
+        }
+
+        /* Clean-up */
+
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SFC_IID, LogicalDatastoreType.CONFIGURATION));
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SF_IID, LogicalDatastoreType.CONFIGURATION));
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SFF_IID, LogicalDatastoreType.CONFIGURATION));
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SFP_IID, LogicalDatastoreType.CONFIGURATION));
+
+    }
+
+    /**
+     * In this test we create a RSP and update a SF used by it. This will trigger a more complete
+     * code coverage within the listener.
+     * In order to simulate a removal from the data store this test does the following:
+     *
+     * - Create RSP
+     * - Update first SF used by RSP by explicitly calling the listener
+     * - creates a IID and add to removedPaths data structure. This IID points to the SF objects stored in the
+     *   original data
+     * - Call listener explicitly.
+     * - Cleans up
+     *
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testOnDataChanged_UpdateSFDataWithRSP() throws Exception {
+        String UPDATED_IP_MGMT_ADDRESS = "196.168.55.102";
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+        Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Set<InstanceIdentifier<?>> removedPaths = new HashSet<InstanceIdentifier<?>>();
+        Map<InstanceIdentifier<?>, DataObject> updatedData = new HashMap<InstanceIdentifier<?>, DataObject>();
+        Map<InstanceIdentifier<?>, DataObject> originalData = new HashMap<InstanceIdentifier<?>, DataObject>();
+
+        RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path();
+        assertNotNull(renderedServicePath);
+
+        // Prepare to update the first SF used by the RSP.
+        String sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName();
+        ServiceFunction originalServiceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(sfName);
+        assertNotNull(originalServiceFunction);
+
+        // Now we prepare the updated data. We change mgmt address and type
+
+        // Now we prepare to remove the entry through the listener
+        InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class).
+                child(ServiceFunction.class, originalServiceFunction.getKey()).build();
+
+        ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction);
+        IpAddress updatedIpMgmtAddress = new IpAddress(new Ipv4Address(UPDATED_IP_MGMT_ADDRESS));
+        Class<? extends ServiceFunctionTypeIdentity> updatedType = Dpi.class;
+        updatedServiceFunctionBuilder.setIpMgmtAddress(updatedIpMgmtAddress).setType(updatedType);
+        ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build();
+        updatedData.put(sfEntryIID, updatedServiceFunction);
+
+        originalData.put(sfEntryIID, originalServiceFunction);
+        when(dataChangeEvent.getUpdatedData()).thenReturn(updatedData);
+        when(dataChangeEvent.getOriginalData()).thenReturn(originalData);
+        // Empty MAPs below
+        when(dataChangeEvent.getCreatedData()).thenReturn(createdData);
+        when(dataChangeEvent.getRemovedPaths()).thenReturn(removedPaths);
+
+        /* The listener will remove the Original Service Function Type Entry and create a new one
+         * with the new type
+         */
+        sfEntryDataListener.onDataChanged(dataChangeEvent);
+        Thread.sleep(500);
+        assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction));
+        assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction));
+
+        //Clean-up
+        assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction));
+        assertNull(SfcProviderRenderedPathAPI.readRenderedServicePathExecutor(renderedServicePath.getName()));
+        List<String> sfpNameList = SfcProviderServiceFunctionAPI.
+                readServiceFunctionStateAsStringList(originalServiceFunction.getName());
+        if (sfpNameList != null) {
+            for (String sfpName : sfpNameList) {
+                assertNotEquals(sfpName, renderedServicePath.getName());
+            }
+        }
+
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SFF_IID, LogicalDatastoreType.CONFIGURATION));
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SF_IID, LogicalDatastoreType.CONFIGURATION));
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SFC_IID, LogicalDatastoreType.CONFIGURATION));
+        assertTrue(SfcDataStoreAPI.deleteTransactionAPI(OpendaylightSfc.SFP_IID, LogicalDatastoreType.CONFIGURATION));
+    }
+
+
+    /**
+     * Builds a complete service Function Object
+     *
+     * @return ServiceFunction object
+     */
+    ServiceFunction build_service_function() {
+        String[] LOCATOR_IP_ADDRESS =
+                {"196.168.55.1",
+                        "196.168.55.2",
+                        "196.168.55.3"};
+        String[] IP_MGMT_ADDRESS =
+                {"196.168.55.101",
+                        "196.168.55.102",
+                        "196.168.55.103"};
+        String SF_NAME = "listernerSF";
+        int PORT = 555;
+        Class<? extends ServiceFunctionTypeIdentity> type = Firewall.class;
+        IpAddress ipMgmtAddress = new IpAddress(new Ipv4Address(IP_MGMT_ADDRESS[0]));
+        SfDataPlaneLocator sfDataPlaneLocator;
+        ServiceFunctionKey key = new ServiceFunctionKey(SF_NAME);
+
+        IpAddress ipAddress = new IpAddress(new Ipv4Address(LOCATOR_IP_ADDRESS[0]));
+        PortNumber portNumber = new PortNumber(PORT);
+        IpBuilder ipBuilder = new IpBuilder();
+        ipBuilder.setIp(ipAddress).setPort(portNumber);
+        SfDataPlaneLocatorBuilder locatorBuilder = new SfDataPlaneLocatorBuilder();
+        locatorBuilder.setName(LOCATOR_IP_ADDRESS[0]).setLocatorType(ipBuilder.build());
+        sfDataPlaneLocator = locatorBuilder.build();
+        List<SfDataPlaneLocator> dataPlaneLocatorList = new ArrayList<>();
+        dataPlaneLocatorList.add(sfDataPlaneLocator);
+
+        ServiceFunctionBuilder sfBuilder = new ServiceFunctionBuilder();
+        sfBuilder.setName(SF_NAME).setKey(key)
+                .setType(type)
+                .setIpMgmtAddress(ipMgmtAddress)
+                .setSfDataPlaneLocator(dataPlaneLocatorList);
+
+        ServiceFunction serviceFunction = sfBuilder.build();
+        return serviceFunction;
+    }
+
+    /**
+     * Builds and return a complete RSP Object
+     *
+     * @return RSP object
+     */
+    RenderedServicePath build_and_commit_rendered_service_path() throws Exception {
+        String[] LOCATOR_IP_ADDRESS =
+                {"196.168.55.1", "196.168.55.2", "196.168.55.3",
+                        "196.168.55.4", "196.168.55.5"};
+        String[] IP_MGMT_ADDRESS =
+                {"196.168.55.101", "196.168.55.102", "196.168.55.103",
+                        "196.168.55.104", "196.168.55.105"};
+        int[] PORT = {1111, 2222, 3333, 4444, 5555};
+        Class[] sfTypes = {Firewall.class, Dpi.class, Napt44.class, HttpHeaderEnrichment.class, Qos.class};
+        String[] SF_ABSTRACT_NAMES = {"firewall", "dpi", "napt", "http-header-enrichment", "qos"};
+        String SFC_NAME = "unittest-chain-1";
+        String SFP_NAME = "unittest-sfp-1";
+        String RSP_NAME = "unittest-rsp-1";
+        String[] sfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1", "unittest-http-header-enrichment-1", "unittest-qos-1"};
+        String[] SFF_NAMES = {"SFF1", "SFF2", "SFF3", "SFF4", "SFF5"};
+        String[][] TO_SFF_NAMES =
+                {{"SFF2", "SFF5"}, {"SFF3", "SFF1"}, {"SFF4", "SFF2"}, {"SFF5", "SFF3"}, {"SFF1", "SFF4"}};
+        String[] SFF_LOCATOR_IP =
+                {"196.168.66.101", "196.168.66.102", "196.168.66.103", "196.168.66.104", "196.168.66.105"};
+        List<ServiceFunction> sfList = new ArrayList<>();
+        List<ServiceFunctionForwarder> sffList = new ArrayList<>();
+
+        final IpAddress[] ipMgmtAddress = new IpAddress[sfNames.length];
+        final IpAddress[] locatorIpAddress = new IpAddress[sfNames.length];
+        SfDataPlaneLocator[] sfDataPlaneLocator = new SfDataPlaneLocator[sfNames.length];
+        ServiceFunctionKey[] key = new ServiceFunctionKey[sfNames.length];
+        for (int i = 0; i < sfNames.length; i++) {
+            ipMgmtAddress[i] = new IpAddress(new Ipv4Address(IP_MGMT_ADDRESS[0]));
+            locatorIpAddress[i] = new IpAddress(new Ipv4Address(LOCATOR_IP_ADDRESS[0]));
+            PortNumber portNumber = new PortNumber(PORT[i]);
+            key[i] = new ServiceFunctionKey(sfNames[i]);
+
+            IpBuilder ipBuilder = new IpBuilder();
+            ipBuilder.setIp(locatorIpAddress[i]).setPort(portNumber);
+            SfDataPlaneLocatorBuilder locatorBuilder = new SfDataPlaneLocatorBuilder();
+            locatorBuilder.setName(LOCATOR_IP_ADDRESS[i]).setLocatorType(ipBuilder.build()).setServiceFunctionForwarder(SFF_NAMES[i]);
+            sfDataPlaneLocator[i] = locatorBuilder.build();
+
+            ServiceFunctionBuilder sfBuilder = new ServiceFunctionBuilder();
+            List<SfDataPlaneLocator> dataPlaneLocatorList = new ArrayList<>();
+            dataPlaneLocatorList.add(sfDataPlaneLocator[i]);
+            sfBuilder.setName(sfNames[i]).setKey(key[i])
+                    .setType(sfTypes[i])
+                    .setIpMgmtAddress(ipMgmtAddress[i])
+                    .setSfDataPlaneLocator(dataPlaneLocatorList);
+            sfList.add(sfBuilder.build());
+        }
+
+        ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
+        sfsBuilder.setServiceFunction(sfList);
+
+        assertTrue(SfcProviderServiceFunctionAPI.putAllServiceFunctionsExecutor(sfsBuilder.build()));
+        //executor.submit(SfcProviderServiceFunctionAPI.getPutAll(new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+        Thread.sleep(1000); // Wait they are really created
+
+        // Create ServiceFunctionTypeEntry for all ServiceFunctions
+        for (ServiceFunction serviceFunction : sfList) {
+            assertTrue(SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction));
+        }
+
+        // Create Service Function Forwarders
+        for (int i = 0; i < SFF_NAMES.length; i++) {
+            //ServiceFunctionForwarders connected to SFF_NAMES[i]
+            List<ConnectedSffDictionary> sffDictionaryList = new ArrayList<>();
+            for (int j = 0; j < 2; j++) {
+                ConnectedSffDictionaryBuilder sffDictionaryEntryBuilder = new ConnectedSffDictionaryBuilder();
+                ConnectedSffDictionary sffDictEntry = sffDictionaryEntryBuilder.setName(TO_SFF_NAMES[i][j]).build();
+                sffDictionaryList.add(sffDictEntry);
+            }
+
+            //ServiceFunctions attached to SFF_NAMES[i]
+            List<ServiceFunctionDictionary> sfDictionaryList = new ArrayList<>();
+            ServiceFunction serviceFunction = sfList.get(i);
+            SfDataPlaneLocator sfDPLocator = serviceFunction.getSfDataPlaneLocator().get(0);
+            SffSfDataPlaneLocatorBuilder sffSfDataPlaneLocatorBuilder = new SffSfDataPlaneLocatorBuilder(sfDPLocator);
+            SffSfDataPlaneLocator sffSfDataPlaneLocator = sffSfDataPlaneLocatorBuilder.build();
+            ServiceFunctionDictionaryBuilder dictionaryEntryBuilder = new ServiceFunctionDictionaryBuilder();
+            dictionaryEntryBuilder.setName(serviceFunction.getName())
+                    .setKey(new ServiceFunctionDictionaryKey(serviceFunction.getName()))
+                    .setType(serviceFunction.getType())
+                    .setSffSfDataPlaneLocator(sffSfDataPlaneLocator)
+                    .setFailmode(Open.class)
+                    .setSffInterfaces(null);
+            ServiceFunctionDictionary sfDictEntry = dictionaryEntryBuilder.build();
+            sfDictionaryList.add(sfDictEntry);
+
+            List<SffDataPlaneLocator> locatorList = new ArrayList<>();
+            IpBuilder ipBuilder = new IpBuilder();
+            ipBuilder.setIp(new IpAddress(new Ipv4Address(SFF_LOCATOR_IP[i])))
+                    .setPort(new PortNumber(PORT[i]));
+            DataPlaneLocatorBuilder sffLocatorBuilder = new DataPlaneLocatorBuilder();
+            sffLocatorBuilder.setLocatorType(ipBuilder.build())
+                    .setTransport(VxlanGpe.class);
+            SffDataPlaneLocatorBuilder locatorBuilder = new SffDataPlaneLocatorBuilder();
+            locatorBuilder.setName(SFF_LOCATOR_IP[i])
+                    .setKey(new SffDataPlaneLocatorKey(SFF_LOCATOR_IP[i]))
+                    .setDataPlaneLocator(sffLocatorBuilder.build());
+            locatorList.add(locatorBuilder.build());
+            ServiceFunctionForwarderBuilder sffBuilder = new ServiceFunctionForwarderBuilder();
+            sffBuilder.setName(SFF_NAMES[i])
+                    .setKey(new ServiceFunctionForwarderKey(SFF_NAMES[i]))
+                    .setSffDataPlaneLocator(locatorList)
+                    .setServiceFunctionDictionary(sfDictionaryList)
+                    .setConnectedSffDictionary(sffDictionaryList)
+                    .setServiceNode(null);
+            ServiceFunctionForwarder sff = sffBuilder.build();
+            sffList.add(sff);
+            //assertTrue(SfcProviderServiceForwarderAPI.putServiceFunctionForwarderExecutor(sff));
+            //executor.submit(SfcProviderServiceForwarderAPI.getPut(new Object[]{sff}, new Class[]{ServiceFunctionForwarder.class})).get();
+        }
+        ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder = new ServiceFunctionForwardersBuilder();
+        serviceFunctionForwardersBuilder.setServiceFunctionForwarder(sffList);
+        assertTrue(SfcProviderServiceForwarderAPI.
+                putAllServiceFunctionForwardersExecutor(serviceFunctionForwardersBuilder.build()));
+
+        //Create Service Function Chain
+        ServiceFunctionChainKey sfcKey = new ServiceFunctionChainKey(SFC_NAME);
+        List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
+
+        for (int i = 0; i < SF_ABSTRACT_NAMES.length; i++) {
+            SfcServiceFunctionBuilder sfcSfBuilder = new SfcServiceFunctionBuilder();
+            SfcServiceFunction sfcServiceFunction =
+                    sfcSfBuilder.setName(SF_ABSTRACT_NAMES[i])
+                            .setKey(new SfcServiceFunctionKey(SF_ABSTRACT_NAMES[i]))
+                            .setType(sfTypes[i])
+                            .build();
+            sfcServiceFunctionList.add(sfcServiceFunction);
+        }
+        ServiceFunctionChainBuilder sfcBuilder = new ServiceFunctionChainBuilder();
+        sfcBuilder.setName(SFC_NAME).setKey(sfcKey)
+                .setSfcServiceFunction(sfcServiceFunctionList)
+                .setSymmetric(true);
+
+//        Object[] parameters = {sfcBuilder.build()};
+//        Class[] parameterTypes = {ServiceFunctionChain.class};
+
+        assertTrue(SfcProviderServiceChainAPI.putServiceFunctionChainExecutor(sfcBuilder.build()));
+//        executor.submit(SfcProviderServiceChainAPI
+//                .getPut(parameters, parameterTypes)).get();
+        Thread.sleep(1000); // Wait SFC is really crated
+
+        //Check if Service Function Chain was created
+//        Object[] parameters2 = {SFC_NAME};
+//        Class[] parameterTypes2 = {String.class};
+//        Object result = executor.submit(SfcProviderServiceChainAPI
+//                .getRead(parameters2, parameterTypes2)).get();
+//        ServiceFunctionChain sfc2 = (ServiceFunctionChain) result;
+
+        ServiceFunctionChain readServiceFunctionChain =
+                SfcProviderServiceChainAPI.readServiceFunctionChainExecutor(SFC_NAME);
+
+        assertNotNull(readServiceFunctionChain);
+
+        //assertNotNull("Must be not null", sfc2);
+        assertEquals("Must be equal", readServiceFunctionChain.getSfcServiceFunction(), sfcServiceFunctionList);
+
+        /* Create ServiceFunctionPath */
+        ServiceFunctionPathBuilder pathBuilder = new ServiceFunctionPathBuilder();
+        pathBuilder.setName(SFP_NAME)
+                .setServiceChainName(SFC_NAME)
+                .setSymmetric(true);
+        ServiceFunctionPath serviceFunctionPath = pathBuilder.build();
+        assertNotNull("Must be not null", serviceFunctionPath);
+        assertTrue(SfcProviderServicePathAPI.putServiceFunctionPathExecutor(serviceFunctionPath));
+//        assertTrue("Must be true", ret);
+
+        Thread.sleep(1000); // Wait they are really created
+
+        /* Create RenderedServicePath and reverse RenderedServicePath */
+        RenderedServicePath renderedServicePath = null;
+
+        CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder();
+        createRenderedPathInputBuilder.setName(RSP_NAME);
+        createRenderedPathInputBuilder.setSymmetric(serviceFunctionPath.isSymmetric());
+        try {
+            renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInputBuilder.build());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        assertNotNull("Must be not null", renderedServicePath);
+        return renderedServicePath;
+    }
+
+
+}
index 43d9829288468170fbf1f4c1e3c3ae34ec000062..057bb5634ca84901b6fc9d412f3c95253241c323 100644 (file)
@@ -74,7 +74,7 @@ public abstract class AbstractSfcRendererServicePathAPITest extends AbstractData
     protected static final String SFC_NAME = "unittest-chain-1";
     protected static final String SFP_NAME = "unittest-sfp-1";
     protected static final String RSP_NAME = "unittest-rsp-1";
-    protected static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceChainAPITest.class);
+    protected static final Logger LOG = LoggerFactory.getLogger(AbstractSfcRendererServicePathAPITest.class);
     protected static final String[] sfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1", "unittest-http-header-enrichment-1", "unittest-qos-1"};
     protected final String[] SFF_NAMES = {"SFF1", "SFF2", "SFF3", "SFF4", "SFF5"};
     protected final String[][] TO_SFF_NAMES =
index 334afe12d05e02a2c39b0193b69589f8ff24f464..e1fd43ddaa4e15a99a2019821ddb3d13c037c435 100755 (executable)
@@ -9,7 +9,6 @@
 package org.opendaylight.sfc.provider.api;
 
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.CreateRenderedPathInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.path.first.hop.info.RenderedServicePathFirstHop;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
@@ -25,10 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev14070
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.LoadBalance;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.Random;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.RoundRobin;
-import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ShortestPath;
+import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.*;
 import org.powermock.reflect.Whitebox;
 
 import java.util.ArrayList;
@@ -49,7 +45,8 @@ public class SfcProviderRenderedPathAPITest extends AbstractSfcRendererServicePa
         lbResult = Whitebox.invokeMethod(SfcProviderRenderedPathAPI.class, "getServiceFunctionScheduler", LoadBalance.class);
         rnResult = Whitebox.invokeMethod(SfcProviderRenderedPathAPI.class, "getServiceFunctionScheduler", Random.class);
         spResult = Whitebox.invokeMethod(SfcProviderRenderedPathAPI.class, "getServiceFunctionScheduler", ShortestPath.class);
-        rsResult = Whitebox.invokeMethod(SfcProviderRenderedPathAPI.class, "getServiceFunctionScheduler", Mockito.any());
+        rsResult = Whitebox.invokeMethod(SfcProviderRenderedPathAPI.class, "getServiceFunctionScheduler",
+                ServiceFunctionSchedulerTypeIdentity.class);
 
         assertEquals("Must be equal", rrResult.getClass(), SfcServiceFunctionRoundRobinSchedulerAPI.class);
         assertEquals("Must be equal", lbResult.getClass(), SfcServiceFunctionLoadBalanceSchedulerAPI.class);