+ task.setCommandRequest(getCommandRequest("FIREWALL", 30, new Date(), "12" , setTTLInFlags("30"), VNFOperation.Terminate, "2", "1.0"));
+ setResponseContext(100, task.getCommandRequest().getCommandExecutorInput().getRuntimeContext());
+ task.run();
+ }
+
+ @Test
+ public void testRunPositiveTerminateNotFound() throws SvcLogicException, AAIServiceException{
+ AAIService mockAai = Mockito.mock(AAIService.class);
+
+ Mockito.when(mockAai.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
+ .thenReturn(SvcLogicResource.QueryStatus.NOT_FOUND);
+ Mockito.when(mockAai.getRequestFromResource("generic-vnf")).thenReturn(Mockito.mock(AAIRequest.class));
+ Mockito.when(mockAai.delete(Mockito.any(AAIRequest.class), Mockito.anyString())).thenReturn(true);
+ Whitebox.setInternalState(task, "aaiService", mockAai);
+ Mockito.when(workflowManager.executeWorkflow(anyObject())).thenReturn(getWorkflowResponse());
+ task.setWorkflowManager(workflowManager);
+ task.setRequestHandler(requestHandler);
+ task.setCommandRequest(getCommandRequest("FIREWALL", 30, new Date(), "12" , setTTLInFlags("30"), VNFOperation.Terminate, "2", "1.0"));
+ setResponseContext(100, task.getCommandRequest().getCommandExecutorInput().getRuntimeContext());
+ expectedEx.expect(RuntimeException.class);
+ expectedEx.expectMessage("VNF not found for vnf_id = ");
+ task.run();
+ }
+
+ @Test
+ public void testRunPositiveTerminateFailure() throws SvcLogicException, AAIServiceException{
+ AAIService mockAai = Mockito.mock(AAIService.class);
+
+ Mockito.when(mockAai.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
+ .thenReturn(SvcLogicResource.QueryStatus.FAILURE);
+ Mockito.when(mockAai.getRequestFromResource("generic-vnf")).thenReturn(Mockito.mock(AAIRequest.class));
+ Mockito.when(mockAai.delete(Mockito.any(AAIRequest.class), Mockito.anyString())).thenReturn(true);
+ Whitebox.setInternalState(task, "aaiService", mockAai);
+ Mockito.when(workflowManager.executeWorkflow(anyObject())).thenReturn(getWorkflowResponse());
+ task.setWorkflowManager(workflowManager);
+ task.setRequestHandler(requestHandler);
+ task.setCommandRequest(getCommandRequest("FIREWALL", 30, new Date(), "12" , setTTLInFlags("30"), VNFOperation.Terminate, "2", "1.0"));
+ setResponseContext(100, task.getCommandRequest().getCommandExecutorInput().getRuntimeContext());
+ expectedEx.expect(RuntimeException.class);
+ expectedEx.expectMessage("Error Querying AAI with vnfID = ");
+ task.run();
+ }
+
+ @Test
+ public void testRunPositiveAaiServiceException() throws SvcLogicException, AAIServiceException{
+ AAIService mockAai = Mockito.mock(AAIService.class);
+
+ Mockito.when(mockAai.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
+ .thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
+ Mockito.when(mockAai.getRequestFromResource("generic-vnf")).thenReturn(Mockito.mock(AAIRequest.class));
+ Mockito.when(mockAai.delete(Mockito.any(AAIRequest.class), Mockito.anyString())).thenThrow(new AAIServiceException("ERROR IN DELETE"));
+ Whitebox.setInternalState(task, "aaiService", mockAai);
+ Mockito.when(workflowManager.executeWorkflow(anyObject())).thenReturn(getWorkflowResponse());
+ task.setWorkflowManager(workflowManager);
+ task.setRequestHandler(requestHandler);
+ task.setCommandRequest(getCommandRequest("FIREWALL", 30, new Date(), "12" , setTTLInFlags("30"), VNFOperation.Terminate, "2", "1.0"));
+ setResponseContext(100, task.getCommandRequest().getCommandExecutorInput().getRuntimeContext());
+ expectedEx.expect(RuntimeException.class);
+ expectedEx.expectCause(allOf(isA(AAIServiceException.class),
+ hasProperty("message", is("ERROR IN DELETE"))));
+ task.run();
+ }
+
+ @Test
+ public void testRunSvcLogicException() throws SvcLogicException, AAIServiceException {
+ AAIService mockAai = Mockito.mock(AAIService.class);
+
+ Mockito.when(mockAai.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
+ .thenThrow(new SvcLogicException());
+ Mockito.when(mockAai.getRequestFromResource("generic-vnf")).thenReturn(Mockito.mock(AAIRequest.class));
+ Mockito.when(mockAai.delete(Mockito.any(AAIRequest.class), Mockito.anyString())).thenReturn(true);
+ Whitebox.setInternalState(task, "aaiService", mockAai);
+ Mockito.when(workflowManager.executeWorkflow(anyObject())).thenReturn(getWorkflowResponse());
+ task.setWorkflowManager(workflowManager);
+ task.setRequestHandler(requestHandler);
+ task.setCommandRequest(getCommandRequest("FIREWALL", 30, new Date(), "12" , setTTLInFlags("30"), VNFOperation.Terminate, "2", "1.0"));
+ setResponseContext(100, task.getCommandRequest().getCommandExecutorInput().getRuntimeContext());
+ expectedEx.expect(RuntimeException.class);
+ expectedEx.expectCause(isA(SvcLogicException.class));