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.lifecyclemanager.LifecycleManager;
40 import org.openecomp.appc.requesthandler.RequestHandler;
41 import org.openecomp.appc.workflow.WorkFlowManager;
43 import java.util.Date;
44 import java.util.concurrent.TimeUnit;
46 import static junit.framework.Assert.assertTrue;
49 @SuppressWarnings("deprecation")
50 public class TestCommandExecutor {
52 private static final String TTL_FLAG= "TTL";
53 private static final String API_VERSION= "2.0.0";
54 private static final String ORIGINATOR_ID= "1";
56 CommandExecutorImpl commandExecutor;
58 CommandTaskFactory executionTaskFactory;
60 private RequestHandler requestHandler;
61 private WorkFlowManager workflowManager;
62 private LifecycleManager lifecyclemanager;
64 private ExecutionQueueService executionQueueService;
67 public void init()throws Exception {
68 requestHandler= Mockito.mock(RequestHandler.class);
69 lifecyclemanager= Mockito.mock(LifecycleManager.class);
70 workflowManager= Mockito.mock(WorkFlowManager.class);
72 executionQueueService = Mockito.mock(ExecutionQueueService.class);
74 commandExecutor = new CommandExecutorImpl();
75 executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
76 commandExecutor.setExecutionTaskFactory(executionTaskFactory);
77 commandExecutor.setExecutionQueueService(executionQueueService);
78 LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
79 LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
80 Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure");
81 Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync");
82 // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
88 public void testPositiveFlow_LCM(){
89 //Map <String,Object> flags = setTTLInFlags("30");
90 Date timeStamp = new Date();
91 String requestId = "1";
92 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
94 commandExecutor.executeCommand(commandExecutorInput);
95 } catch (APPCException e) {
96 Assert.fail(e.toString());
102 public void testPositiveFlow_GetConfig(){
103 Date timeStamp = new Date();
104 String requestId = "1";
106 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
108 commandExecutor.executeCommand(commandExecutorInput);
109 } catch (APPCException e) {
110 Assert.fail(e.toString());
116 private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){
117 RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();
118 RequestContext requestContext = commandExecutorInput.getRequestContext();
119 requestContext.getCommonHeader().getFlags().setTtl(ttl);
120 requestContext.getCommonHeader().setApiVer(apiVersion);
121 requestContext.getCommonHeader().setTimestamp(timeStamp);
122 requestContext.getCommonHeader().setRequestId(requestId);
123 requestContext.getCommonHeader().setSubRequestId(subRequestID);
124 requestContext.getCommonHeader().setOriginatorId(originatorID);
125 requestContext.setAction(action);
126 requestContext.setPayload(payload);
127 requestContext.getActionIdentifiers().setVnfId(vnfId);
128 VNFContext vnfContext = commandExecutorInput.getVnfContext();
129 vnfContext.setType(vnfType);
130 vnfContext.setId(vnfId);
131 vnfContext.setVersion(vnfVersion);
132 return commandExecutorInput;
135 private RuntimeContext createCommandExecutorInputWithSubObjects() {
136 RuntimeContext runtimeContext = new RuntimeContext();
137 RequestContext requestContext = new RequestContext();
138 runtimeContext.setRequestContext(requestContext);
139 CommonHeader commonHeader = new CommonHeader();
140 requestContext.setCommonHeader(commonHeader);
141 Flags flags = new Flags();
142 commonHeader.setFlags(flags);
143 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
144 requestContext.setActionIdentifiers(actionIdentifiers);
145 VNFContext vnfContext = new VNFContext();
146 runtimeContext.setVnfContext(vnfContext);
147 return runtimeContext;