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 java.time.Instant;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
35 import org.openecomp.appc.domainmodel.lcm.CommonHeader;
36 import org.openecomp.appc.domainmodel.lcm.Flags;
37 import org.openecomp.appc.domainmodel.lcm.RequestContext;
38 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
39 import org.openecomp.appc.domainmodel.lcm.VNFContext;
40 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
41 import org.openecomp.appc.exceptions.APPCException;
42 import org.openecomp.appc.executionqueue.ExecutionQueueService;
43 import org.openecomp.appc.executor.impl.CommandExecutorImpl;
44 import org.openecomp.appc.executor.impl.CommandTaskFactory;
45 import org.openecomp.appc.executor.impl.LCMCommandTask;
46 import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
47 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
48 import org.openecomp.appc.requesthandler.RequestHandler;
49 import org.openecomp.appc.workflow.WorkFlowManager;
52 @SuppressWarnings("deprecation")
53 public class TestCommandExecutor {
55 private static final String TTL_FLAG= "TTL";
56 private static final String API_VERSION= "2.0.0";
57 private static final String ORIGINATOR_ID= "1";
59 CommandExecutorImpl commandExecutor;
61 CommandTaskFactory executionTaskFactory;
63 private RequestHandler requestHandler;
64 private WorkFlowManager workflowManager;
65 private LifecycleManager lifecyclemanager;
67 private ExecutionQueueService executionQueueService;
70 public void init()throws Exception {
71 requestHandler= Mockito.mock(RequestHandler.class);
72 lifecyclemanager= Mockito.mock(LifecycleManager.class);
73 workflowManager= Mockito.mock(WorkFlowManager.class);
75 executionQueueService = Mockito.mock(ExecutionQueueService.class);
77 commandExecutor = new CommandExecutorImpl();
78 executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
79 commandExecutor.setExecutionTaskFactory(executionTaskFactory);
80 commandExecutor.setExecutionQueueService(executionQueueService);
81 LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
82 LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
83 Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null);
84 Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null);
85 // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
91 public void testPositiveFlow_LCM(){
92 //Map <String,Object> flags = setTTLInFlags("30");
93 String requestId = "1";
94 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
96 commandExecutor.executeCommand(commandExecutorInput);
97 } catch (APPCException e) {
98 Assert.fail(e.toString());
104 public void testPositiveFlow_GetConfig(){
105 String requestId = "1";
107 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
109 commandExecutor.executeCommand(commandExecutorInput);
110 } catch (APPCException e) {
111 Assert.fail(e.toString());
117 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){
118 RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();
119 RequestContext requestContext = commandExecutorInput.getRequestContext();
120 requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
121 requestContext.getCommonHeader().setApiVer(apiVersion);
122 requestContext.getCommonHeader().setTimestamp(timeStamp);
123 requestContext.getCommonHeader().setRequestId(requestId);
124 requestContext.getCommonHeader().setSubRequestId(subRequestID);
125 requestContext.getCommonHeader().setOriginatorId(originatorID);
126 requestContext.setAction(action);
127 requestContext.setPayload(payload);
128 requestContext.getActionIdentifiers().setVnfId(vnfId);
129 VNFContext vnfContext = commandExecutorInput.getVnfContext();
130 vnfContext.setType(vnfType);
131 vnfContext.setId(vnfId);
132 vnfContext.setVersion(vnfVersion);
133 return commandExecutorInput;
136 private RuntimeContext createCommandExecutorInputWithSubObjects() {
137 RuntimeContext runtimeContext = new RuntimeContext();
138 RequestContext requestContext = new RequestContext();
139 runtimeContext.setRequestContext(requestContext);
140 CommonHeader commonHeader = new CommonHeader();
141 requestContext.setCommonHeader(commonHeader);
142 commonHeader.setFlags(new Flags(null, false, 0));
143 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
144 requestContext.setActionIdentifiers(actionIdentifiers);
145 VNFContext vnfContext = new VNFContext();
146 runtimeContext.setVnfContext(vnfContext);
147 return runtimeContext;