[ONOS-5295] JUNIT Test cases for volt-onus, volt-setonu and volt-onustats as FUJITSU NETCONF commands

Change-Id: I8f80bc651adf2bfbfa7ce8587e03b1373222f37a
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java
index c38c46d..be16f55 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java
@@ -40,9 +40,14 @@
         implements VoltOnuConfig {
 
     private final Logger log = getLogger(FujitsuVoltOnuConfig.class);
-    private final Set<String> onuConfigParams = ImmutableSet.of(
-            "admin-state", "pm-enable", "fec-enable",
-            "security-enable", "password");
+    private static final String ADMIN_STATE = "admin-state";
+    private static final String PASSWORD = "password";
+    private static final Set<String> ONUCONFIGPARAMS =
+            ImmutableSet.of(ADMIN_STATE, "pm-enable", "fec-enable", "security-enable", PASSWORD);
+    private static final Set<String> ADMINSTATES =
+            ImmutableSet.of("enable", "disable");
+    private static final Set<String> ENABLES =
+            ImmutableSet.of("true", "false");
     private static final String VOLT_ONUS = "volt-onus";
     private static final String ONUS_PERLINK = "onus-perlink";
     private static final String ONUS_LIST = "onus-list";
@@ -55,9 +60,7 @@
     private static final String ETH_STATS = "eth-stats";
     private static final String ONU_GEM_STATS = "onu-gem-stats";
     private static final String GEM_STATS = "gem-stats";
-    private int pon;
-    private int onu;
-
+    private static final String PASSWORD_PATTERN = "^[a-zA-Z0-9]+$";
 
     @Override
     public String getOnus(String target) {
@@ -73,23 +76,14 @@
             log.warn("Not master for {} Use {} to execute command",
                      ncDeviceId,
                      mastershipService.getMasterFor(ncDeviceId));
-            return reply;
+            return null;
         }
 
         if (target != null) {
-            onuId = target.split(HYPHEN);
-            if (onuId.length > 2) {
-                log.error("Invalid number of arguments");
-                return reply;
-            }
-            try {
-                pon = Integer.parseInt(onuId[0]);
-                if (onuId.length > 1) {
-                    onu = Integer.parseInt(onuId[1]);
-                }
-            } catch (NumberFormatException e) {
-                log.error("Non-number input");
-                return reply;
+            onuId = checkIdString(target);
+            if (onuId == null) {
+                log.error("Invalid ONU identifier {}", target);
+                return null;
             }
         }
 
@@ -101,13 +95,13 @@
                 request.append(buildStartTag(VOLT_ONUS));
                 request.append(buildStartTag(ONUS_PERLINK));
                 request.append(buildStartTag(PONLINK_ID, false));
-                request.append(onuId[0]);
+                request.append(onuId[FIRST_PART]);
                 request.append(buildEndTag(PONLINK_ID));
-                if (onuId.length > 1) {
+                if (onuId.length > ONE) {
                     request.append(buildStartTag(ONUS_LIST));
                     request.append(buildStartTag(ONU_INFO));
                     request.append(buildStartTag(ONU_ID, false));
-                    request.append(onuId[1]);
+                    request.append(onuId[SECOND_PART]);
                     request.append(buildEndTag(ONU_ID));
                     request.append(buildEndTag(ONU_INFO));
                     request.append(buildEndTag(ONUS_LIST));
@@ -119,11 +113,13 @@
             }
             request.append(VOLT_NE_CLOSE);
 
-            reply = controller.
-                    getDevicesMap().get(ncDeviceId).getSession().
-                    get(request.toString(), REPORT_ALL);
+            reply = controller
+                        .getDevicesMap()
+                        .get(ncDeviceId)
+                        .getSession()
+                        .get(request.toString(), REPORT_ALL);
         } catch (IOException e) {
-            log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
+            log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
         }
         return reply;
     }
@@ -141,32 +137,25 @@
             log.warn("Not master for {} Use {} to execute command",
                      ncDeviceId,
                      mastershipService.getMasterFor(ncDeviceId));
-            return reply;
+            return null;
         }
 
         String[] data = target.split(COLON);
