Fix ServiceExecutorImpl 23/76223/3
authorJoss Armstrong <joss.armstrong@ericsson.com>
Wed, 23 Jan 2019 18:17:31 +0000 (18:17 +0000)
committerTakamune Cho <takamune.cho@att.com>
Thu, 24 Jan 2019 19:39:37 +0000 (19:39 +0000)
Code change to fix handling of vserver-id

Issue-ID: APPC-1358
Change-Id: I463fceda2321b5006100b12644708d22fe25a04e
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImpl.java
appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImplTest.java
appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/utils/ServiceConstantsTest.java [deleted file]

index 67b9c6f..ee83c87 100644 (file)
@@ -102,24 +102,28 @@ public class ServiceExecutorImpl {
             int vm_count = Integer.parseInt(ctx.getAttribute("vm-count"));
                 for(Request inprogressRequest:inProgressRequests){
                     if(inprogressRequest.getActionIdentifiers().getVnfcName() != null){
-                    for (int i = 0; i < vm_count; i++) {
-                        if (ctx.getAttribute("vm[" + i + "].vnfc-name") != null && ctx.getAttribute("vm[" + i + "].vnfc-name")
-                        .equals(inprogressRequest.getActionIdentifiers().getVnfcName()))
-                            inProgressVServerIds.add(ctx.getAttribute("vm[" + i + "].vserver-id"));
-                        log.debug("Received vserver-id from AAI: " + inProgressVServerIds);
+                        for (int i = 0; i < vm_count; i++) {
+                            if (ctx.getAttribute("vm[" + i + "].vnfc-name") != null && ctx.getAttribute("vm[" + i + "].vnfc-name")
+                                    .equals(inprogressRequest.getActionIdentifiers().getVnfcName())) {
+                                String newInProgressVserverId = ctx.getAttribute("vm[" + i + "].vserver-id");
+                                inProgressVServerIds.add(newInProgressVserverId);
+                                log.debug("Received vserver-id from AAI: " + newInProgressVserverId);
+                            }
+                        }
                     }
-                }
             }
             for(Request inProgVserverIds:inProgressRequests)
                 if(inProgVserverIds.getActionIdentifiers().getvServerId() != null)
                     inProgressVServerIds.add(inProgVserverIds.getActionIdentifiers().getvServerId());
             if(currentRequestVnfcName != null){
-                for (int i = 0; i < vm_count; i++)
+                for (int i = 0; i < vm_count; i++) {
                     if (ctx.getAttribute("vm[" + i + "].vnfc-name") != null && ctx.getAttribute("vm[" + i + "].vnfc-name")
-                            .equals(currentRequestVnfcName))
-                 currentVnfcVserverId = ctx.getAttribute("vm[" + i + "].vserver-id");
-                log.debug("Received vserver-id from AAI: " + currentVnfcVserverId);
-                return inProgressVServerIds.contains(currentVnfcVserverId);
+                            .equals(currentRequestVnfcName)) {
+                        currentVnfcVserverId = ctx.getAttribute("vm[" + i + "].vserver-id");
+                        log.debug("Received vserver-id from AAI: " + currentVnfcVserverId);
+                        return inProgressVServerIds.contains(currentVnfcVserverId);
+                    }
+                }
             }
             for (Request request : inProgressRequests) {
                 if(!Strings.isNullOrEmpty(currentRequestVServerId)  && currentRequestVServerId.equalsIgnoreCase(request.getActionIdentifiers().getvServerId()))
index 6cdca79..040723f 100644 (file)
@@ -123,6 +123,7 @@ public class ServiceExecutorImplTest {
         Mockito.doReturn(aaiServiceMock).when(executor).getAaiService(Mockito.any(AAIClient.class));
         SvcLogicContext ctx = new SvcLogicContext();
         ctx.setAttribute("vm-count", "1");
+        ctx.setAttribute("vm[0].vnfc-name", "vnfc-name1");
         Mockito.doReturn(ctx).when(executor).getSvcLogicContext();
         assertEquals("\"requestOverlap\"  : false", executor.isRequestOverLap(requestData));
     }
@@ -144,6 +145,25 @@ public class ServiceExecutorImplTest {
         assertEquals("\"requestOverlap\"  : false", executor.isRequestOverLap(requestData));
     }
 
+    @Test
+    public void testScopeOverlapWithVnfcNameAndInProgressRequestAndContextVariables() throws Exception {
+        executor = Mockito.spy(new ServiceExecutorImpl());
+        String requestData = "{\"vnf-id\":\"\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :"
+                + " \"service-instance-id\",\"vnfc-name\" : \"vnfc-name\"}},\"in-progress-requests\" :"
+                + " [{\"target-id\": \"vnf-id1\",\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" :"
+                + " \"service-instance-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vserver-id\": \"vserver-id1\"}},{\"action\" :"
+                + " \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnfc-name\" :"
+                + " \"vnfc-name2\",\"vserver-id\": \"vserver-id2\"}}]}";
+        AaiService aaiServiceMock = Mockito.mock(AaiService.class);
+        Mockito.doReturn(aaiServiceMock).when(executor).getAaiService(Mockito.any(AAIClient.class));
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("vm-count", "1");
+        ctx.setAttribute("vm[0].vnfc-name", "vnfc-name");
+        ctx.setAttribute("vm[0].vserverid", "vnfc-name");
+        Mockito.doReturn(ctx).when(executor).getSvcLogicContext();
+        assertEquals("\"requestOverlap\"  : false", executor.isRequestOverLap(requestData));
+    }
+
     @Test
     public void testScopeOverlapExceptionFlow() throws Exception {
         executor = Mockito.spy(new ServiceExecutorImpl());
diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/utils/ServiceConstantsTest.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/utils/ServiceConstantsTest.java
deleted file mode 100644 (file)
index 64d150a..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-* ============LICENSE_START=======================================================
-* ONAP : APPC
-* ================================================================================
-* Copyright 2018 TechMahindra
-* ================================================================================
-* Modifications Copyright (C) 2019 Ericsson
-*=================================================================================
-* 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.
-* ============LICENSE_END=========================================================
-*/
-package org.onap.appc.interfaces.service.utils;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ServiceConstantsTest {
-
-    @Test
-    public void testServiceConstants() {
-        Assert.assertEquals("action-identifiers", ServiceConstants.ACTIONIDENTIFIER);
-    }
-
-}