summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java
blob: cd33e8b2eced42cc419cde46ee769e7218b6a353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*-
 * ============LICENSE_START=======================================================
 * openECOMP : APP-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 * 						reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.appc.executor;
/**
 * 
 */


import java.time.Instant;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
import org.openecomp.appc.domainmodel.lcm.CommonHeader;
import org.openecomp.appc.domainmodel.lcm.Flags;
import org.openecomp.appc.domainmodel.lcm.RequestContext;
import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
import org.openecomp.appc.domainmodel.lcm.VNFContext;
import org.openecomp.appc.domainmodel.lcm.VNFOperation;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.appc.executionqueue.ExecutionQueueService;
import org.openecomp.appc.executor.impl.CommandExecutorImpl;
import org.openecomp.appc.executor.impl.CommandTaskFactory;
import org.openecomp.appc.executor.impl.LCMCommandTask;
import org.openecomp.appc.executor.impl.LCMReadonlyCommandTask;
import org.openecomp.appc.lifecyclemanager.LifecycleManager;
import org.openecomp.appc.requesthandler.RequestHandler;
import org.openecomp.appc.workflow.WorkFlowManager;


@SuppressWarnings("deprecation")
public class TestCommandExecutor {

		private static final String TTL_FLAG= "TTL";
		private static final String API_VERSION= "2.0.0";
		private static final String ORIGINATOR_ID= "1";

	CommandExecutorImpl commandExecutor;

	CommandTaskFactory executionTaskFactory;

	private RequestHandler requestHandler;
	private WorkFlowManager workflowManager;
	private LifecycleManager lifecyclemanager;

	private ExecutionQueueService executionQueueService;

	@Before
	public void init()throws Exception {
		requestHandler= Mockito.mock(RequestHandler.class);
		lifecyclemanager= Mockito.mock(LifecycleManager.class);
		workflowManager= Mockito.mock(WorkFlowManager.class);

		executionQueueService = Mockito.mock(ExecutionQueueService.class);

		commandExecutor = new CommandExecutorImpl();
		executionTaskFactory = Mockito.mock(CommandTaskFactory.class);
		commandExecutor.setExecutionTaskFactory(executionTaskFactory);
		commandExecutor.setExecutionQueueService(executionQueueService);
		LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
		LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
		Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null);
		Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null);
//		Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);

	}
		

	@Test
	public void testPositiveFlow_LCM(){
		//Map <String,Object> flags = setTTLInFlags("30");
		String requestId = "1";
		RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ;
		try {
			commandExecutor.executeCommand(commandExecutorInput);
		} catch (APPCException e) {
			Assert.fail(e.toString());
		}

	}

	@Test
	public void testPositiveFlow_GetConfig(){
		String requestId = "1";

		RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
		try {
			commandExecutor.executeCommand(commandExecutorInput);
		} catch (APPCException e) {
			Assert.fail(e.toString());
		}

	}

	
	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){
		RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects();		
		RequestContext requestContext = commandExecutorInput.getRequestContext();
		requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl));
		requestContext.getCommonHeader().setApiVer(apiVersion);
		requestContext.getCommonHeader().setTimestamp(timeStamp);
		requestContext.getCommonHeader().setRequestId(requestId);
		requestContext.getCommonHeader().setSubRequestId(subRequestID);
		requestContext.getCommonHeader().setOriginatorId(originatorID);
		requestContext.setAction(action);
		requestContext.setPayload(payload);
		requestContext.getActionIdentifiers().setVnfId(vnfId);
		VNFContext vnfContext = commandExecutorInput.getVnfContext();
		vnfContext.setType(vnfType);
		vnfContext.setId(vnfId);
		vnfContext.setVersion(vnfVersion);
		return commandExecutorInput;
	}

	private RuntimeContext createCommandExecutorInputWithSubObjects() {
		RuntimeContext runtimeContext = new RuntimeContext();
        RequestContext requestContext = new RequestContext();
		runtimeContext.setRequestContext(requestContext);
		CommonHeader commonHeader = new CommonHeader();
		requestContext.setCommonHeader(commonHeader);
		commonHeader.setFlags(new Flags(null, false, 0));
		ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
		requestContext.setActionIdentifiers(actionIdentifiers);
		VNFContext vnfContext = new VNFContext();
		runtimeContext.setVnfContext(vnfContext);
		return runtimeContext;
	}



}