-        if (data.length != 3) {
+        if (data.length != THREE) {
             log.error("Invalid number of arguments");
-            return reply;
+            return null;
         }
 
-        String[] onuId = data[0].split(HYPHEN);
-        if (onuId.length != 2) {
-            log.error("Invalid ONU identifier");
-            return reply;
+        String[] onuId = checkIdString(data[FIRST_PART]);
+        if ((onuId == null) || (onuId.length != TWO)) {
+            log.error("Invalid ONU identifier {}", target);
+            return null;
         }
 
-        try {
-            pon = Integer.parseInt(onuId[0]);
-            onu = Integer.parseInt(onuId[1]);
-        } catch (NumberFormatException e) {
-            log.error("Non-number input");
-            return reply;
-        }
-
-        if (!onuConfigParams.contains(data[1])) {
-            log.error("Unsupported parameter: " + data[1]);
-            return reply;
+        if (!checkSetParam(data[SECOND_PART],
+                            data[THIRD_PART])) {
+            log.error("Failed to check input {}", target);
+            return null;
         }
 
         try {
@@ -174,23 +163,25 @@
             request.append(ANGLE_LEFT).append(ONU_SET_CONFIG).append(SPACE);
             request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE);
             request.append(buildStartTag(PONLINK_ID, false));
-            request.append(onuId[0]);
+            request.append(onuId[FIRST_PART]);
             request.append(buildEndTag(PONLINK_ID));
             request.append(buildStartTag(ONU_ID, false));
-            request.append(onuId[1]);
+            request.append(onuId[SECOND_PART]);
             request.append(buildEndTag(ONU_ID));
             request.append(buildStartTag(CONFIG_INFO));
-            request.append(buildStartTag(data[1], false));
-            request.append(data[2]);
-            request.append(buildEndTag(data[1]));
+            request.append(buildStartTag(data[SECOND_PART], false));
+            request.append(data[THIRD_PART]);
+            request.append(buildEndTag(data[SECOND_PART]));
             request.append(buildEndTag(CONFIG_INFO));
             request.append(buildEndTag(ONU_SET_CONFIG));
 
-            reply = controller.
-                    getDevicesMap().get(ncDeviceId).getSession().
-                    doWrappedRpc(request.toString());
+            reply = controller
+                        .getDevicesMap()
+                        .get(ncDeviceId)
+                        .getSession()
+                        .doWrappedRpc(request.toString());
         } catch (IOException e) {
-            log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
+            log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
         }
         return reply;
     }
@@ -209,23 +200,14 @@
             log.warn("Not master for {} Use {} to execute command",
                      ncDeviceId,
                      mastershipService.getMasterFor(ncDeviceId));
-            return reply;
+            return null;
         }
 
         if (target != null) {
-            onuId = target.split(HYPHEN);
-            if (onuId.length > 2) {
-                log.error("Invalid number of arguments:" + onuId.length);
-                return reply;
-            }
-            try {
-                pon = Integer.parseInt(onuId[0]);
-                if (onuId.length > 1) {
-                    onu = Integer.parseInt(onuId[1]);
-                }
-            } catch (NumberFormatException e) {
-                log.error("Non-number input");
-                return reply;
+            onuId = checkIdString(target);
+            if (onuId == null) {
+                log.error("Failed to check ID: {}", target);
+                return null;
             }
         }
 
@@ -239,11 +221,11 @@
                 request.append(buildStartTag(ONU_GEM_STATS));
                 request.append(buildStartTag(GEM_STATS));
                 request.append(buildStartTag(PONLINK_ID, false));
-                request.append(onuId[0]);
+                request.append(onuId[FIRST_PART]);
                 request.append(buildEndTag(PONLINK_ID));
-                if (onuId.length > 1) {
+                if (onuId.length > ONE) {
                     request.append(buildStartTag(ONU_ID, false));
-                    request.append(onuId[1]);
+                    request.append(onuId[SECOND_PART]);
                     request.append(buildEndTag(ONU_ID));
                 }
                 request.append(buildEndTag(GEM_STATS));
@@ -252,30 +234,119 @@
                 request.append(buildStartTag(ONU_ETH_STATS));
                 request.append(buildStartTag(ETH_STATS));
                 request.append(buildStartTag(PONLINK_ID, false));
-                request.append(onuId[0]);
+                request.append(onuId[FIRST_PART]);
                 request.append(buildEndTag(PONLINK_ID));
-                if (onuId.length > 1) {
+                if (onuId.length > ONE) {
                     request.append(buildStartTag(ONU_ID, false));
-                    request.append(onuId[1]);
+                    request.append(onuId[SECOND_PART]);
                     request.append(buildEndTag(ONU_ID));
                 }
                 request.append(buildEndTag(ETH_STATS));
                 request.append(buildEndTag(ONU_ETH_STATS));
-
                 request.append(buildEndTag(ONU_STATISTICS));
-            } else {
+            } else  {
                 request.append(buildEmptyTag(ONU_STATISTICS));
             }
             request.append(buildEndTag(VOLT_STATISTICS));
             request.append(VOLT_NE_CLOSE);
 
-            reply = controller.
-                    getDevicesMap().get(ncDeviceId).getSession().
-                    get(request.toString(), REPORT_ALL);
+            reply = controller
+                        .getDevicesMap()
+                        .get(ncDeviceId)
+                        .getSession()
+                        .get(request.toString(), REPORT_ALL);
         } catch (IOException e) {
-            log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
+            log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
         }
         return reply;
     }
 
