2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.appc.executor;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.openecomp.appc.domainmodel.lcm.*;
33 import org.openecomp.appc.exceptions.APPCException;
34 import org.openecomp.appc.executionqueue.ExecutionQueueService;
35 import org.openecomp.appc.executor.impl.CommandExecutorImpl;
36 import org.openecomp.appc.executor.impl.CommandTaskFactory;
37 import org.openecomp.appc.executor.impl.LCMCommandTask;
38 import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
39 import org.openecomp.appc.executor.objects.CommandExecutorInput;
40 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
41 import org.openecomp.appc.requesthandler.RequestHandler;
42 import org.openecomp.appc.workflow.WorkFlowManager;
44 import java.util.Date;
45 import java.util.concurrent.TimeUnit;
47 import static junit.framework.Assert.assertTrue;
50 @SuppressWarnings("deprecation")
51 public class TestCommandExecutor {
53 private static final String TTL_FLAG= "TTL";
54 private static final String API_VERSION= "2.0.0";
55 private static final String ORIGINATOR_ID= "1";
57 CommandExecutorImpl commandExecutor;
59 CommandTaskFactory executionTaskFactory;
61 private RequestHandler requestHandler;
62 private WorkFlowManager workflowManager;
63 private LifecycleManager lifecyclemanager;
65 private ExecutionQueueService executionQueueService;
68 public void init()throws Exception {
69 requestHandler= Mockito.mock(RequestHandler.class);
70 lifecyclemanager= Mockito.mock(LifecycleManager.class);
71 workflowManager= Mockito.mock(WorkFlowManager.class);
73 executionQueueService = Mockito.mock(ExecutionQueueService.class);
75 commandExecutor = new CommandExecutorImpl();
76 executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
77 commandExecutor.setExecutionTaskFactory(executionTaskFactory);
78 commandExecutor.setExecutionQueueService(executionQueueService);
79 LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
80 LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
81 Mockito.when(executionTaskFactory.getExecutionTask("Configure")).thenReturn(lcmCommandTask);
82 Mockito.when(executionTaskFactory.getExecutionTask("Sync")).thenReturn(LCMReadonlyCommandTask);
83 // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
89 public void testPositiveFlow_LCM(){
90 //Map <String,Object> flags = setTTLInFlags("30");
91 Date timeStamp = new Date();
92 String requestId = "1";
93 CommandExecutorInput commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
95 commandExecutor.executeCommand(commandExecutorInput);
96 } catch (APPCException e) {
97 Assert.fail(e.toString());
103 public void testPositiveFlow_GetConfig(){
104 Date timeStamp = new Date();
105 String requestId = "1";
107 CommandExecutorInput commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
109 commandExecutor.executeCommand(commandExecutorInput);
110 } catch (APPCException e) {
111 Assert.fail(e.toString());
117 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){
118 CommandExecutorInput commandExecutorInput = createCommandExecutorInputWithSubObjects();
119 RuntimeContext runtimeContext = commandExecutorInput.getRuntimeContext();
120 RequestContext requestContext = runtimeContext.getRequestContext();
121 requestContext.getCommonHeader().getFlags().setTtl(ttl);
122 requestContext.getCommonHeader().setApiVer(apiVersion);
123 requestContext.getCommonHeader().setTimestamp(timeStamp);
124 requestContext.getCommonHeader().setRequestId(requestId);
125 requestContext.getCommonHeader().setSubRequestId(subRequestID);
126 requestContext.getCommonHeader().setOriginatorId(originatorID);
127 requestContext.setAction(action);
128 requestContext.setPayload(payload);
129 requestContext.getActionIdentifiers().setVnfId(vnfId);
130 VNFContext vnfContext = runtimeContext.getVnfContext();
131 vnfContext.setType(vnfType);
132 vnfContext.setId(vnfId);
133 vnfContext.setVersion(vnfVersion);
134 return commandExecutorInput;
137 private CommandExecutorInput createCommandExecutorInputWithSubObjects() {
138 RuntimeContext runtimeContext = new RuntimeContext();
139 RequestContext requestContext = new RequestContext();
140 runtimeContext.setRequestContext(requestContext);
141 CommonHeader commonHeader = new CommonHeader();
142 requestContext.setCommonHeader(commonHeader);
143 Flags flags = new Flags();
144 commonHeader.setFlags(flags);
145 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
146 requestContext.setActionIdentifiers(actionIdentifiers);
147 VNFContext vnfContext = new VNFContext();
148 runtimeContext.setVnfContext(vnfContext);
149 return new CommandExecutorInput(runtimeContext, 0);