2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.executor;
29 import java.time.Instant;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
36 import org.openecomp.appc.domainmodel.lcm.CommonHeader;
37 import org.openecomp.appc.domainmodel.lcm.Flags;
38 import org.openecomp.appc.domainmodel.lcm.RequestContext;
39 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
40 import org.openecomp.appc.domainmodel.lcm.VNFContext;
41 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
42 import org.openecomp.appc.exceptions.APPCException;
43 import org.openecomp.appc.executionqueue.ExecutionQueueService;
44 import org.openecomp.appc.executor.impl.CommandExecutorImpl;
45 import org.openecomp.appc.executor.impl.CommandTaskFactory;
46 import org.openecomp.appc.executor.impl.LCMCommandTask;
47 import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
48 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
49 import org.openecomp.appc.requesthandler.RequestHandler;
50 import org.openecomp.appc.workflow.WorkFlowManager;
53 @SuppressWarnings("deprecation")
54 public class TestCommandExecutor {
56 private static final String TTL_FLAG= "TTL";
57 private static final String API_VERSION= "2.0.0";
58 private static final String ORIGINATOR_ID= "1";
60 CommandExecutorImpl commandExecutor;
62 CommandTaskFactory executionTaskFactory;
64 private RequestHandler requestHandler;
65 private WorkFlowManager workflowManager;
66 private LifecycleManager lifecyclemanager;
68 private ExecutionQueueService executionQueueService;
71 public void init()throws Exception {
72 requestHandler= Mockito.mock(RequestHandler.class);
73 lifecyclemanager= Mockito.mock(LifecycleManager.class);
74 workflowManager= Mockito.mock(WorkFlowManager.class);
76 executionQueueService = Mockito.mock(ExecutionQueueService.class);
78 commandExecutor = new CommandExecutorImpl();
79 executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
80 commandExecutor.setExecutionTaskFactory(executionTaskFactory);
81 commandExecutor.setExecutionQueueService(executionQueueService);
82 LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
83 LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
84 Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null);
85 Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null);
86 // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
92 public void testPositiveFlow_LCM(){
93 //Map <String,Object> flags = setTTLInFlags("30");
94 String requestId = "1";
95 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
97 commandExecutor.executeCommand(commandExecutorInput);
98 } catch (APPCException e) {
99 Assert.fail(e.toString());
105 public void testPositiveFlow_GetConfig(){
106 String requestId = "1";
108 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
110 commandExecutor.executeCommand(commandExecutorInput);
111 } catch (APPCException e) {
112 Assert.fail(e.toString());
118 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){
119 RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();
120 RequestContext requestContext = commandExecutorInput.getRequestContext();
121 requestContext.getCommonHeader().setFlags(new Flags(null, false, 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 = commandExecutorInput.getVnfContext();
131 vnfContext.setType(vnfType);
132 vnfContext.setId(vnfId);
133 vnfContext.setVersion(vnfVersion);
134 return commandExecutorInput;
137 private RuntimeContext 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 commonHeader.setFlags(new Flags(null, false, 0));
144 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
145 requestContext.setActionIdentifiers(actionIdentifiers);
146 VNFContext vnfContext = new VNFContext();
147 runtimeContext.setVnfContext(vnfContext);
148 return runtimeContext;