Change code in appc dispatcher for new LCMs in R6
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / test / java / org / onap / appc / executor / impl / TestCommandExecutor.java
index 83c6a0f..3385b84 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
- * 
+ *
  * ============LICENSE_END=========================================================
  */
 
 package org.onap.appc.executor.impl;
-/**
- * 
- */
-
 
 import org.junit.Assert;
 import org.junit.Before;
@@ -48,8 +44,8 @@ import java.util.concurrent.TimeUnit;
 
 public class TestCommandExecutor {
 
-        private static final String API_VERSION= "2.0.0";
-        private static final String ORIGINATOR_ID= "1";
+    private static final String API_VERSION = "2.0.0";
+    private static final String ORIGINATOR_ID = "1";
 
     private CommandExecutorImpl commandExecutor;
 
@@ -59,16 +55,16 @@ public class TestCommandExecutor {
 
     private Date timeStamp = new Date();
     private String requestId = "1";
-    private CommandExecutorInput commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30000, "1.0",
-            timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
-    private CommandExecutorInput commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
-            timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
+    private CommandExecutorInput commandExecutorInputConfigure = populateCommandExecutorInput("FIREWALL", 30000, "1.0",
+            timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "");
+    private CommandExecutorInput commandExecutorInputSync = populateCommandExecutorInput("FIREWALL", 30, "1.0",
+            timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync, "15", "");
     private CommandTask commandTask;
 
     @Before
-    public void init()throws Exception {
-        requestHandler= Mockito.mock(RequestHandler.class);
-        workflowManager= Mockito.mock(WorkFlowManager.class);
+    public void init() throws Exception {
+        requestHandler = Mockito.mock(RequestHandler.class);
+        workflowManager = Mockito.mock(WorkFlowManager.class);
 
         executionQueueService = Mockito.mock(ExecutionQueueService.class);
 
@@ -79,7 +75,10 @@ public class TestCommandExecutor {
         commandExecutor.initialize();
         commandTask = Mockito.mock(CommandTask.class);
         Mockito.when(commandTask.getCommandRequest()).thenReturn(new CommandRequest(commandExecutorInputConfigure));
-        PowerMockito.whenNew(CommandTask.class).withParameterTypes(RequestHandler.class,WorkFlowManager.class).withArguments(requestHandler,workflowManager).thenReturn(commandTask);
+        PowerMockito.whenNew(CommandTask.class)
+                .withParameterTypes(RequestHandler.class, WorkFlowManager.class)
+                .withArguments(requestHandler, workflowManager)
+                .thenReturn(commandTask);
     }
 
     @Test
@@ -93,21 +92,26 @@ public class TestCommandExecutor {
     }
 
     @Test(expected = APPCException.class)
-    public void testNegativeFlow_LCM() throws APPCException{
-            Mockito.doThrow(new APPCException("Failed to enqueue request")).when(executionQueueService).putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit) Mockito.anyObject());
+    public void testNegativeFlow_LCM() throws APPCException {
+            Mockito.doThrow(new APPCException("Failed to enqueue request"))
+                    .when(executionQueueService)
+                    .putMessage((Runnable) Mockito.anyObject(), Mockito.anyLong(), (TimeUnit) Mockito.anyObject());
             commandExecutor.executeCommand(commandExecutorInputSync);
     }
 
-    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){
+    private CommandExecutorInput populateCommandExecutorInput(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();
-        requestContext.getCommonHeader().getFlags().setTtl(ttl);
-        requestContext.getCommonHeader().setApiVer(apiVersion);
-        requestContext.getCommonHeader().setTimestamp(timeStamp);
-        requestContext.getCommonHeader().setRequestId(requestId);
-        requestContext.getCommonHeader().setSubRequestId(subRequestID);
-        requestContext.getCommonHeader().setOriginatorId(originatorID);
+        CommonHeader commonHeader = requestContext.getCommonHeader();
+        commonHeader.getFlags().setTtl(ttl);
+        commonHeader.setApiVer(apiVersion);
+        commonHeader.setTimestamp(timeStamp);
+        commonHeader.setRequestId(requestId);
+        commonHeader.setSubRequestId(subRequestID);
+        commonHeader.setOriginatorId(originatorID);
         requestContext.setAction(action);
         requestContext.setPayload(payload);
         requestContext.getActionIdentifiers().setVnfId(vnfId);
@@ -135,4 +139,3 @@ public class TestCommandExecutor {
         return commandExecutorInput;
     }
 }
-