Applying license changes to all files
[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  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.executor;
26 /**
27  * 
28  */
29
30
31 import java.time.Instant;
32
33 import org.junit.Assert;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
38 import org.openecomp.appc.domainmodel.lcm.CommonHeader;
39 import org.openecomp.appc.domainmodel.lcm.Flags;
40 import org.openecomp.appc.domainmodel.lcm.RequestContext;
41 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
42 import org.openecomp.appc.domainmodel.lcm.VNFContext;
43 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
44 import org.openecomp.appc.exceptions.APPCException;
45 import org.openecomp.appc.executionqueue.ExecutionQueueService;
46 import org.openecomp.appc.executor.impl.CommandExecutorImpl;
47 import org.openecomp.appc.executor.impl.CommandTaskFactory;
48 import org.openecomp.appc.executor.impl.LCMCommandTask;
49 import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
50 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
51 import org.openecomp.appc.requesthandler.RequestHandler;
52 import org.openecomp.appc.workflow.WorkFlowManager;
53
54
55 @SuppressWarnings("deprecation")
56 public class TestCommandExecutor {
57
58                 private static final String TTL_FLAG= "TTL";
59                 private static final String API_VERSION= "2.0.0";
60                 private static final String ORIGINATOR_ID= "1";
61
62         CommandExecutorImpl commandExecutor;
63
64         CommandTaskFactory executionTaskFactory;
65
66         private RequestHandler requestHandler;
67         private WorkFlowManager workflowManager;
68         private LifecycleManager lifecyclemanager;
69
70         private ExecutionQueueService executionQueueService;
71
72         @Before
73         public void init()throws Exception {
74                 requestHandler= Mockito.mock(RequestHandler.class);
75                 lifecyclemanager= Mockito.mock(LifecycleManager.class);
76                 workflowManager= Mockito.mock(WorkFlowManager.class);
77
78                 executionQueueService = Mockito.mock(ExecutionQueueService.class);
79
80                 commandExecutor = new CommandExecutorImpl();
81                 executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
82                 commandExecutor.setExecutionTaskFactory(executionTaskFactory);
83                 commandExecutor.setExecutionQueueService(executionQueueService);
84                 LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
85                 LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
86                 Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null);
87                 Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null);
88 //              Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
89
90         }
91                 
92
93         @Test
94         public void testPositiveFlow_LCM(){
95                 //Map <String,Object> flags = setTTLInFlags("30");
96                 String requestId = "1";
97                 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
98                 try {
99                         commandExecutor.executeCommand(commandExecutorInput);
100                 } catch (APPCException e) {
101                         Assert.fail(e.toString());
102                 }
103
104         }
105
106         @Test
107         public void testPositiveFlow_GetConfig(){
108                 String requestId = "1";
109
110                 RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
111                 try {
112                         commandExecutor.executeCommand(commandExecutorInput);
113                 } catch (APPCException e) {
114                         Assert.fail(e.toString());
115                 }
116
117         }
118
119         
120         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){
121                 RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();               
122                 RequestContext requestContext = commandExecutorInput.getRequestContext();
123                 requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
124                 requestContext.getCommonHeader().setApiVer(apiVersion);
125                 requestContext.getCommonHeader().setTimestamp(timeStamp);
126                 requestContext.getCommonHeader().setRequestId(requestId);
127                 requestContext.getCommonHeader().setSubRequestId(subRequestID);
128                 requestContext.getCommonHeader().setOriginatorId(originatorID);
129                 requestContext.setAction(action);
130                 requestContext.setPayload(payload);
131                 requestContext.getActionIdentifiers().setVnfId(vnfId);
132                 VNFContext vnfContext = commandExecutorInput.getVnfContext();
133                 vnfContext.setType(vnfType);
134                 vnfContext.setId(vnfId);
135                 vnfContext.setVersion(vnfVersion);
136                 return commandExecutorInput;
137         }
138
139         private RuntimeContext createCommandExecutorInputWithSubObjects() {
140                 RuntimeContext runtimeContext = new RuntimeContext();
141         RequestContext requestContext = new RequestContext();
142                 runtimeContext.setRequestContext(requestContext);
143                 CommonHeader commonHeader = new CommonHeader();
144                 requestContext.setCommonHeader(commonHeader);
145                 commonHeader.setFlags(new Flags(null, false, 0));
146                 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
147                 requestContext.setActionIdentifiers(actionIdentifiers);
148                 VNFContext vnfContext = new VNFContext();
149                 runtimeContext.setVnfContext(vnfContext);
150                 return runtimeContext;
151         }
152
153
154
155 }
156