+    /**
+     * Verifies input string for ponlink-id{-onu-id}.
+     *
+     * @param target input data in string
+     * @return String array
+     * @return null if an error condition is detected
+     */
+    private String[] checkIdString(String target) {
+        String[] onuId = target.split(HYPHEN);
+        int pon;
+        int onu;
+
+        if (onuId.length > TWO) {
+            log.error("Invalid number of arguments for id:{}", onuId.length);
+            return null;
+        }
+        try {
+            pon = Integer.parseInt(onuId[FIRST_PART]);
+            if (pon <= ZERO) {
+                log.error("Invalid integer for ponlink-id:{}", onuId[FIRST_PART]);
+                return null;
+            }
+            if (onuId.length > ONE) {
+                onu = Integer.parseInt(onuId[SECOND_PART]);
+                if (onu <= ZERO) {
+                    log.error("Invalid integer for onu-id:{}", onuId[SECOND_PART]);
+                    return null;
+                }
+            }
+        } catch (NumberFormatException e) {
+            log.error("Non-number input for id:{}", target);
+            return null;
+        }
+        return onuId;
+    }
+
+    /**
+     * Verifies input string for valid options.
+     *
+     * @param name input data in string
+     * @param value input data in string
+     * @return true if the parameter is valid
+     * @return false if the parameter is invalid
+     */
+    private boolean checkSetParam(String name, String value) {
+        if (!ONUCONFIGPARAMS.contains(name)) {
+            log.error("Unsupported parameter: {}", name);
+            return false;
+        }
+
+        switch (name) {
+            case ADMIN_STATE:
+                if (!validState(ADMINSTATES, name, value)) {
+                    return false;
+                }
+                break;
+            case PASSWORD:
+                if (!value.matches(PASSWORD_PATTERN)) {
+                    log.error("Invalid value for Name {} : Value {}.", name, value);
+                    return false;
+                }
+                break;
+            default:
+                if (!validState(ENABLES, name, value)) {
+                    return false;
+                }
+                break;
+        }
+        return true;
+    }
+
+    /**
+     * Verifies input string for valid options.
+     *
+     * @param states input data in string for parameter state
+     * @param name input data in string for parameter name
+     * @param value input data in string for parameter value
+     * @return true if the param is valid
+     * @return false if the param is invalid
+     */
+    private boolean validState(Set<String> states, String name, String value) {
+        if (!states.contains(value)) {
+            log.error("Invalid value for Name {} : Value {}.", name, value);
+            return false;
+        }
+        return true;
+    }
+
 }
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
index 4e05001..d8c64c6 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
@@ -79,13 +79,8 @@
     private static final int LOF_THRESHOLD_MAX = 10;
     private static final int LOS_THRESHOLD_MIN = 1;
     private static final int LOS_THRESHOLD_MAX = 10;
-    private static final int FIRST_PART = 0;
-    private static final int SECOND_PART = 1;
-    private static final int THIRD_PART = 2;
     private static final int RANGE_MIN = 0;
     private static final int RANGE_MAX = 1;
