aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher')
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/CommandExecutionTaskTest.java295
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java300
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/RequestValidatorTest.java (renamed from appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java)356
3 files changed, 440 insertions, 511 deletions
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/CommandExecutionTaskTest.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/CommandExecutionTaskTest.java
new file mode 100644
index 000000000..a46202c1b
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/CommandExecutionTaskTest.java
@@ -0,0 +1,295 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
+import org.openecomp.appc.domainmodel.lcm.CommonHeader;
+import org.openecomp.appc.domainmodel.lcm.Flags;
+import org.openecomp.appc.domainmodel.lcm.RequestContext;
+import org.openecomp.appc.domainmodel.lcm.ResponseContext;
+import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
+import org.openecomp.appc.domainmodel.lcm.Status;
+import org.openecomp.appc.domainmodel.lcm.VNFContext;
+import org.openecomp.appc.domainmodel.lcm.VNFOperation;
+import org.openecomp.appc.executor.impl.CommandTask;
+import org.openecomp.appc.executor.impl.CommandTaskFactory;
+import org.openecomp.appc.executor.impl.LCMCommandTask;
+import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
+import org.openecomp.appc.executor.objects.CommandResponse;
+import org.openecomp.appc.lifecyclemanager.LifecycleManager;
+import org.openecomp.appc.requesthandler.RequestHandler;
+import org.openecomp.appc.workflow.WorkFlowManager;
+import org.openecomp.appc.workflow.objects.WorkflowResponse;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.openecomp.sdnc.sli.aai.AAIService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.time.Instant;
+
+import static junit.framework.Assert.assertEquals;
+import static org.mockito.Matchers.*;
+
+@SuppressWarnings("unchecked")
+@RunWith(PowerMockRunner.class)
+@PrepareForTest( {FrameworkUtil.class, CommandTask.class, LCMCommandTask.class})
+public class CommandExecutionTaskTest {
+
+ private final String TTL_FLAG= "TTL";
+ private final String API_VERSION= "2.0.0";
+ private final String ORIGINATOR_ID= "1";
+ private CommandTaskFactory factory ;
+
+ private RequestHandler requestHandler;
+ private WorkFlowManager workflowManager;
+ private AAIService aaiService;
+ private LifecycleManager lifecyclemanager;
+
+ private final BundleContext bundleContext=Mockito.mock(BundleContext.class);
+ private final Bundle bundleService=Mockito.mock(Bundle.class);
+ private final ServiceReference sref=Mockito.mock(ServiceReference.class);
+
+ @Before
+ public void init() throws SvcLogicException {
+
+ // ***
+ AAIService aaiService = Mockito.mock(AAIService.class);
+ PowerMockito.mockStatic(FrameworkUtil.class);
+ PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
+ PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
+ PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
+ PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
+ PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),
+ anyString(), anyObject())).thenAnswer(invocation -> {
+ Object[] args = invocation.getArguments();
+ SvcLogicContext ctx =(SvcLogicContext)args[6];
+ String prefix = (String)args[4];
+ String key = (String)args[3];
+ if(key.contains("'28'")){
+ return SvcLogicResource.QueryStatus.FAILURE ;
+ }else if ( key.contains("'8'")) {
+ return SvcLogicResource.QueryStatus.NOT_FOUND ;
+ }else {
+ ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
+ ctx.setAttribute(prefix + ".orchestration-status", "INSTANTIATED");
+ }
+ return SvcLogicResource.QueryStatus.SUCCESS ;
+ });
+ PowerMockito.when(aaiService.update(anyString(), anyString(), anyObject(), anyString(),
+ anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
+
+ requestHandler = Mockito.mock(RequestHandler.class);
+ workflowManager = Mockito.mock(WorkFlowManager.class);
+ lifecyclemanager = Mockito.mock(LifecycleManager.class );
+
+ factory = new CommandTaskFactory();
+ factory.setLifecyclemanager(lifecyclemanager);
+ factory.setWorkflowManager(workflowManager);
+ factory.setVnfRequestHandler(requestHandler);
+ Mockito.when(workflowManager.executeWorkflow(anyObject())).thenReturn(getWorkflowResponse ());
+ }
+
+
+ @Test
+ public void testFactory(){
+ CommandTask task;
+ Instant timeStamp = Instant.now();
+ String requestId = "1";
+ RuntimeContext commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
+ task = factory.getExecutionTask(commandExecutorInputConfigure);
+ assertEquals(LCMCommandTask.class,task.getClass() );
+ RuntimeContext commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
+ task = factory.getExecutionTask(commandExecutorInputSync);
+ assertEquals(LCMReadonlyCommandTask.class,task.getClass() );
+
+ }
+
+
+
+ @Test
+ public void testOnRequestCompletion(){
+ Mockito.doNothing().when(requestHandler).onRequestTTLEnd(anyObject(),anyBoolean());
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure,
+ "1", "");
+ CommandResponse response = getCommandResponse(VNFOperation.Configure, true, "11",
+ "","1");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
+ executionTask.onRequestCompletion(response);
+ }
+
+ @Test
+ public void testRunGetConfig(){
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync,
+ "1", "");
+ LCMReadonlyCommandTask readonlyCommandTask = new LCMReadonlyCommandTask(
+ request, requestHandler,workflowManager);
+ readonlyCommandTask.run();
+ }
+
+ @Test
+ public void testRun(){
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync,
+ "1", "");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
+ executionTask.run();
+ }
+
+ @Test
+ public void testRunNegative(){
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync,
+ "1", "");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
+ executionTask.run();
+ }
+
+
+ private CommandResponse getCommandResponse(VNFOperation action,
+ boolean success,
+ String responseId,
+ String payload,
+ String vnfId){
+ RuntimeContext runtimeContext = new RuntimeContext();
+ ResponseContext responseContext = new ResponseContext();
+ runtimeContext.setResponseContext(responseContext);
+ RequestContext requestContext = new RequestContext();
+ runtimeContext.setRequestContext(requestContext);
+ CommonHeader commonHeader = new CommonHeader();
+ requestContext.setCommonHeader(commonHeader);
+ responseContext.setCommonHeader(commonHeader);
+ commonHeader.setFlags(new Flags(null, false, 0));
+ ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
+ requestContext.setActionIdentifiers(actionIdentifiers);
+ VNFContext vnfContext = new VNFContext();
+ runtimeContext.setVnfContext(vnfContext);
+ requestContext.setAction(action);
+ runtimeContext.setRpcName(action.name().toLowerCase());
+ commonHeader.setApiVer(API_VERSION);
+ responseContext.setStatus(new Status(100, null));
+ commonHeader.setRequestId(responseId);
+ responseContext.setPayload(payload);
+ commonHeader.setTimestamp(Instant.now());
+ vnfContext.setId(vnfId);
+ return new CommandResponse(runtimeContext);
+ }
+
+
+
+ @Test
+ public void testPositiveFlow_configure() {
+
+ String requestId = "1";
+
+ pouplateCommandExecutorInput("FIREWALL",30,
+ "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "",
+ VNFOperation.Configure, "33", "");
+ }
+
+ public WorkflowResponse getWorkflowResponse (){
+ WorkflowResponse wfResponse = new WorkflowResponse();
+ ResponseContext responseContext = createResponseContextWithSuObjects();
+ wfResponse.setResponseContext(responseContext);
+ responseContext.setPayload("");
+ wfResponse.getResponseContext().setStatus(new Status(100, null));
+ return wfResponse;
+ }
+
+ private RuntimeContext pouplateCommandExecutorInput(String vnfType,
+ int ttl,
+ String vnfVersion,
+ Instant timeStamp,
+ String apiVersion,
+ String requestId,
+ String originatorID,
+ String subRequestID,
+ VNFOperation action,
+ String vnfId,
+ String payload){
+ RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();
+ RequestContext requestContext = commandExecutorInput.getRequestContext();
+ ResponseContext responseContext = createResponseContextWithSuObjects();
+ commandExecutorInput.setResponseContext(responseContext);
+
+ requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
+ requestContext.getCommonHeader().setApiVer(apiVersion);
+ requestContext.getCommonHeader().setTimestamp(timeStamp);
+ requestContext.getCommonHeader().setRequestId(requestId);
+ requestContext.getCommonHeader().setSubRequestId(subRequestID);
+ requestContext.getCommonHeader().setOriginatorId(originatorID);
+ requestContext.setAction(action);
+ requestContext.setPayload(payload);
+ requestContext.getActionIdentifiers().setVnfId(vnfId);
+ VNFContext vnfContext = commandExecutorInput.getVnfContext();
+ vnfContext.setType(vnfType);
+ vnfContext.setId(vnfId);
+ vnfContext.setVersion(vnfVersion);
+ return commandExecutorInput;
+ }
+
+ private RuntimeContext createCommandExecutorInputWithSubObjects() {
+ return createRuntimeContextWithSubObjects();
+ }
+
+ private RuntimeContext createRuntimeContextWithSubObjects() {
+ RuntimeContext runtimeContext = new RuntimeContext();
+ RequestContext requestContext = new RequestContext();
+ runtimeContext.setRequestContext(requestContext);
+ CommonHeader commonHeader = new CommonHeader();
+ requestContext.setCommonHeader(commonHeader);
+ commonHeader.setFlags(new Flags(null, false, 0));
+ ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
+ requestContext.setActionIdentifiers(actionIdentifiers);
+ VNFContext vnfContext = new VNFContext();
+ runtimeContext.setVnfContext(vnfContext);
+ return runtimeContext;
+
+ }
+
+ private ResponseContext createResponseContextWithSuObjects(){
+ ResponseContext responseContext = new ResponseContext();
+ CommonHeader commonHeader = new CommonHeader();
+ responseContext.setCommonHeader(commonHeader);
+ responseContext.setStatus(new Status(0, null));
+ commonHeader.setFlags(new Flags(null, false, 0));
+ return responseContext;
+ }
+
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java
deleted file mode 100644
index 460f0e7ad..000000000
--- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Copyright (C) 2017 Amdocs
- * =============================================================================
- * 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.appc.executor;
-/**
- *
- */
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.openecomp.appc.domainmodel.lcm.*;
-import org.openecomp.appc.domainmodel.lcm.Flags.Mode;
-import org.openecomp.appc.executor.impl.CommandTask;
-import org.openecomp.appc.executor.impl.CommandTaskFactory;
-import org.openecomp.appc.executor.impl.LCMCommandTask;
-import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
-import org.openecomp.appc.executor.objects.*;
-import org.openecomp.appc.lifecyclemanager.LifecycleManager;
-import org.openecomp.appc.requesthandler.RequestHandler;
-import org.openecomp.appc.workflow.WorkFlowManager;
-import org.openecomp.appc.workflow.objects.WorkflowRequest;
-import org.openecomp.appc.workflow.objects.WorkflowResponse;
-import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.openecomp.sdnc.sli.SvcLogicException;
-import org.openecomp.sdnc.sli.SvcLogicResource;
-import org.openecomp.sdnc.sli.aai.AAIService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.time.Instant;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import static junit.framework.Assert.assertEquals;
-import static org.mockito.Matchers.*;
-
-
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest( {FrameworkUtil.class, CommandTask.class, LCMCommandTask.class})
-public class TestCommandExecutionTask {
-
- private static final String TTL_FLAG= "TTL";
- private static final String API_VERSION= "2.0.0";
- private static final String ORIGINATOR_ID= "1";
- private CommandTaskFactory factory ;
-
- private RequestHandler requestHandler;
- private WorkFlowManager workflowManager;
- private AAIService aaiService;
- private LifecycleManager lifecyclemanager;
-
- private final BundleContext bundleContext=Mockito.mock(BundleContext.class);
- private final Bundle bundleService=Mockito.mock(Bundle.class);
- private final ServiceReference sref=Mockito.mock(ServiceReference.class);
-
- @Before
- public void init() throws SvcLogicException {
-
- // ***
- AAIService aaiService = Mockito.mock(AAIService.class);;
- PowerMockito.mockStatic(FrameworkUtil.class);
- PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
- PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
- PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
- PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
- PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
- @Override
- public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
- Object[] args = invocation.getArguments();
- SvcLogicContext ctx =(SvcLogicContext)args[6];
- String prefix = (String)args[4];
- String key = (String)args[3];
- if(key.contains("'28'")){
- return SvcLogicResource.QueryStatus.FAILURE ;
- }else if ( key.contains("'8'")) {
- return SvcLogicResource.QueryStatus.NOT_FOUND ;
- }else {
- ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
- ctx.setAttribute(prefix + ".orchestration-status", "INSTANTIATED");
- }
- return SvcLogicResource.QueryStatus.SUCCESS ;
- }
- });
- PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
-
- requestHandler = Mockito.mock(RequestHandler.class);
- workflowManager = Mockito.mock(WorkFlowManager.class);
- lifecyclemanager = Mockito.mock(LifecycleManager.class );
-
- factory = new CommandTaskFactory();
- factory.setLifecyclemanager(lifecyclemanager);
- factory.setWorkflowManager(workflowManager);
- factory.setVnfRequestHandler(requestHandler);
- Mockito.when(workflowManager.executeWorkflow((WorkflowRequest)anyObject())).thenReturn(getWorkflowResponse () );
- }
-
-
- @Test
- public void testFactory(){
- CommandTask task;
- Instant timeStamp = Instant.now();
- String requestId = "1";
- RuntimeContext commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
- timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
- task = factory.getExecutionTask(commandExecutorInputConfigure);
- assertEquals(LCMCommandTask.class,task.getClass() );
- RuntimeContext commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
- timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
- task = factory.getExecutionTask(commandExecutorInputSync);
- assertEquals(LCMReadonlyCommandTask.class,task.getClass() );
-
- }
-
-
-
- @Test
- public void testOnRequestCompletion(){
- Mockito.doNothing().when(requestHandler).onRequestTTLEnd((RuntimeContext) anyObject(),anyBoolean());
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", "");
- CommandResponse response = getCommandResponse(VNFOperation.Configure, true, "11", "","1");
- LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
- executionTask.onRequestCompletion(response);
- }
-
- @Test
- public void testRunGetConfig(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- LCMReadonlyCommandTask readonlyCommandTask = new LCMReadonlyCommandTask(request, requestHandler,workflowManager);
- readonlyCommandTask.run();
- }
-
- @Test
- public void testRun(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
- executionTask.run();
- }
-
- @Test
- public void testRunNegative(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
- executionTask.run();
- }
-
-
- CommandResponse getCommandResponse(VNFOperation action , boolean success, String responseId, String payload, String vnfId){
- RuntimeContext runtimeContext = new RuntimeContext();
- ResponseContext responseContext = new ResponseContext();
- runtimeContext.setResponseContext(responseContext);
- RequestContext requestContext = new RequestContext();
- runtimeContext.setRequestContext(requestContext);
- CommonHeader commonHeader = new CommonHeader();
- requestContext.setCommonHeader(commonHeader);
- responseContext.setCommonHeader(commonHeader);
- commonHeader.setFlags(new Flags(null, false, 0));
- ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
- requestContext.setActionIdentifiers(actionIdentifiers);
- VNFContext vnfContext = new VNFContext();
- runtimeContext.setVnfContext(vnfContext);
- requestContext.setAction(action);
- runtimeContext.setRpcName(action.name().toLowerCase());
- commonHeader.setApiVer(API_VERSION);
- responseContext.setStatus(new Status(100, null));
- commonHeader.setRequestId(responseId);
- responseContext.setPayload(payload);
- commonHeader.setTimestamp(Instant.now());
- vnfContext.setId(vnfId);
- return new CommandResponse(runtimeContext);
- }
-
-
-
- @Test
- public void testPositiveFlow_configure() {
-
- String requestId = "1";
-
- RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", "");
- }
-
-
- private Map<String,Object> setTTLInFlags( String value){
- Map<String,Object> flags = new HashMap<String,Object>();
- if( value != null || !("".equalsIgnoreCase(value))){
- flags.put(TTL_FLAG, value);
- }
- return flags;
- }
-
-
- private RuntimeContext getConfigCommandRequest(String vnfType , Integer ttl , Instant timeStamp, String requestId,
- Map<String,Object> flags, VNFOperation command , String vnfId, String vnfVersion ){
-
- RuntimeContext commandExecutorInput = pouplateCommandExecutorInput(vnfType, ttl, vnfVersion, timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", command, vnfId, "");
-
- return commandExecutorInput;
- }
-
- private RuntimeContext getLCMCommandRequest(String vnfType , Integer ttl ,Instant timeStamp, String requestId,
- Map<String,Object> flags, VNFOperation command , String vnfId, String vnfVersion ){
-
- RuntimeContext commandExecutorInput = pouplateCommandExecutorInput(vnfType, ttl, vnfVersion, timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", command, vnfId, "");
-
- return commandExecutorInput;
- }
-
- public WorkflowResponse getWorkflowResponse (){
- WorkflowResponse wfResponse = new WorkflowResponse();
- ResponseContext responseContext = createResponseContextWithSuObjects();
- wfResponse.setResponseContext(responseContext);
- responseContext.setPayload("");
- wfResponse.getResponseContext().setStatus(new Status(100, null));
- return wfResponse;
- }
-
- private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Instant timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){
- RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();
- RequestContext requestContext = commandExecutorInput.getRequestContext();
- ResponseContext responseContext = createResponseContextWithSuObjects();
- commandExecutorInput.setResponseContext(responseContext);
-
- requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
- requestContext.getCommonHeader().setApiVer(apiVersion);
- requestContext.getCommonHeader().setTimestamp(timeStamp);
- requestContext.getCommonHeader().setRequestId(requestId);
- requestContext.getCommonHeader().setSubRequestId(subRequestID);
- requestContext.getCommonHeader().setOriginatorId(originatorID);
- requestContext.setAction(action);
- requestContext.setPayload(payload);
- requestContext.getActionIdentifiers().setVnfId(vnfId);
- VNFContext vnfContext = commandExecutorInput.getVnfContext();
- vnfContext.setType(vnfType);
- vnfContext.setId(vnfId);
- vnfContext.setVersion(vnfVersion);
- return commandExecutorInput;
- }
-
- private RuntimeContext createCommandExecutorInputWithSubObjects() {
- return createRuntimeContextWithSubObjects();
- }
-
- private RuntimeContext createRuntimeContextWithSubObjects() {
- RuntimeContext runtimeContext = new RuntimeContext();
- RequestContext requestContext = new RequestContext();
- runtimeContext.setRequestContext(requestContext);
- CommonHeader commonHeader = new CommonHeader();
- requestContext.setCommonHeader(commonHeader);
- commonHeader.setFlags(new Flags(null, false, 0));
- ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
- requestContext.setActionIdentifiers(actionIdentifiers);
- VNFContext vnfContext = new VNFContext();
- runtimeContext.setVnfContext(vnfContext);
- return runtimeContext;
-
- }
-
- private ResponseContext createResponseContextWithSuObjects(){
- ResponseContext responseContext = new ResponseContext();
- CommonHeader commonHeader = new CommonHeader();
- responseContext.setCommonHeader(commonHeader);
- responseContext.setStatus(new Status(0, null));
- commonHeader.setFlags(new Flags(null, false, 0));
- return responseContext;
- }
-
-}
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/RequestValidatorTest.java
index 2cdf37e48..24fd37834 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/RequestValidatorTest.java
@@ -24,37 +24,31 @@
package org.openecomp.appc.requesthandler;
-
-import static junit.framework.TestCase.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-
-import java.time.Instant;
-import java.util.Map;
-import java.util.UUID;
-
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.openecomp.appc.domainmodel.lcm.*;
-import org.openecomp.appc.executor.UnstableVNFException;
+import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
+import org.openecomp.appc.domainmodel.lcm.CommonHeader;
+import org.openecomp.appc.domainmodel.lcm.Flags;
+import org.openecomp.appc.domainmodel.lcm.RequestContext;
+import org.openecomp.appc.domainmodel.lcm.ResponseContext;
+import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
+import org.openecomp.appc.domainmodel.lcm.Status;
+import org.openecomp.appc.domainmodel.lcm.VNFContext;
+import org.openecomp.appc.domainmodel.lcm.VNFOperation;
import org.openecomp.appc.lifecyclemanager.LifecycleManager;
-import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
-import org.openecomp.appc.requesthandler.exceptions.*;
+import org.openecomp.appc.requesthandler.exceptions.InvalidInputException;
+import org.openecomp.appc.requesthandler.exceptions.LCMOperationsDisabledException;
import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl;
import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl;
import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
import org.openecomp.appc.transactionrecorder.TransactionRecorder;
import org.openecomp.appc.workflow.WorkFlowManager;
import org.openecomp.appc.workflow.objects.WorkflowExistsOutput;
-import org.openecomp.appc.workflow.objects.WorkflowRequest;
import org.openecomp.appc.workingstatemanager.WorkingStateManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
import org.openecomp.sdnc.sli.SvcLogicResource;
@@ -67,161 +61,83 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+import java.time.Instant;
+import java.util.UUID;
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.*;
+@SuppressWarnings("unchecked")
@RunWith(PowerMockRunner.class)
-@PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class})
-public class TestRequestValidator {
-
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
-
- private static final String TTL_FLAG= "TTL";
+@PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,
+ RequestValidatorImpl.class, TransactionRecorder.class})
+public class RequestValidatorTest {
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
private RequestValidatorImpl requestValidator;
- AAIService aaiAdapter ;
- LifecycleManager lifecyclemanager;
- WorkFlowManager workflowManager;
- WorkingStateManager workingStateManager ;
- LCMStateManager lcmStateManager;
-// AppcDAOImpl dao ;
+ private AAIService aaiAdapter ;
+ private LifecycleManager lifecyclemanager;
+ private WorkFlowManager workflowManager;
+ private WorkingStateManager workingStateManager ;
+ private LCMStateManager lcmStateManager;
private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
private final Bundle bundleService=Mockito.mock(Bundle.class);
private final ServiceReference sref=Mockito.mock(ServiceReference.class);
-
-
@Before
public void init() throws Exception {
-
-// dao = Mockito.mock(AppcDAOImpl.class);
-// PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
-// Mockito.doNothing().when(dao).storeTransactionRecord((TransactionRecord)anyObject());
- // PowerMockito.when(dao.queryWorkflow(anyString(),anyString())).thenReturn(true);
-
// ***
- AAIService aaiService = Mockito.mock(AAIService.class);;
+ AAIService aaiService = Mockito.mock(AAIService.class);
PowerMockito.mockStatic(FrameworkUtil.class);
PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
- PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
- @Override
- public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
- Object[] args = invocation.getArguments();
- SvcLogicContext ctx =(SvcLogicContext)args[6];
- String prefix = (String)args[4];
- String key = (String)args[3];
- if(key.contains("'28'")){
- return SvcLogicResource.QueryStatus.FAILURE ;
- }else if ( key.contains("'8'")) {
- return SvcLogicResource.QueryStatus.NOT_FOUND ;
- }else {
- ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
- ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
- }
- return SvcLogicResource.QueryStatus.SUCCESS ;
- }
- });
- PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
- //PowerMockito.when(requestHandler.getVnfdata(anyString(), anyString(), (SvcLogicContext)anyObject())).thenReturn()
+ PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),
+ anyObject())).thenAnswer(invocation -> {
+ Object[] args = invocation.getArguments();
+ SvcLogicContext ctx =(SvcLogicContext)args[6];
+ String prefix = (String)args[4];
+ String key = (String)args[3];
+ if(key.contains("'28'")){
+ return SvcLogicResource.QueryStatus.FAILURE ;
+ }else if ( key.contains("'8'")) {
+ return SvcLogicResource.QueryStatus.NOT_FOUND ;
+ }else {
+ ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
+ ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
+ }
+ return SvcLogicResource.QueryStatus.SUCCESS ;
+ });
+ PowerMockito.when(aaiService.update(anyString(),anyString(), anyObject(),anyString(), anyObject()))
+ .thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
// ***
-
aaiAdapter = Mockito.mock(AAIService.class);
lifecyclemanager= Mockito.mock(LifecycleManager.class);
workflowManager= Mockito.mock(WorkFlowManager.class);
workingStateManager = Mockito.mock(WorkingStateManager.class);
lcmStateManager = Mockito.mock(LCMStateManager.class);
- // transactionRecorder= spy(TransactionRecorder.class);
requestValidator = new RequestValidatorImpl();
-// requestValidator = Mockito.mock(RequestValidator.class);
requestValidator.setWorkflowManager(workflowManager);
requestValidator.setLifecyclemanager(lifecyclemanager);
requestValidator.setWorkingStateManager(workingStateManager);
requestValidator.setLcmStateManager(lcmStateManager);
Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(true);
- /* Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
- Mockito.when(aaiAdapter.requestGenericVnfData("1")).thenReturn(getGenericVnf("FIREWALL","INSTNATIATED"));*/
- // Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(true);
-
- /*PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("8")).thenThrow(new AAIAdapterException("404"));
- Mockito.when(workingStateManager.isVNFStable("8")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("9")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("9")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("10")).thenReturn(getGenericVnf("WrongRouter","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("10")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("11")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("11")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("12")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("12")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("13")).thenReturn(getGenericVnf("FIREWALL","TESTING"));
- Mockito.when(workingStateManager.isVNFStable("13")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("14")).thenReturn(getGenericVnf("FIREWALL","REBUILDING"));
- Mockito.when(workingStateManager.isVNFStable("14")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("26")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("26")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("27")).thenReturn(getGenericVnf("FIREWALL","RESTARTING"));
- Mockito.when(workingStateManager.isVNFStable("27")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("28")).thenThrow(new RuntimeException("AAI Down Excpetion"));
- Mockito.when(workingStateManager.isVNFStable("28")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("35")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("35")).thenReturn(true);*/
-
- /*for(Integer i=130; i<=140 ; i++)
- {
- PowerMockito.when(getAaiadapter().requestGenericVnfData(i.toString())).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable(i.toString())).thenReturn(true);
- }
- PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("40")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("40")).thenReturn(true).thenReturn(false);
-
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("38")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("38")).thenReturn(true).thenReturn(false);
-
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("201")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","CONFIGURED"));
- Mockito.when(workingStateManager.isVNFStable("201")).thenReturn(true);
- PowerMockito.when(getAaiadapter().requestGenericVnfData("202")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","ERROR"));
- Mockito.when(workingStateManager.isVNFStable("202")).thenReturn(true).thenReturn(false);
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("301")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true).thenReturn(false);
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("302")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("302")).thenReturn(true).thenReturn(true);
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("303")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("303")).thenReturn(true).thenReturn(true);
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("309")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true).thenReturn(true);
-
- PowerMockito.when(getAaiadapter().requestGenericVnfData("310")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
- Mockito.when(workingStateManager.isVNFStable("310")).thenReturn(true).thenReturn(true);*/
}
+
public AAIService getAaiadapter() {
return this.aaiAdapter;
}
-/* public GenericVnf getGenericVnf(String vnfType, String operationalState) {
- GenericVnf genericVnf = new GenericVnf();
- genericVnf.setVnfType(vnfType);
- // genericVnf.setOperationalState(operationalState);
- genericVnf.setOrchestrationStatus(operationalState);
- return genericVnf;
- }*/
- private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Instant timeStamp){
+
+ private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl,
+ boolean force, String originatorId, String requestId,
+ String subRequestId, Instant timeStamp){
String API_VERSION= "2.0.0";
RequestHandlerInput input = new RequestHandlerInput();
RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
@@ -231,8 +147,7 @@ public class TestRequestValidator {
requestContext.setAction(action);
if (action != null) {
input.setRpcName(convertActionNameToUrl(action.name()));
- }
- else{
+ } else{
input.setRpcName(null);
}
requestContext.getCommonHeader().setRequestId(requestId);
@@ -244,12 +159,15 @@ public class TestRequestValidator {
requestContext.getCommonHeader().setTimestamp(timeStamp);
return input;
}
+
@Test
- public void testNullVnfID() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testNullVnfID() throws Exception {
logger.debug("=====================testNullVnfID=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30,
- false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -257,18 +175,19 @@ public class TestRequestValidator {
}catch(InvalidInputException e ) {
ex = e;
}
-// assertEquals(new InvalidInputException("vnfID or command is null") ,ex);
assertNotNull(ex);
logger.debug("=====================testNullVnfID=============================");
}
@Test
- public void testPositiveFlowWithConfigure() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testPositiveFlowWithConfigure() throws Exception {
logger.debug("=====================testPositiveFlowWithConfigure=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -282,11 +201,13 @@ public class TestRequestValidator {
}
@Test
- public void testVnfNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testVnfNotFound() throws Exception {
logger.debug("=====================testVnfNotFound=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -298,14 +219,14 @@ public class TestRequestValidator {
logger.debug("=====================testVnfNotFound=============================");
}
-
-
@Test
- public void testNullCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testNullCommand() throws Exception {
logger.debug("=====================testNullCommand=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
RequestHandlerInput input = this.getRequestHandlerInput("7", null,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -318,11 +239,13 @@ public class TestRequestValidator {
}
@Test
- public void testNullVnfIDAndCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testNullVnfIDAndCommand() throws Exception {
logger.debug("=====================testNullVnfIDAndCommand=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
RequestHandlerInput input = this.getRequestHandlerInput(null, null,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -335,11 +258,13 @@ public class TestRequestValidator {
}
@Test
- public void testWorkflowNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testWorkflowNotFound() throws Exception {
logger.debug("=====================testWorkflowNotFound=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(false,false));
RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -352,13 +277,16 @@ public class TestRequestValidator {
}
@Test
- public void testUnstableVnfWithConfigure() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testUnstableVnfWithConfigure() throws Exception {
logger.debug("=====================testUnstableVnfWithConfigure=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString()))
+ .thenThrow( new NoTransitionDefinedException("","",""));
RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -371,12 +299,15 @@ public class TestRequestValidator {
}
@Test
- public void testUnstableVnfWithTest() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testUnstableVnfWithTest() throws Exception {
logger.debug("=====================testUnstableVnfWithTest=============================");
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString()))
+ .thenThrow( new NoTransitionDefinedException("","",""));
RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -389,12 +320,14 @@ public class TestRequestValidator {
}
@Test
- public void testUnstableVnfWithStart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testUnstableVnfWithStart() throws Exception {
logger.debug("=====================testUnstableVnfWithStart=============================");
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString()))
+ .thenThrow( new NoTransitionDefinedException("","",""));
RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -407,11 +340,13 @@ public class TestRequestValidator {
}
@Test
- public void testUnstableVnfWithTerminate() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testUnstableVnfWithTerminate() throws Exception {
logger.debug("=====================testUnstableVnfWithTerminate=============================");
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString()))
+ .thenThrow( new NoTransitionDefinedException("","",""));
RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -424,12 +359,14 @@ public class TestRequestValidator {
}
@Test
- public void testUnstableVnfWithRestart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testUnstableVnfWithRestart() throws Exception {
logger.debug("=====================testUnstableVnfWithRestart=============================");
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString()))
+ .thenThrow( new NoTransitionDefinedException("","",""));
RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -442,13 +379,14 @@ public class TestRequestValidator {
}
@Test
- public void testUnstableVnfWithRebuild() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testUnstableVnfWithRebuild() throws Exception {
logger.debug("=====================testUnstableVnfWithRebuild=============================");
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString()))
+ .thenThrow( new NoTransitionDefinedException("","",""));
- // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8");
RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
@@ -460,22 +398,16 @@ public class TestRequestValidator {
logger.debug("=====================testUnstableVnfWithRebuild=============================");
}
-
-
-
@Test
public void testAAIDown() throws Exception {
logger.debug("=====================testAAIDown=============================");
- // AAIAdapter aaiAdapter = Mockito.mock(AAIAdapterImpl.class);
- // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
- // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30,
- false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
- Exception ex =null;
+ false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),
+ Instant.now());
+ Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
try {
requestValidator.validateRequest(runtimeContext);
-
}catch(Exception e ) {
ex = e;
}
@@ -484,7 +416,7 @@ public class TestRequestValidator {
}
@Test
- public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void testNegativeFlowWithTimeStamp() throws Exception {
logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
Instant now = Instant.now();
Instant past = now.minusMillis(1000000);
@@ -503,19 +435,21 @@ public class TestRequestValidator {
logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
}
-
@Test
- public void rejectDuplicateRequest() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
+ public void rejectDuplicateRequest() throws Exception {
String originatorID = UUID.randomUUID().toString();
String requestID = UUID.randomUUID().toString();
String subRequestID = UUID.randomUUID().toString();
- Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
+ Mockito.when(workflowManager.workflowExists(anyObject()))
+ .thenReturn(new WorkflowExistsOutput(true,true));
Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true);
Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true);
- RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
+ RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,
+ originatorID, requestID, subRequestID, Instant.now());
- RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
+ RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,
+ originatorID, requestID, subRequestID, Instant.now());
Exception ex =null;
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1);
@@ -536,60 +470,63 @@ public class TestRequestValidator {
}
@Test
- public void testLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testLockOperation() throws Exception {
Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
testOperation("no-matter", VNFOperation.Lock);
}
@Test
- public void testUnlockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testUnlockOperation() throws Exception {
Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
testOperation("no-matter", VNFOperation.Unlock);
}
@Test
- public void testCheckLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testCheckLockOperation() throws Exception {
Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
testOperation("no-matter", VNFOperation.CheckLock);
}
@Test(expected = NoTransitionDefinedException.class)
- public void testLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
+ public void testLockOperationNegative() throws Exception {
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString())))
+ .thenThrow(new NoTransitionDefinedException("", "", ""));
Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
testOperation("no-matter", VNFOperation.Lock);
}
@Test(expected = NoTransitionDefinedException.class)
- public void testUnlockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
+ public void testUnlockOperationNegative() throws Exception {
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString())))
+ .thenThrow(new NoTransitionDefinedException("", "", ""));
Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
testOperation("no-matter", VNFOperation.Unlock);
}
@Test(expected = NoTransitionDefinedException.class)
- public void testCheckLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
- Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
+ public void testCheckLockOperationNegative() throws Exception {
+ Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString())))
+ .thenThrow(new NoTransitionDefinedException("", "", ""));
Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
testOperation("no-matter", VNFOperation.CheckLock);
}
@Test(expected = LCMOperationsDisabledException.class)
- public void testLCMOperationsDisabled() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ public void testLCMOperationsDisabled() throws Exception {
Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(false);
testOperation("no-matter", VNFOperation.Configure);
}
- private void testOperation(String resource, VNFOperation operation) throws WorkflowNotFoundException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, InvalidInputException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, RequestExpiredException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
+ private void testOperation(String resource, VNFOperation operation) throws Exception {
String originatorID = UUID.randomUUID().toString();
String requestID = UUID.randomUUID().toString();
String subRequestID = UUID.randomUUID().toString();
- RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, Instant.now());
+ RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID,
+ requestID, subRequestID, Instant.now());
RuntimeContext runtimeContext = putInputToRuntimeContext(input);
requestValidator.validateRequest(runtimeContext);
}
-
private RuntimeContext createRuntimeContextWithSubObjects() {
RuntimeContext runtimeContext = new RuntimeContext();
RequestContext requestContext = new RequestContext();
@@ -628,9 +565,6 @@ public class TestRequestValidator {
runtimeContext.setRequestContext(input.getRequestContext());
runtimeContext.setRpcName(input.getRpcName());
runtimeContext.getVnfContext().setId(input.getRequestContext().getActionIdentifiers().getVnfId());
- //runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(input.getRequestContext().getActionIdentifiers().getVnfId());
return runtimeContext;
-
- //String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp
}
}