2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.executor;
31 import java.time.Instant;
33 import org.junit.Assert;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
38 import org.onap.appc.domainmodel.lcm.CommonHeader;
39 import org.onap.appc.domainmodel.lcm.Flags;
40 import org.onap.appc.domainmodel.lcm.RequestContext;
41 import org.onap.appc.domainmodel.lcm.RuntimeContext;
42 import org.onap.appc.domainmodel.lcm.VNFContext;
43 import org.onap.appc.domainmodel.lcm.VNFOperation;
44 import org.onap.appc.exceptions.APPCException;
45 import org.onap.appc.executionqueue.ExecutionQueueService;
46 import org.onap.appc.executor.impl.*;
47 import org.onap.appc.lifecyclemanager.LifecycleManager;
48 import org.onap.appc.requesthandler.RequestHandler;
49 import org.onap.appc.workflow.WorkFlowManager;
50 import org.powermock.api.mockito.PowerMockito;
52 import java.util.Date;
53 import java.util.concurrent.TimeUnit;
55 import static junit.framework.Assert.assertTrue;
56 import static org.powermock.api.support.membermodification.MemberMatcher.method;
59 @SuppressWarnings("deprecation")
60 public class TestCommandExecutor {
62 private static final String TTL_FLAG= "TTL";
63 private static final String API_VERSION= "2.0.0";
64 private static final String ORIGINATOR_ID= "1";
66 private CommandExecutorImpl commandExecutor;
68 private CommandTaskFactory executionTaskFactory;
70 private RequestHandler requestHandler;
71 private WorkFlowManager workflowManager;
72 private LifecycleManager lifecyclemanager;
74 private ExecutionQueueService executionQueueService;
75 private Instant timeStamp = Instant.now();
76 private String requestId = "1";
77 private RuntimeContext commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30000, "1.0",
78 timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
79 private RuntimeContext commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
80 timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
83 public void init()throws Exception {
84 requestHandler= Mockito.mock(RequestHandler.class);
85 lifecyclemanager= Mockito.mock(LifecycleManager.class);
86 workflowManager= Mockito.mock(WorkFlowManager.class);
88 executionQueueService = Mockito.mock(ExecutionQueueService.class);
90 commandExecutor = new CommandExecutorImpl();
91 executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
92 commandExecutor.setExecutionTaskFactory(executionTaskFactory);
93 commandExecutor.setExecutionQueueService(executionQueueService);
94 LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
95 LCMReadonlyCommandTask lCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
97 Mockito.when(executionTaskFactory.getExecutionTask(commandExecutorInputConfigure)).thenReturn(lcmCommandTask);
98 Mockito.when(executionTaskFactory.getExecutionTask(commandExecutorInputSync)).thenReturn(lCMReadonlyCommandTask);
100 // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
106 public void testPositiveFlow_LCM() throws Exception {
107 //Map <String,Object> flags = setTTLInFlags("30");
108 String requestId = "1";
109 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
111 commandExecutor.executeCommand(commandExecutorInput);
112 } catch (APPCException e) {
113 Assert.fail(e.toString());
119 public void testPositiveFlow_GetConfig(){
120 String requestId = "1";
122 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
124 commandExecutor.executeCommand(commandExecutorInput);
125 } catch (APPCException e) {
126 Assert.fail(e.toString());
132 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){
133 RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();
134 RequestContext requestContext = commandExecutorInput.getRequestContext();
135 requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
136 requestContext.getCommonHeader().setApiVer(apiVersion);
137 requestContext.getCommonHeader().setTimestamp(timeStamp);
138 requestContext.getCommonHeader().setRequestId(requestId);
139 requestContext.getCommonHeader().setSubRequestId(subRequestID);
140 requestContext.getCommonHeader().setOriginatorId(originatorID);
141 requestContext.setAction(action);
142 requestContext.setPayload(payload);
143 requestContext.getActionIdentifiers().setVnfId(vnfId);
144 VNFContext vnfContext = commandExecutorInput.getVnfContext();
145 vnfContext.setType(vnfType);
146 vnfContext.setId(vnfId);
147 vnfContext.setVersion(vnfVersion);
148 return commandExecutorInput;
151 private RuntimeContext createCommandExecutorInputWithSubObjects() {
152 RuntimeContext runtimeContext = new RuntimeContext();
153 RequestContext requestContext = new RequestContext();
154 runtimeContext.setRequestContext(requestContext);
155 CommonHeader commonHeader = new CommonHeader();
156 requestContext.setCommonHeader(commonHeader);
157 commonHeader.setFlags(new Flags(null, false, 0));
158 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
159 requestContext.setActionIdentifiers(actionIdentifiers);
160 VNFContext vnfContext = new VNFContext();
161 runtimeContext.setVnfContext(vnfContext);
162 return runtimeContext;