Change nexus values to properties
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / test / java / org / openecomp / appc / executor / TestCommandExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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  */
21
22 package org.openecomp.appc.executor;
23 /**
24  * 
25  */
26
27
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;
43
44 import java.util.Date;
45 import java.util.concurrent.TimeUnit;
46
47 import static junit.framework.Assert.assertTrue;
48
49
50 @SuppressWarnings("deprecation")
51 public class TestCommandExecutor {
52
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";
56
57         CommandExecutorImpl commandExecutor;
58
59         CommandTaskFactory executionTaskFactory;
60
61         private RequestHandler requestHandler;
62         private WorkFlowManager workflowManager;
63         private LifecycleManager lifecyclemanager;
64
65         private ExecutionQueueService executionQueueService;
66
67         @Before
68         public void init()throws Exception {
69                 requestHandler= Mockito.mock(RequestHandler.class);
70                 lifecyclemanager= Mockito.mock(LifecycleManager.class);
71                 workflowManager= Mockito.mock(WorkFlowManager.class);
72
73                 executionQueueService = Mockito.mock(ExecutionQueueService.class);
74
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);
84
85         }
86                 
87
88         @Test
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", "") ;
94                 try {
95                         commandExecutor.executeCommand(commandExecutorInput);
96                 } catch (APPCException e) {
97                         Assert.fail(e.toString());
98                 }
99
100         }
101
102         @Test
103         public void testPositiveFlow_GetConfig(){
104                 Date timeStamp = new Date();
105                 String requestId = "1";
106
107                 CommandExecutorInput commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
108                 try {
109                         commandExecutor.executeCommand(commandExecutorInput);
110                 } catch (APPCException e) {
111                         Assert.fail(e.toString());
112                 }
113
114         }
115
116         
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;
135         }
136
137         private CommandExecutorInput createCommandExecutorInputWithSubObjects() {
138                 CommandExecutorInput commandExecutorInput = new CommandExecutorInput();
139                 RuntimeContext runtimeContext = new RuntimeContext();
140                 commandExecutorInput.setRuntimeContext(runtimeContext);
141                 RequestContext requestContext = new RequestContext();
142                 runtimeContext.setRequestContext(requestContext);
143                 CommonHeader commonHeader = new CommonHeader();
144                 requestContext.setCommonHeader(commonHeader);
145                 Flags flags = new Flags();
146                 commonHeader.setFlags(flags);
147                 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
148                 requestContext.setActionIdentifiers(actionIdentifiers);
149                 VNFContext vnfContext = new VNFContext();
150                 runtimeContext.setVnfContext(vnfContext);
151                 return commandExecutorInput;
152         }
153
154
155
156 }
157