FIX: to support delete operation for list node under a module

Change-Id: Id71503a2206be648e91d84265f92c0a18ac90e67
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java
index 0620420..831aa79 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java
@@ -86,11 +86,24 @@
         YdtAppNodeOperationType opType = getAppOpTypeFromYdtOpType(ydtOpType);
         YdtAppContext curNode = this;
         YdtAppNodeOperationType parentOpType = operationType;
-        if (parentOpType != null && opType != parentOpType) {
-            while (curNode.getOperationType() != BOTH &&
-                    curNode.getParent() != null) {
-                curNode.setOperationType(BOTH);
-                curNode = curNode.getParent();
+        if (opType != parentOpType) {
+            if (parentOpType != null) {
+                while (curNode.getOperationType() != BOTH &&
+                        curNode.getParent() != null) {
+                    curNode.setOperationType(BOTH);
+                    curNode = curNode.getParent();
+                }
+            } else {
+                // If operation type for ydt node is "NONE" then in that
+                // case operation type for module node in app tree set as null.
+                // Once the target node operation type received by ydt then
+                // operation type for module node will be updated with the
+                // same target node operation type in app tree.
+                while (curNode.getParent() != null && curNode
+                        .getOperationType() == null) {
+                    curNode.setOperationType(opType);
+                    curNode = curNode.getParent();
+                }
             }
         }
     }
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
index cd37eea..e5e9f86 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
@@ -25,6 +25,7 @@
 import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
 import org.onosproject.yms.app.ydt.exceptions.YdtException;
 import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ydt.YdtContext;
 import org.onosproject.yms.ydt.YdtContextOperationType;
 import org.onosproject.yms.ydt.YdtType;
 import org.onosproject.yms.ydt.YmsOperationType;
@@ -569,7 +570,10 @@
 
             // If node is of multiInstanceNode type then check key uniqueness.
             if (curNode.getYdtType() == MULTI_INSTANCE_NODE) {
-                curNode.createKeyNodeList();
+                List<YdtContext> keyList = ((YdtMultiInstanceNode) curNode).getKeyNodeList();
+                if (keyList == null || keyList.isEmpty()) {
+                    curNode.createKeyNodeList();
+                }
             }
 
             /*
@@ -679,6 +683,7 @@
                 }
 
                 curNode = curNode.getParent();
+                curNode.createKeyNodeList();
             }
         } catch (YdtException e) {
             freeRestResources(rootNode);
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/FoodArenaTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/FoodArenaTest.java
index 7f058a9..9754192 100644
--- a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/FoodArenaTest.java
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/FoodArenaTest.java
@@ -22,11 +22,16 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.DELETE_ONLY;
 import static org.onosproject.yms.app.ydt.YdtTestUtils.foodArenaYdt;
+import static org.onosproject.yms.app.ydt.YdtTestUtils.getYdtBuilder;
 import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
 import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
 import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree;
+import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE;
 import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
 
 public class FoodArenaTest {
 
@@ -56,6 +61,19 @@
     }
 
     /**
+     * Creates and validates food arena ydt.
+     */
+    @Test
+    public void foodArenaDeleteOperationTest() throws IOException {
+
+        YangRequestWorkBench ydtBuilder;
+        ydtBuilder = getYdtBuilder("foodarena", "food", "ydt.food", NONE);
+        ydtBuilder.addChild("food", "ydt.food", DELETE);
+        YdtAppContext appRootNode = ydtBuilder.getAppRootNode();
+        assertEquals(appRootNode.getFirstChild().getOperationType(), DELETE_ONLY);
+    }
+
+    /**
      * Validates the given built ydt.
      */
     private void validateTree(YangRequestWorkBench ydtBuilder) {