/*-
* ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 Amdocs
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.openecomp.appc.executor;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
private static final String TTL_FLAG= "TTL";
private static final String API_VERSION= "2.0.0";
private static final String ORIGINATOR_ID= "1";
- private LCMCommandTask executionTask;
- private LCMReadonlyCommandTask LCMReadonlyCommandTask;
private CommandTaskFactory factory ;
private RequestHandler requestHandler;
PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
- PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiService);
+ PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
@Override
public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
workflowManager = Mockito.mock(WorkFlowManager.class);
lifecyclemanager = Mockito.mock(LifecycleManager.class );
- executionTask = new LCMCommandTask(requestHandler,workflowManager,lifecyclemanager);
- LCMReadonlyCommandTask = new LCMReadonlyCommandTask(requestHandler,workflowManager);
factory = new CommandTaskFactory();
factory.setLifecyclemanager(lifecyclemanager);
factory.setWorkflowManager(workflowManager);
@Test
public void testFactory(){
- CommandTask task = factory.getExecutionTask("Configure");
+ CommandTask task = factory.getExecutionTask("Configure", null);
assertEquals(LCMCommandTask.class,task.getClass() );
- task = factory.getExecutionTask("Sync");
+ task = factory.getExecutionTask("Sync", null);
assertEquals(LCMReadonlyCommandTask.class,task.getClass() );
}
@Test
public void testOnRequestCompletion(){
Mockito.doNothing().when(requestHandler).onRequestTTLEnd((RuntimeContext) anyObject(),anyBoolean());
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", "");
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", "");
CommandResponse response = getCommandResponse(VNFOperation.Configure, true, "11", "","1");
- executionTask.onRequestCompletion(request, response);
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
+ executionTask.onRequestCompletion(response);
}
@Test
public void testRunGetConfig(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- LCMReadonlyCommandTask.setCommandRequest(request);
- LCMReadonlyCommandTask.run();
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ LCMReadonlyCommandTask readonlyCommandTask = new LCMReadonlyCommandTask(request, requestHandler,workflowManager);
+ readonlyCommandTask.run();
}
@Test
public void testRun(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- executionTask.setCommandRequest(request);
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
executionTask.run();
}
@Test
public void testRunNegative(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- executionTask.setCommandRequest(request);
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
executionTask.run();
}
CommandResponse getCommandResponse(VNFOperation action , boolean success, String responseId, String payload, String vnfId){
- CommandResponse commandResponse = new CommandResponse();
RuntimeContext runtimeContext = new RuntimeContext();
- commandResponse.setRuntimeContext(runtimeContext);
ResponseContext responseContext = new ResponseContext();
runtimeContext.setResponseContext(responseContext);
RequestContext requestContext = new RequestContext();
responseContext.setStatus(new Status(100, null));
commonHeader.setRequestId(responseId);
responseContext.setPayload(payload);
- commonHeader.setTimestamp(new Date());
+ commonHeader.setTimestamp(Instant.now());
vnfContext.setId(vnfId);
- return commandResponse;
+ return new CommandResponse(runtimeContext);
}
@Test
public void testPositiveFlow_configure() {
- Date timeStamp = new Date();
String requestId = "1";
- RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", "");
+ RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", "");
}
return wfResponse;
}
- private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){
+ 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();
ResponseContext responseContext = createResponseContextWithSuObjects();