diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-01-23 12:38:05 +0000 |
---|---|---|
committer | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-01-23 12:38:18 +0000 |
commit | 425988fd78defd866d2e02dc9523764be2ec0a51 (patch) | |
tree | 8f33e0de3971d7f2837b124252584598b346d5f0 /appc-inbound/appc-interfaces-service/bundle | |
parent | 4d39d0e04eabcfb741852c6871a80ac76e40338f (diff) |
Test coverage in interface-services-executorImpl
Increased coverage from 39% to 93%
Issue-ID: APPC-1354
Change-Id: I372be6e61e6041dbf81607d4386fc5123fa5ee79
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-inbound/appc-interfaces-service/bundle')
7 files changed, 237 insertions, 37 deletions
diff --git a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executor/ExecutorException.java b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executor/ExecutorException.java index c20a84f06..9d065afda 100644 --- a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executor/ExecutorException.java +++ b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executor/ExecutorException.java @@ -1,4 +1,25 @@ -package org.onap.appc.interfaces.service.executor; +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * 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.executor; public class ExecutorException extends Exception{ diff --git a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImpl.java b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImpl.java index cafa8dc18..67b9c6f2e 100644 --- a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImpl.java +++ b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImpl.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * 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 @@ -41,12 +43,12 @@ public class ServiceExecutorImpl { private static final EELFLogger log = EELFManager.getInstance().getLogger(ServiceExecutorImpl.class); private AAIClient aaiClient; + public String isRequestOverLap(String requestData) throws Exception { String response = "\"requestOverlap\" : "; log.info("Response from ServiceExecutorImpl"); - ScopeOverlap scopeOverlap = new ScopeOverlap(); - ObjectMapper mapper = new ObjectMapper(); - scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class); + ObjectMapper mapper = getObjectMapper(); + ScopeOverlap scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class); // return response + String.valueOf(checkForOverLap(scopeOverlap)); boolean isOverlap = checkForOverLap(scopeOverlap); scopeOverlap.setOverlap(String.valueOf(isOverlap)); @@ -67,9 +69,6 @@ public class ServiceExecutorImpl { }else if ( scopeOverlap.getInProgressRequest().isEmpty()){ return Boolean.FALSE; } - else if (scopeOverlap.getInProgressRequest().size() == 0) { - return Boolean.FALSE; - } if (scopeOverlap.getCurrentRequest().getActionIdentifiers().getVnfId() != null) { return Boolean.TRUE; } else if (!Strings.isNullOrEmpty(scopeOverlap.getVnfId()) @@ -88,9 +87,9 @@ public class ServiceExecutorImpl { } private boolean isVnfcNameOverLap(ScopeOverlap scopeOverlap) throws Exception { - - AaiService aaiService =new AaiService(aaiClient); - SvcLogicContext ctx = new SvcLogicContext(); + + AaiService aaiService = getAaiService(aaiClient); + SvcLogicContext ctx = getSvcLogicContext(); Map<String, String> params = new HashMap<String, String>(); List<String> inProgressVServerIds = new ArrayList<String>(); String currentVnfcVserverId = new String(); @@ -101,25 +100,25 @@ public class ServiceExecutorImpl { try { aaiService.getGenericVnfInfo(params, ctx); int vm_count = Integer.parseInt(ctx.getAttribute("vm-count")); - for(Request inprogressRequest:inProgressRequests){ + for(Request inprogressRequest:inProgressRequests){ if(inprogressRequest.getActionIdentifiers().getVnfcName() != 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(inprogressRequest.getActionIdentifiers().getVnfcName())) inProgressVServerIds.add(ctx.getAttribute("vm[" + i + "].vserver-id")); - log.debug("Received vserver-id from AAI: "+ inProgressVServerIds); + log.debug("Received vserver-id from AAI: " + inProgressVServerIds); } } } for(Request inProgVserverIds:inProgressRequests) - if(inProgVserverIds.getActionIdentifiers().getvServerId()!=null) + if(inProgVserverIds.getActionIdentifiers().getvServerId() != null) inProgressVServerIds.add(inProgVserverIds.getActionIdentifiers().getvServerId()); if(currentRequestVnfcName != null){ 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); + log.debug("Received vserver-id from AAI: " + currentVnfcVserverId); return inProgressVServerIds.contains(currentVnfcVserverId); } for (Request request : inProgressRequests) { @@ -140,11 +139,11 @@ public class ServiceExecutorImpl { private boolean isVserverOrVnfcIdOverLap(ScopeOverlap scopeOverlap) throws Exception { List<Request> inProgressRequests = scopeOverlap.getInProgressRequest(); for (Request request : inProgressRequests) { - if(request.getActionIdentifiers().getVnfId()!= null) + if(request.getActionIdentifiers().getVnfId() != null) return Boolean.TRUE ; } for (Request request : inProgressRequests) { - if(request.getActionIdentifiers().getVfModuleId()!= null) + if(request.getActionIdentifiers().getVfModuleId() != null) return Boolean.TRUE ; } String currentVserverID = scopeOverlap.getCurrentRequest().getActionIdentifiers().getvServerId(); @@ -157,9 +156,9 @@ public class ServiceExecutorImpl { private boolean isVnfIdOverlap(ScopeOverlap scopeOverlap) throws Exception { List<Request> inProgressRequests = scopeOverlap.getInProgressRequest(); - log.info("inProgressRequests list"+inProgressRequests.toString()); + log.info("inProgressRequests list" + inProgressRequests.toString()); for (Request request : inProgressRequests) { - log.info("request list"+request.getTargetId()); + log.info("request list" + request.getTargetId()); if (!Strings.isNullOrEmpty(scopeOverlap.getVnfId()) && !Strings.isNullOrEmpty(request.getTargetId()) && (request.getTargetId() @@ -168,4 +167,16 @@ public class ServiceExecutorImpl { } return Boolean.FALSE; } + + protected ObjectMapper getObjectMapper() { + return new ObjectMapper(); + } + + protected AaiService getAaiService(AAIClient aaiClient) { + return new AaiService(aaiClient); + } + + protected SvcLogicContext getSvcLogicContext() { + return new SvcLogicContext(); + } } diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestRequestValidator.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestRequestValidator.java index 73e45080e..e641b499e 100644 --- a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestRequestValidator.java +++ b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestRequestValidator.java @@ -3,6 +3,8 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 IBM + * ================================================================================ + * 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. @@ -21,8 +23,6 @@ package org.onap.appc.interfaceService.serviceExecutor; -import static org.junit.Assert.*; - import org.junit.Test; import org.onap.appc.interfaces.service.executor.RequestValidator; diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestServiceExecutor.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestServiceExecutor.java index 6567a2cce..a81d56db0 100644 --- a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestServiceExecutor.java +++ b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaceService/serviceExecutor/TestServiceExecutor.java @@ -7,6 +7,8 @@ * Copyright (C) 2017 Amdocs * ================================================================================ * Modification Copyright (C) 2018 IBM + * ================================================================================ + * 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. @@ -25,10 +27,9 @@ package org.onap.appc.interfaceService.serviceExecutor; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; - import org.onap.appc.interfaces.service.executorImpl.ServiceExecutorImpl; import org.onap.appc.interfaces.service.data.ScopeOverlap; import org.onap.appc.interfaces.service.executor.ServiceExecutor; @@ -70,7 +71,7 @@ public class TestServiceExecutor { @Test(expected = Exception.class) public void serviceExecutorException() throws Exception { ServiceExecutor sei = new ServiceExecutor(); - String action =""; + String action = ""; String requestDataType = ""; String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}"; sei.execute(action, requestData, requestDataType); @@ -79,29 +80,29 @@ public class TestServiceExecutor { @Test public void serviceExecutorRequest() throws Exception { ServiceExecutor sei = new ServiceExecutor(); - String action ="isScopeOverlap"; + String action = "isScopeOverlap"; String requestDataType = ""; String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}"; String actual ="\"requestOverlap\" : true"; String result = sei.execute(action, requestData, requestDataType); - assertEquals(actual,result); + assertEquals(actual, result); } @Test public void serviceExecutorRqsFal() throws Exception { ServiceExecutor sei = new ServiceExecutor(); - String action ="isScopeOverlap"; + String action = "isScopeOverlap"; String requestDataType = ""; String actual ="\"requestOverlap\" : false"; String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}}}"; String result = sei.execute(action, requestData, requestDataType); - assertEquals(actual,result); + assertEquals(actual, result); } @Test(expected = Exception.class) public void serviceExecutorRqstEx() throws Exception { ServiceExecutor sei = new ServiceExecutor(); - String action ="isScopeOverlap"; + String action = "isScopeOverlap"; String requestData = ""; String requestDataType = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"},\"target-id\":\"ibcx0001v\"}]}"; sei.execute(action, requestData, requestDataType); @@ -114,7 +115,7 @@ public class TestServiceExecutor { ScopeOverlap scopeOverlap = new ScopeOverlap(); ObjectMapper mapper = new ObjectMapper(); scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class); - boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap); + boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap); assertEquals(true, result); } @@ -125,7 +126,7 @@ public class TestServiceExecutor { ScopeOverlap scopeOverlap = new ScopeOverlap(); ObjectMapper mapper = new ObjectMapper(); scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class); - boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap); + boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap); assertEquals(true, result); } @@ -136,6 +137,6 @@ public class TestServiceExecutor { ScopeOverlap scopeOverlap = new ScopeOverlap(); ObjectMapper mapper = new ObjectMapper(); scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class); - Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap); + Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap); } } diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executor/ExecutorExceptionTest.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executor/ExecutorExceptionTest.java index 025715910..9e7a96e43 100644 --- a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executor/ExecutorExceptionTest.java +++ b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executor/ExecutorExceptionTest.java @@ -3,6 +3,8 @@ * 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. @@ -24,8 +26,9 @@ import org.junit.Test; public class ExecutorExceptionTest { + @Test - public void testConstructorWithMessaqge() throws Exception { + public void testConstructorWithMessage() throws Exception { String message = "testing message"; ExecutorException executorException = new ExecutorException(message); Assert.assertTrue(executorException.getCause() == null); diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImplTest.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImplTest.java new file mode 100644 index 000000000..6cdca796b --- /dev/null +++ b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/executorImpl/ServiceExecutorImplTest.java @@ -0,0 +1,165 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * 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.executorImpl; + +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; +import org.onap.appc.aai.client.aai.AaiService; +import org.onap.appc.interfaces.service.data.Request; +import org.onap.appc.interfaces.service.data.ScopeOverlap; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceExecutorImplTest { + + private ServiceExecutorImpl executor; + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void testScopeOverlapEmpty() throws Exception { + executor = Mockito.spy(new ServiceExecutorImpl()); + ScopeOverlap scopeOverlap = Mockito.spy(new ScopeOverlap()); + List<Request> emptyList = new ArrayList<Request>(); + Mockito.doReturn(emptyList).when(scopeOverlap).getInProgressRequest(); + ObjectMapper objectMapper = Mockito.spy(new ObjectMapper()); + Mockito.doReturn(objectMapper).when(executor).getObjectMapper(); + Mockito.doReturn(scopeOverlap).when(objectMapper).readValue("{}", ScopeOverlap.class); + assertEquals("\"requestOverlap\" : false", executor.isRequestOverLap("{}")); + } + + @Test + public void testScopeOverlapWithVnfIdInCurrentRequest() throws Exception { + executor = Mockito.spy(new ServiceExecutorImpl()); + String requestData = "{\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\"," + + "\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" :" + + " {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" :" + + " \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\":" + + " \"vserver-id2\"}}]}"; + assertEquals("\"requestOverlap\" : true", executor.isRequestOverLap(requestData)); + } + + @Test + public void testScopeOverlapWithoutVnfIdButWithVfModuleIdCurrentRequest() throws Exception { + executor = Mockito.spy(new ServiceExecutorImpl()); + String requestData = "{\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\"," + + "\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" :" + + " {\"service-instance-id\" : \"service-instance-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" :" + + " \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\":" + + " \"vserver-id2\"}}]}"; + assertEquals("\"requestOverlap\" : true", executor.isRequestOverLap(requestData)); + } + + @Test + public void testScopeOverlapWithVnfIdAndInProgressRequest() throws Exception { + executor = Mockito.spy(new ServiceExecutorImpl()); + String requestData = "{\"vnf-id\":\"vnf-id1\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\"," + + "\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" : [{\"target-id\": \"vnf-id1\",\"action\" : \"HealthCheck\",\"action-identifiers\" :" + + " {\"service-instance-id\" : \"service-instance-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" :" + + " \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\":" + + " \"vserver-id2\"}}]}"; + assertEquals("\"requestOverlap\" : true", executor.isRequestOverLap(requestData)); + } + + @Test + public void testScopeOverlapWithVserverIdAndInProgressRequest() 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\",\"vserver-id\": \"vserver-id\"}},\"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"); + Mockito.doReturn(ctx).when(executor).getSvcLogicContext(); + assertEquals("\"requestOverlap\" : false", executor.isRequestOverLap(requestData)); + } + + @Test + public void testScopeOverlapWithNoVnfcNameInCurrentRequest() throws Exception { + executor = Mockito.spy(new ServiceExecutorImpl()); + String requestData = "{\"vnf-id\":\"\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id\",\"vserver-id\": \"vserver-id\"}},\"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"); + Mockito.doReturn(ctx).when(executor).getSvcLogicContext(); + assertEquals("\"requestOverlap\" : false", executor.isRequestOverLap(requestData)); + } + + @Test + public void testScopeOverlapWithVnfcNameAndInProgressRequest() 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"); + Mockito.doReturn(ctx).when(executor).getSvcLogicContext(); + assertEquals("\"requestOverlap\" : false", executor.isRequestOverLap(requestData)); + } + + @Test + public void testScopeOverlapExceptionFlow() throws Exception { + executor = Mockito.spy(new ServiceExecutorImpl()); + String requestData = "{\"vnf-id\":\"\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :" + + " \"service-instance-id\"}},\"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"); + Mockito.doReturn(ctx).when(executor).getSvcLogicContext(); + expectedEx.expect(Exception.class); + expectedEx.expectMessage(" Action Identifier doesn't have VnfId, VfModuleId, VServerId, VnfcName "); + executor.isRequestOverLap(requestData); + } +} 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 index 9367a4420..64d150a52 100644 --- 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 @@ -3,6 +3,8 @@ * 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. @@ -24,12 +26,9 @@ import org.junit.Test; public class ServiceConstantsTest { - private ServiceConstants serviceConstants=new ServiceConstants(); @Test public void testServiceConstants() { - Assert.assertEquals("action-identifiers",serviceConstants.ACTIONIDENTIFIER); - Assert.assertNotNull(serviceConstants.ACTIONIDENTIFIER); - + Assert.assertEquals("action-identifiers", ServiceConstants.ACTIONIDENTIFIER); } } |