- private static final String TTL_FLAG= "TTL";
- private static final String API_VERSION= "2.0.0";
- private static final String ORIGINATOR_ID= "1";
-
- private CommandExecutorImpl commandExecutor;
-
- private CommandTaskFactory executionTaskFactory;
-
- private RequestHandler requestHandler;
- private WorkFlowManager workflowManager;
- private LifecycleManager lifecyclemanager;
-
- private ExecutionQueueService executionQueueService;
- private Instant timeStamp = Instant.now();
- private String requestId = "1";
- private RuntimeContext commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30000, "1.0",
- timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
- private RuntimeContext commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
- timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
-
- @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.when(executionTaskFactory.getExecutionTask(commandExecutorInputConfigure)).thenReturn(lcmCommandTask);
- Mockito.when(executionTaskFactory.getExecutionTask(commandExecutorInputSync)).thenReturn(lCMReadonlyCommandTask);
-
-// Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
-
- }
-
-
- @Test
- public void testPositiveFlow_LCM() throws Exception {
- //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();
+ private static final String TTL_FLAG= "TTL";
+ private static final String API_VERSION= "2.0.0";
+ private static final String ORIGINATOR_ID= "1";
+
+ private CommandExecutorImpl commandExecutor;
+
+ private RequestHandler requestHandler;
+ private WorkFlowManager workflowManager;
+ private ExecutionQueueService executionQueueService;
+
+ private Date timeStamp = new Date();
+ private String requestId = "1";
+ private CommandExecutorInput commandExecutorInputConfigure = pouplateCommandExecutorInput("FIREWALL", 30000, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure,"15","") ;
+ private CommandExecutorInput commandExecutorInputSync = pouplateCommandExecutorInput("FIREWALL", 30, "1.0",
+ timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ;
+
+ @Before
+ public void init()throws Exception {
+ requestHandler= Mockito.mock(RequestHandler.class);
+ workflowManager= Mockito.mock(WorkFlowManager.class);
+
+ executionQueueService = Mockito.mock(ExecutionQueueService.class);
+
+ commandExecutor = new CommandExecutorImpl();
+ commandExecutor.setExecutionQueueService(executionQueueService);
+ commandExecutor.setRequestHandler(requestHandler);
+ commandExecutor.setWorkflowManager(workflowManager);
+ commandExecutor.initialize();
+ CommandTask commandTask = Mockito.mock(CommandTask.class);
+ Mockito.when(commandTask.getCommandRequest()).thenReturn(new CommandRequest(commandExecutorInputConfigure));
+ PowerMockito.whenNew(CommandTask.class).withParameterTypes(RequestHandler.class,WorkFlowManager.class).withArguments(requestHandler,workflowManager).thenReturn(commandTask);
+ }
+
+
+ @Test
+ public void testPositiveFlow_LCM() throws Exception {
+ //Map <String,Object> flags = setTTLInFlags("30");
+ try {
+ commandExecutor.executeCommand(commandExecutorInputConfigure);
+ } catch (APPCException e) {
+ Assert.fail(e.toString());
+ }
+
+ }
+
+ @Test(expected = APPCException.class)
+ public void testNegativeFlow_LCM() throws APPCException{
+ Mockito.doThrow(new APPCException("Failed to enqueue request")).when(executionQueueService).putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit) Mockito.anyObject());
+ commandExecutor.executeCommand(commandExecutorInputSync);
+ }
+
+
+ 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){
+ CommandExecutorInput commandExecutorInput = createCommandExecutorInputWithSubObjects();
+ RuntimeContext runtimeContext = commandExecutorInput.getRuntimeContext();
+ RequestContext requestContext = runtimeContext.getRequestContext();
+ requestContext.getCommonHeader().getFlags().setTtl(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 = runtimeContext.getVnfContext();
+ vnfContext.setType(vnfType);
+ vnfContext.setId(vnfId);
+ vnfContext.setVersion(vnfVersion);
+ return commandExecutorInput;
+ }
+
+ private CommandExecutorInput createCommandExecutorInputWithSubObjects() {
+ CommandExecutorInput commandExecutorInput = new CommandExecutorInput();
+ RuntimeContext runtimeContext = new RuntimeContext();
+ commandExecutorInput.setRuntimeContext(runtimeContext);