[ONOS-3161]UT for port pair web resource

Change-Id: I81a98b9407305f572eec999f9555dd4a6bc4e808
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
index 8bf459c..b901289 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
@@ -42,7 +42,9 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 /**
@@ -67,8 +69,13 @@
     public Response getPortPairs() {
         Iterable<PortPair> portPairs = service.getPortPairs();
         ObjectNode result = new ObjectMapper().createObjectNode();
-        result.set("port_pairs", new PortPairCodec().encode(portPairs, this));
-        return ok(result).build();
+        ArrayNode portPairEntry = result.putArray("port_pairs");
+        if (portPairs != null) {
+            for (final PortPair portPair : portPairs) {
+                portPairEntry.add(new PortPairCodec().encode(portPair, this));
+            }
+        }
+        return ok(result.toString()).build();
     }
 
     /**
@@ -80,18 +87,15 @@
     @GET
     @Path("{pair_id}")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getPortPair(@PathParam("portPairId") String id) {
+    public Response getPortPair(@PathParam("pair_id") String id) {
 
         if (!service.exists(PortPairId.of(id))) {
-            return Response.status(NOT_FOUND)
-                    .entity(PORT_PAIR_NOT_FOUND).build();
+            return Response.status(NOT_FOUND).entity(PORT_PAIR_NOT_FOUND).build();
         }
-        PortPair portPair = nullIsNotFound(service.getPortPair(PortPairId.of(id)),
-                                           PORT_PAIR_NOT_FOUND);
-
+        PortPair portPair = nullIsNotFound(service.getPortPair(PortPairId.of(id)), PORT_PAIR_NOT_FOUND);
         ObjectNode result = new ObjectMapper().createObjectNode();
         result.set("port_pair", new PortPairCodec().encode(portPair, this));
-        return ok(result).build();
+        return ok(result.toString()).build();
     }
 
     /**
@@ -106,11 +110,11 @@
     @Produces(MediaType.APPLICATION_JSON)
     public Response createPortPair(InputStream stream) {
         try {
-            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-
-            PortPair portPair = codec(PortPair.class).decode(jsonTree, this);
-            Boolean isSuccess = nullIsNotFound(service.createPortPair(portPair),
-                                               PORT_PAIR_NOT_FOUND);
+            ObjectMapper mapper = new ObjectMapper();
+            ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+            JsonNode port = jsonTree.get("port_pair");
+            PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this);
+            Boolean isSuccess = nullIsNotFound(service.createPortPair(portPair), PORT_PAIR_NOT_FOUND);
             return Response.status(OK).entity(isSuccess.toString()).build();
         } catch (IOException e) {
             log.error("Exception while creating port pair {}.", e.toString());
@@ -132,8 +136,10 @@
     public Response updatePortPair(@PathParam("pair_id") String id,
                                    final InputStream stream) {
         try {
-            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-            PortPair portPair = codec(PortPair.class).decode(jsonTree, this);
+            ObjectMapper mapper = new ObjectMapper();
+            ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+            JsonNode port = jsonTree.get("port_pair");
+            PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this);
             Boolean isSuccess = nullIsNotFound(service.updatePortPair(portPair), PORT_PAIR_NOT_FOUND);
             return Response.status(OK).entity(isSuccess.toString()).build();
         } catch (IOException e) {
@@ -152,8 +158,7 @@
     public void deletePortPair(@PathParam("pair_id") String id) {
 
         PortPairId portPairId = PortPairId.of(id);
-        Boolean isSuccess = nullIsNotFound(service.removePortPair(portPairId),
-                                           PORT_PAIR_NOT_FOUND);
+        Boolean isSuccess = nullIsNotFound(service.removePortPair(portPairId), PORT_PAIR_NOT_FOUND);
         if (!isSuccess) {
             log.debug("Port pair identifier {} does not exist", id);
         }