-    private static final int ZERO = 0;
-    private static final int THREE = 3;
 
     @Override
     public String getPonLinks(String target) {
@@ -100,7 +95,7 @@
             log.warn("Not master for {} Use {} to execute command",
                      ncDeviceId,
                      mastershipService.getMasterFor(ncDeviceId));
-            return reply;
+            return null;
         }
 
         try {
@@ -114,11 +109,11 @@
                     pon = Integer.parseInt(target);
                     if (pon <= ZERO) {
                         log.error("Invalid integer for ponlink-id:{}", target);
-                        return reply;
+                        return null;
                     }
                 } catch (NumberFormatException e) {
                     log.error("Non-number input for ponlink-id:{}", target);
-                    return reply;
+                    return null;
                 }
                 request.append(buildStartTag(GPON_PONLINK_PORTS));
                 request.append(buildStartTag(GPON_PONLINK_PORT));
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtility.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtility.java
index 92df893..358504c 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtility.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtility.java
@@ -42,6 +42,14 @@
     public static final String VOLT_NE_OPEN = ANGLE_LEFT + VOLT_NE + SPACE;
     public static final String VOLT_NE_CLOSE = ANGLE_LEFT + SLASH + VOLT_NE + ANGLE_RIGHT;
 
+    public static final int FIRST_PART = 0;
+    public static final int SECOND_PART = 1;
+    public static final int THIRD_PART = 2;
+    public static final int ZERO = 0;
+    public static final int ONE = 1;
+    public static final int TWO = 2;
+    public static final int THREE = 3;
+
     private FujitsuVoltXmlUtility() {
         // Preventing any allocation
     }
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java
index e25aae0..4e52429 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java
@@ -52,9 +52,6 @@
     private static final String TEST_VOLT_OFCONFIG = "volt-ofconfig";
     private static final String TEST_OFCONFIG_ID = "ofconfig-id";
     private static final String TEST_END_LICENSE_HEADER = "-->";
