Updating licenses in all files
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / test / java / org / openecomp / appc / executor / TestCommandExecutionTask.java
index 1e46393..0c7c0ba 100644 (file)
@@ -1,9 +1,9 @@
 /*-
  * ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- *                                             reserved.
+ * 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.
@@ -17,6 +17,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 
 package org.openecomp.appc.executor;
@@ -31,13 +32,11 @@ 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.impl.objects.CommandRequest;
-import org.openecomp.appc.executor.impl.objects.LCMCommandRequest;
-import org.openecomp.appc.executor.impl.objects.LCMReadOnlyCommandRequest;
 import org.openecomp.appc.executor.objects.*;
 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
 import org.openecomp.appc.requesthandler.RequestHandler;
@@ -56,6 +55,7 @@ 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;
@@ -73,8 +73,6 @@ 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 LCMCommandTask executionTask;
-       private LCMReadonlyCommandTask LCMReadonlyCommandTask;
        private CommandTaskFactory factory ;
 
        private RequestHandler requestHandler;
@@ -95,7 +93,7 @@ public class TestCommandExecutionTask {
                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.getService(sref)).thenReturn(aaiService);
+               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 {
@@ -120,8 +118,6 @@ public class TestCommandExecutionTask {
                workflowManager = Mockito.mock(WorkFlowManager.class);
                lifecyclemanager = Mockito.mock(LifecycleManager.class );
 
-               executionTask = new LCMCommandTask(requestHandler,workflowManager,lifecyclemanager);
-               LCMReadonlyCommandTask = new LCMReadonlyCommandTask(requestHandler,workflowManager);
                factory = new CommandTaskFactory();
                factory.setLifecyclemanager(lifecyclemanager);
                factory.setWorkflowManager(workflowManager);
@@ -132,9 +128,9 @@ public class TestCommandExecutionTask {
 
        @Test
        public void testFactory(){
-               CommandTask<? extends CommandRequest> task = factory.getExecutionTask("Configure");
+               CommandTask task = factory.getExecutionTask("Configure", null);
                assertEquals(LCMCommandTask.class,task.getClass() );
-               task = factory.getExecutionTask("Sync");
+               task = factory.getExecutionTask("Sync", null);
                assertEquals(LCMReadonlyCommandTask.class,task.getClass() );
 
        }
@@ -144,37 +140,36 @@ public class TestCommandExecutionTask {
        @Test
        public void testOnRequestCompletion(){
                Mockito.doNothing().when(requestHandler).onRequestTTLEnd((RuntimeContext) anyObject(),anyBoolean());
-               LCMCommandRequest request = getLCMCommandRequest("FIREWALL",30,new Date(), "11" ,setTTLInFlags("30"), VNFOperation.Configure, "1", "1.0");
+               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");
-               executionTask.onRequestCompletion(request, response);
+        LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
+               executionTask.onRequestCompletion(response);
        }
 
        @Test
        public void testRunGetConfig(){
-               LCMReadOnlyCommandRequest request = getConfigCommandRequest("FIREWALL",30,new Date(), "11" ,setTTLInFlags("30"),VNFOperation.Sync, "1", "1.0");
-               LCMReadonlyCommandTask.setCommandRequest(request);
-               LCMReadonlyCommandTask.run();
+                   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(){
-               LCMCommandRequest request = getLCMCommandRequest("FIREWALL",30,new Date(), "11" ,setTTLInFlags("30"),VNFOperation.Sync, "1", "1.0");
-               executionTask.setCommandRequest(request);
+           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(){
-               LCMCommandRequest request = getLCMCommandRequest("FIREWALL",30,new Date(), "11" ,setTTLInFlags("30"),VNFOperation.Sync, "1", "1.0");
-               executionTask.setCommandRequest(request);
+           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){
-               CommandResponse commandResponse = new CommandResponse();
                RuntimeContext runtimeContext = new RuntimeContext();
-               commandResponse.setRuntimeContext(runtimeContext);
                ResponseContext responseContext = new ResponseContext();
                runtimeContext.setResponseContext(responseContext);
                RequestContext requestContext = new RequestContext();
@@ -182,8 +177,7 @@ public class TestCommandExecutionTask {
                CommonHeader commonHeader = new CommonHeader();
                requestContext.setCommonHeader(commonHeader);
                responseContext.setCommonHeader(commonHeader);
-               Flags flags = new Flags();
-               commonHeader.setFlags(flags);
+               commonHeader.setFlags(new Flags(null, false, 0));
                ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
                requestContext.setActionIdentifiers(actionIdentifiers);
                VNFContext vnfContext = new VNFContext();
@@ -194,9 +188,9 @@ public class TestCommandExecutionTask {
                responseContext.setStatus(new Status(100, null));
                commonHeader.setRequestId(responseId);
                responseContext.setPayload(payload);
-               commonHeader.setTimestamp(new Date());
+               commonHeader.setTimestamp(Instant.now());
                vnfContext.setId(vnfId);
-               return commandResponse;
+        return new CommandResponse(runtimeContext);
        }
 
 
@@ -204,11 +198,9 @@ public class TestCommandExecutionTask {
        @Test
        public void testPositiveFlow_configure()  {
 
-               Date timeStamp = new Date();
                String requestId = "1";
 
-               CommandExecutorInput commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", "");
-               CommandRequest request = new CommandRequest(commandExecutorInput);
+               RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", "");
        }
 
 
@@ -221,24 +213,6 @@ public class TestCommandExecutionTask {
        }
 
 
-       private LCMReadOnlyCommandRequest getConfigCommandRequest(String vnfType , Integer ttl , Date timeStamp, String requestId,
-                                                                                                                         Map<String,Object> flags, VNFOperation command , String vnfId, String vnfVersion ){
-
-               CommandExecutorInput commandExecutorInput = pouplateCommandExecutorInput(vnfType, ttl, vnfVersion, timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", command, vnfId, "");
-               LCMReadOnlyCommandRequest request = new LCMReadOnlyCommandRequest(commandExecutorInput);
-
-               return request;
-       }
-
-       private LCMCommandRequest getLCMCommandRequest(String vnfType , Integer ttl ,Date timeStamp, String requestId,
-                                                                                        Map<String,Object> flags, VNFOperation command , String vnfId, String vnfVersion ){
-
-               CommandExecutorInput commandExecutorInput = pouplateCommandExecutorInput(vnfType, ttl, vnfVersion, timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", command, vnfId, "");
-               LCMCommandRequest request = new LCMCommandRequest(commandExecutorInput);
-
-               return request;
-       }
-
        public WorkflowResponse getWorkflowResponse (){
                WorkflowResponse wfResponse = new WorkflowResponse();
                ResponseContext responseContext = createResponseContextWithSuObjects();
@@ -248,14 +222,13 @@ public class TestCommandExecutionTask {
                return wfResponse;
        }
 
-       private CommandExecutorInput pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){
-               CommandExecutorInput commandExecutorInput = createCommandExecutorInputWithSubObjects();
-               RuntimeContext runtimeContext = commandExecutorInput.getRuntimeContext();
-               RequestContext requestContext = runtimeContext.getRequestContext();
+       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();
-               runtimeContext.setResponseContext(responseContext);
+               commandExecutorInput.setResponseContext(responseContext);
 
-               requestContext.getCommonHeader().getFlags().setTtl(ttl);
+               requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
                requestContext.getCommonHeader().setApiVer(apiVersion);
                requestContext.getCommonHeader().setTimestamp(timeStamp);
                requestContext.getCommonHeader().setRequestId(requestId);
@@ -264,16 +237,15 @@ public class TestCommandExecutionTask {
                requestContext.setAction(action);
                requestContext.setPayload(payload);
                requestContext.getActionIdentifiers().setVnfId(vnfId);
-               VNFContext vnfContext = runtimeContext.getVnfContext();
+               VNFContext vnfContext = commandExecutorInput.getVnfContext();
                vnfContext.setType(vnfType);
                vnfContext.setId(vnfId);
                vnfContext.setVersion(vnfVersion);
                return commandExecutorInput;
        }
 
-       private CommandExecutorInput createCommandExecutorInputWithSubObjects() {
-               RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
-        return new CommandExecutorInput(runtimeContext, 0);
+       private RuntimeContext createCommandExecutorInputWithSubObjects() {
+               return createRuntimeContextWithSubObjects();
        }
 
        private RuntimeContext createRuntimeContextWithSubObjects() {
@@ -282,8 +254,7 @@ public class TestCommandExecutionTask {
                runtimeContext.setRequestContext(requestContext);
                CommonHeader commonHeader = new CommonHeader();
                requestContext.setCommonHeader(commonHeader);
-               Flags flags = new Flags();
-               commonHeader.setFlags(flags);
+               commonHeader.setFlags(new Flags(null, false, 0));
                ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
                requestContext.setActionIdentifiers(actionIdentifiers);
                VNFContext vnfContext = new VNFContext();
@@ -295,10 +266,9 @@ public class TestCommandExecutionTask {
        private ResponseContext createResponseContextWithSuObjects(){
                ResponseContext responseContext = new ResponseContext();
                CommonHeader commonHeader = new CommonHeader();
-               Flags flags = new Flags();
                responseContext.setCommonHeader(commonHeader);
                responseContext.setStatus(new Status(0, null));
-               commonHeader.setFlags(flags);
+               commonHeader.setFlags(new Flags(null, false, 0));
                return responseContext;
        }