-    private static final int FIRST_PART = 0;
-    private static final int SECOND_PART = 1;
-    private static final int THIRD_PART = 2;
 
     private static final Map<Integer, String> GET_CONTROLLERS = new HashMap<Integer, String>() {
         {
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java
new file mode 100644
index 0000000..b18a5ab
--- /dev/null
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java
@@ -0,0 +1,417 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.drivers.fujitsu;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
+
+
+/**
+ * Unit tests for methods of FujitsuVoltOnuConfig.
+ */
+public class FujitsuVoltOnuConfigTest {
+
+    private FujitsuNetconfControllerMock controller;
+    private FujitsuDriverHandlerAdapter driverHandler;
+    private FujitsuVoltOnuConfig voltConfig;
+
+    private final FujitsuNetconfSessionListenerTest listener = new InternalSessionListenerTest();
+
+    private static final String TEST_VOLT_ONUS = "volt-onus";
+    private static final String TEST_ONUS_PERLINK = "onus-perlink";
+    private static final String TEST_ONUS_LIST = "onus-list";
+    private static final String TEST_ONU_INFO = "onu-info";
+    private static final String TEST_ONU_SET_CONFIG = "onu-set-config";
+    private static final String TEST_CONFIG_INFO = "config-info";
+    private static final String TEST_VOLT_STATISTICS = "volt-statistics";
+    private static final String TEST_ONU_STATISTICS = "onu-statistics";
+    private static final String TEST_ONU_ETH_STATS = "onu-eth-stats";
+    private static final String TEST_ETH_STATS = "eth-stats";
+    private static final String TEST_ONU_GEM_STATS = "onu-gem-stats";
+    private static final String TEST_GEM_STATS = "gem-stats";
+
+    private static final String TEST_ONU_SET_CONFIG_WITH_NAMESPACE =
+            TEST_ANGLE_LEFT + TEST_ONU_SET_CONFIG + TEST_SPACE +
+            TEST_VOLT_NE_NAMESPACE;
+
+    private static final Map<Integer, String> INVALID_GET_TCS = new HashMap<Integer, String>() {
+        {
+            put(1, "a-b");
+            put(2, "--1-2");
+            put(3, "s-1");
+            put(4, "16-1-1");
+            put(5, "1 A-1");
+            put(6, "1*A-1");
+        }
+    };
+    private static final Map<Integer, String> VALID_GET_TCS = new HashMap<Integer, String>() {
+        {
+            put(1, "1");
+            put(2, "1-2");
+            put(3, null);
+        }
+    };
+    private static final Map<Integer, String> INVALID_SET_TCS = new HashMap<Integer, String>() {
+        {
+            put(1, "-11-3:admin-state:enable");
+            put(2, "1-2:admin-state:false");
+            put(3, "1-2:pm-enable:123");
+            put(4, "^1-2:pm-enable:false");
+            put(5, "1-2:fec-enable:xyz");
+            put(6, "1-2:security-enable:123abc");
+            put(7, "2-3:password:-1&");
+            put(8, "2:admin-state:disable");
+        }
+    };
+    private static final Map<Integer, String> VALID_SET_TCS = new HashMap<Integer, String>() {
+        {
+            put(1, "1-11:admin-state:disable");
+            put(2, "8-1:pm-enable:true");
+            put(3, "1-1:fec-enable:true");
+            put(4, "1-21:security-enable:false");
+            put(5, "3-2:password:abc123");
+        }
+    };
+    private static final Map<Integer, String> INVALID_GET_STATS_TCS = new HashMap<Integer, String>() {
+        {
+            put(1, "1-a");
+            put(2, "1:1");
+            put(3, "a-1");
+            put(4, "1-1-1");
+            put(5, "2 A-1");
+            put(6, "2/A-1");
+        }
+    };
+    private static final Map<Integer, String> VALID_GET_STATS_TCS = new HashMap<Integer, String>() {
+        {
+            put(1, "1");
+            put(2, "3-12");
+            put(3, null);
+        }
+    };
+    private Integer currentKey;
+
+
+    @Before
+    public void setUp() throws Exception {
+        controller = new FujitsuNetconfControllerMock();
+        driverHandler = controller.setUp(listener);
+        voltConfig = new FujitsuVoltOnuConfig();
+        voltConfig.setHandler(driverHandler);
+    }
+
+    /**
+     * Run to verify handling of invalid input for get operation.
+     */
+    @Test
+    public void testInvalidGetOnusInput() throws Exception {
+        String reply;
+        String target;
+
+        for (Integer key : INVALID_GET_TCS.keySet()) {
+            target = INVALID_GET_TCS.get(key);
+            reply = voltConfig.getOnus(target);
+            assertNull("Incorrect response for " + target, reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of valid input for get operation.
+     */
+    @Test
+    public void testValidGetOnus() throws Exception {
+        String reply;
+        String target;
+
+        for (Integer key : VALID_GET_TCS.keySet()) {
+            target = VALID_GET_TCS.get(key);
+            currentKey = key;
+            reply = voltConfig.getOnus(target);
+            assertNotNull("Incorrect response for " + target, reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of invalid input for set operation.
+     */
+    @Test
+    public void testInvalidSetOnuInput() throws Exception {
+        String target;
+        String reply;
+
+        for (Integer key : INVALID_SET_TCS.keySet()) {
+            target = INVALID_SET_TCS.get(key);
+            reply = voltConfig.setOnu(target);
+            assertNull("Incorrect response for " + target, reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of valid input for set operation.
+     */
+    @Test
+    public void testValidSetOnu() throws Exception {
+        String target;
+        String reply;
+
+        for (Integer key : VALID_SET_TCS.keySet()) {
+            target = VALID_SET_TCS.get(key);
+            currentKey = key;
+            reply = voltConfig.setOnu(target);
+            assertNotNull("Incorrect response for " + target, reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of invalid input for get statistics operation.
+     */
+    @Test
+    public void testInvalidGetOnuStatsInput() throws Exception {
+        String reply;
+        String target;
+
+        for (Integer key : INVALID_GET_STATS_TCS.keySet()) {
+            target = INVALID_GET_STATS_TCS.get(key);
+            reply = voltConfig.getOnuStatistics(target);
+            assertNull("Incorrect response for " + target, reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of valid input for get statistics operation.
+     */
+    @Test
+    public void testValidGetOnuStats() throws Exception {
+        String reply;
+        String target;
+
+        for (Integer key : VALID_GET_STATS_TCS.keySet()) {
+            target = VALID_GET_STATS_TCS.get(key);
+            currentKey = key;
+            reply = voltConfig.getOnuStatistics(target);
+            assertNotNull("Incorrect response for " + target, reply);
+        }
+    }
+
+    /**
+     * Verifies XML request string by comparing with generated string.
+     *
+     * @param request XML string for get operation
+     * @return true if XML string matches with generated
+     */
+    private boolean verifyGetRequest(String request) {
+        StringBuilder rpc = new StringBuilder();
+        String target = VALID_GET_TCS.get(currentKey);
+        String[] onuId = null;
+
+        if (target != null) {
+            onuId = target.split(TEST_HYPHEN);
+        }
+
+        rpc.append(TEST_VOLT_NE_OPEN).append(TEST_VOLT_NE_NAMESPACE);
+        rpc.append(TEST_ANGLE_RIGHT).append(TEST_NEW_LINE);
+        if (onuId != null) {
+            rpc.append(startTag(TEST_VOLT_ONUS));
+            rpc.append(startTag(TEST_ONUS_PERLINK));
+            rpc.append(startTag(TEST_PONLINK_ID, false));
+            rpc.append(onuId[FIRST_PART]);
+            rpc.append(endTag(TEST_PONLINK_ID));
+            if (onuId.length > ONE) {
+                rpc.append(startTag(TEST_ONUS_LIST));
+                rpc.append(startTag(TEST_ONU_INFO));
+                rpc.append(startTag(TEST_ONU_ID, false));
+                rpc.append(onuId[SECOND_PART]);
+                rpc.append(endTag(TEST_ONU_ID));
+                rpc.append(endTag(TEST_ONU_INFO));
+                rpc.append(endTag(TEST_ONUS_LIST));
+            }
+            rpc.append(endTag(TEST_ONUS_PERLINK));
+            rpc.append(endTag(TEST_VOLT_ONUS));
+        } else {
+            rpc.append(emptyTag(TEST_VOLT_ONUS));
+        }
+        rpc.append(TEST_VOLT_NE_CLOSE);
+
+        String testRequest = rpc.toString();
+        testRequest = testRequest.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING);
+        request = request.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING);
+        boolean result = request.equals(testRequest);
+        assertTrue("Does not match with generated string", result);
+        return result;
+    }
+
+    /**
+     * Verifies XML request string by comparing with generated string.
+     *
+     * @param request XML string for set operation
+     * @return true or false
+     */
+    private boolean verifyWrappedRpcRequest(String request) {
+        StringBuilder rpc = new StringBuilder();
+        String target = VALID_SET_TCS.get(currentKey);
+        String[] data = target.split(TEST_COLON);
+        String[] onuId = data[FIRST_PART].split(TEST_HYPHEN);
+
+        rpc.append(TEST_ANGLE_LEFT).append(TEST_ONU_SET_CONFIG).append(TEST_SPACE);
+        rpc.append(TEST_VOLT_NE_NAMESPACE).append(TEST_ANGLE_RIGHT).append(TEST_NEW_LINE);
+        rpc.append(startTag(TEST_PONLINK_ID, false));
+        rpc.append(onuId[FIRST_PART]);
+        rpc.append(endTag(TEST_PONLINK_ID));
+        rpc.append(startTag(TEST_ONU_ID, false));
+        rpc.append(onuId[SECOND_PART]);
+        rpc.append(endTag(TEST_ONU_ID));
+        rpc.append(startTag(TEST_CONFIG_INFO));
+        rpc.append(startTag(data[SECOND_PART], false));
+        rpc.append(data[THIRD_PART]);
+        rpc.append(endTag(data[SECOND_PART]));
+        rpc.append(endTag(TEST_CONFIG_INFO));
+        rpc.append(endTag(TEST_ONU_SET_CONFIG));
+
+        String testRequest = rpc.toString();
+        testRequest = testRequest.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING);
+        request = request.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING);
+        boolean result = request.equals(testRequest);
+        assertTrue("Does not match with generated string", result);
+        return result;
+    }
+
+    /**
+     * Verifies XML request string by comparing with generated string (statistics).
+     *
+     * @param request XML string for get operation
+     * @return true if XML string matches with generated
+     */
+    private boolean verifyGetRequestForStats(String request) {
+        StringBuilder rpc = new StringBuilder();
+        String target = VALID_GET_STATS_TCS.get(currentKey);
+        String[] onuId = null;
+
+        if (target != null) {
+            onuId = target.split(TEST_HYPHEN);
+        }
+
+        rpc.append(TEST_VOLT_NE_OPEN).append(TEST_VOLT_NE_NAMESPACE);
+        rpc.append(TEST_ANGLE_RIGHT).append(TEST_NEW_LINE);
+        rpc.append(startTag(TEST_VOLT_STATISTICS));
+        if (onuId != null) {
+            rpc.append(startTag(TEST_ONU_STATISTICS));
+            rpc.append(startTag(TEST_ONU_GEM_STATS));
+            rpc.append(startTag(TEST_GEM_STATS));
+            rpc.append(startTag(TEST_PONLINK_ID, false));
+            rpc.append(onuId[FIRST_PART]);
+            rpc.append(endTag(TEST_PONLINK_ID));
+            if (onuId.length > ONE) {
+                rpc.append(startTag(TEST_ONU_ID, false));
+                rpc.append(onuId[SECOND_PART]);
+                rpc.append(endTag(TEST_ONU_ID));
+            }
+            rpc.append(endTag(TEST_GEM_STATS));
+            rpc.append(endTag(TEST_ONU_GEM_STATS));
+
+            rpc.append(startTag(TEST_ONU_ETH_STATS));
+            rpc.append(startTag(TEST_ETH_STATS));
+            rpc.append(startTag(TEST_PONLINK_ID, false));
+            rpc.append(onuId[FIRST_PART]);
+            rpc.append(endTag(TEST_PONLINK_ID));
+            if (onuId.length > ONE) {
+                rpc.append(startTag(TEST_ONU_ID, false));
+                rpc.append(onuId[SECOND_PART]);
+                rpc.append(endTag(TEST_ONU_ID));
+            }
+            rpc.append(endTag(TEST_ETH_STATS));
+            rpc.append(endTag(TEST_ONU_ETH_STATS));
+            rpc.append(endTag(TEST_ONU_STATISTICS));
+        } else {
+            rpc.append(emptyTag(TEST_ONU_STATISTICS));
+        }
+        rpc.append(endTag(TEST_VOLT_STATISTICS));
+        rpc.append(TEST_VOLT_NE_CLOSE);
+
+        String testRequest = rpc.toString();
+        testRequest = testRequest.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING);
+        request = request.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING);
+        boolean result = request.equals(testRequest);
+        assertTrue("Does not match with generated string", result);
+        return result;
+    }
+
+    /**
+     * Internal listener for device service events.
+     */
+    private class InternalSessionListenerTest implements FujitsuNetconfSessionListenerTest {
+        @Override
+        public boolean verifyEditConfig(String request) {
+            return false;
+        }
+
+        @Override
+        public boolean verifyEditConfig(String target, String mode, String request) {
+            return false;
+        }
+
+        @Override
+        public boolean verifyGet(String filterSchema, String withDefaultsMode) {
+            boolean result;
+            boolean forStats;
+
+            assertTrue("Incorrect withDefaultsMode", withDefaultsMode.equals(TEST_REPORT_ALL));
+            filterSchema = filterSchema.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
+            assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
+                    filterSchema.contains(TEST_VOLT_NAMESPACE));
+
+            forStats = filterSchema.contains(TEST_VOLT_STATISTICS);
+            if (forStats) {
+                result = verifyGetRequestForStats(filterSchema);
+            } else {
+                result = verifyGetRequest(filterSchema);
+            }
+            assertTrue("XML verification failure", result);
+            return result;
+        }
+
+        @Override
+        public String buildGetReply() {
+            return null;
+        }
+
+        @Override
+        public boolean verifyWrappedRpc(String request) {
+            boolean result;
+
+            request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
+            assertTrue("Does not contain:" + TEST_ONU_SET_CONFIG_WITH_NAMESPACE,
+                    request.contains(TEST_ONU_SET_CONFIG_WITH_NAMESPACE));
+
+            result = verifyWrappedRpcRequest(request);
+            assertTrue("XML verification failure", result);
+            return result;
+        }
+
+        @Override
+        public void verifyStartSubscription(String filterSchema) {
+        }
+    }
+
+}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
index 3229b8c..399c521 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
@@ -42,9 +42,6 @@
     private static final String TEST_VOLT_PORTS = "volt-ports";
     private static final String TEST_GPON_PONLINK_PORTS = "gpon-ponlink-ports";
     private static final String TEST_GPON_PONLINK_PORT = "gpon-ponlink-port";
-    private static final int FIRST_PART = 0;
-    private static final int SECOND_PART = 1;
-    private static final int THIRD_PART = 2;
 
     private static final Map<Integer, String> INVALID_GET_TCS = new HashMap<Integer, String>() {
         {
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtilityMock.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtilityMock.java
index 89d5ab9..e9200a3 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtilityMock.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltXmlUtilityMock.java
@@ -55,6 +55,10 @@
     public static final String TEST_VOLT_NAMESPACE = TEST_VOLT_NE_OPEN +
             TEST_VOLT_NE_NAMESPACE;
 
+    public static final int FIRST_PART = 0;
+    public static final int SECOND_PART = 1;
+    public static final int THIRD_PART = 2;
+    public static final int ONE = 1;
 
     private FujitsuVoltXmlUtilityMock() {
     }