@@ -54,6 +54,7 @@ class WorkflowEngineServiceTest {
5454 private static final RestClientException RC_EXC = new RestClientException ("Trigger Failure" );
5555
5656 private static final String DEACTIVATE = "workflow-engine/workflows/deactivate" ;
57+ private static final String HISTORY_INCIDENT = "history/incident" ;
5758 private static final String HISTORY_INSTANCE = "history/process-instance" ;
5859 private static final String PROCESS_DEFINITION = "process-definition" ;
5960
@@ -485,30 +486,74 @@ void startThrowsExceptionWorkflowNotFoundTest() {
485486 });
486487 }
487488
489+ @ Test
490+ void startThrowsExceptionWorkflowNotFoundViaViewTest () {
491+
492+ final JsonNode context = JsonNodeFactory .instance .objectNode ();
493+
494+ when (workflowRepo .getViewById (anyString (), eq (WorkflowOperationalDto .class ))).thenReturn (null );
495+
496+ assertThrows (WorkflowNotFoundException .class , () -> {
497+ workflowEngineService .start (UUID , OKAPI_TENANT , OKAPI_TOKEN , context );
498+ });
499+ }
500+
501+ @ Test
502+ void startThrowsExceptionWorkflowDeploymentNotFoundViaViewTest () {
503+
504+ final ObjectNode objectNode = JsonNodeFactory .instance .objectNode ();
505+ objectNode .put ("id" , UUID );
506+
507+ final ArrayNode arrayNodeSingle = JsonNodeFactory .instance .arrayNode ();
508+
509+ final ResponseEntity <ArrayNode > processEntity = new ResponseEntity <>(arrayNodeSingle , HttpStatus .OK );
510+ final JsonNode context = JsonNodeFactory .instance .objectNode ();
511+
512+ when (workflowRepo .getViewById (anyString (), eq (WorkflowOperationalDto .class ))).thenReturn (workflowOperational );
513+
514+ when (restTemplate .exchange (contains (PROCESS_DEFINITION ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
515+ .thenReturn (processEntity );
516+
517+ assertThrows (WorkflowDeploymentNotFound .class , () -> {
518+ workflowEngineService .start (UUID , OKAPI_TENANT , OKAPI_TOKEN , context );
519+ });
520+ }
521+
488522 @ Test
489523 void historyWorksTest () throws WorkflowDeploymentNotFound , WorkflowEngineServiceException {
490524 WorkflowOperationalDto workflowOperationalDto = (WorkflowOperationalDto ) workflowOperational ;
491- ResponseEntity <ArrayNode > responseEntity = new ResponseEntity <>(HttpStatus .OK );
492- ResponseEntity <ArrayNode > historyResponseEntity = new ResponseEntity <>(HttpStatus .OK );
525+ ResponseEntity <ArrayNode > processEntity = new ResponseEntity <>(HttpStatus .OK );
526+ ResponseEntity <ArrayNode > historyEntity = new ResponseEntity <>(HttpStatus .OK );
527+ ResponseEntity <ArrayNode > incidentEntity = new ResponseEntity <>(HttpStatus .OK );
528+
493529 ObjectNode objectNode = mapper .createObjectNode ();
494530 objectNode .put ("id" , UUID );
495531
496532 ObjectNode historyNode = mapper .createObjectNode ();
497533 historyNode .put ("id" , UUID );
498534 historyNode .put ("history" , VALUE );
499535
500- ArrayNode arrayNode = mapper .createArrayNode ();
501- arrayNode .add (objectNode );
502- setField (responseEntity , "body" , arrayNode );
536+ ObjectNode incidentNode = mapper .createObjectNode ();
537+ incidentNode .put ("id" , UUID );
538+
539+ ArrayNode processNode = mapper .createArrayNode ();
540+ processNode .add (objectNode );
541+ setField (processEntity , "body" , processNode );
503542
504543 ArrayNode historyArrayNode = mapper .createArrayNode ();
505544 historyArrayNode .add (historyNode );
506- setField (historyResponseEntity , "body" , historyArrayNode );
545+ setField (historyEntity , "body" , historyArrayNode );
507546
508547 when (workflowRepo .getViewById (anyString (), eq (WorkflowOperationalDto .class ))).thenReturn (workflowOperationalDto );
509548
510- when (restTemplate .exchange (anyString (), any (HttpMethod .class ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
511- .thenReturn (responseEntity , historyResponseEntity );
549+ when (restTemplate .exchange (contains (PROCESS_DEFINITION ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
550+ .thenReturn (processEntity );
551+
552+ when (restTemplate .exchange (contains (HISTORY_INSTANCE ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
553+ .thenReturn (historyEntity );
554+
555+ when (restTemplate .exchange (contains (HISTORY_INCIDENT ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
556+ .thenReturn (incidentEntity );
512557
513558 JsonNode response = workflowEngineService .history (UUID , OKAPI_TENANT , OKAPI_TOKEN );
514559 assertEquals (historyArrayNode , response );
@@ -552,21 +597,25 @@ void historyWorksWithoutOkFetchingIncidentsHistoryTest() throws WorkflowDeployme
552597 @ Test
553598 void historyThrowsExceptionWithNotOkHttpStatusForProcessTest () {
554599 WorkflowOperationalDto workflowOperationalDto = (WorkflowOperationalDto ) workflowOperational ;
555- ResponseEntity <ArrayNode > responseEntity = new ResponseEntity <>(HttpStatus .OK );
556- ResponseEntity <ArrayNode > historyResponseEntity = new ResponseEntity <>(HttpStatus .RESET_CONTENT );
600+ ResponseEntity <ArrayNode > processEntity = new ResponseEntity <>(HttpStatus .OK );
601+ ResponseEntity <ArrayNode > historyEntity = new ResponseEntity <>(HttpStatus .RESET_CONTENT );
602+
557603 ObjectNode objectNode = mapper .createObjectNode ();
558604 objectNode .put ("id" , UUID );
559605
560- ArrayNode arrayNode = mapper .createArrayNode ();
561- arrayNode .add (objectNode );
562- setField (responseEntity , "body" , arrayNode );
606+ ArrayNode processNode = mapper .createArrayNode ();
607+ processNode .add (objectNode );
608+ setField (processEntity , "body" , processNode );
563609
564- setField (historyResponseEntity , "body" , null );
610+ setField (historyEntity , "body" , null );
565611
566612 when (workflowRepo .getViewById (anyString (), eq (WorkflowOperationalDto .class ))).thenReturn (workflowOperationalDto );
567613
568- when (restTemplate .exchange (anyString (), any (HttpMethod .class ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
569- .thenReturn (responseEntity , historyResponseEntity );
614+ when (restTemplate .exchange (contains (PROCESS_DEFINITION ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
615+ .thenReturn (processEntity );
616+
617+ when (restTemplate .exchange (contains (HISTORY_INSTANCE ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
618+ .thenReturn (historyEntity );
570619
571620 assertThrows (WorkflowEngineServiceException .class , () -> {
572621 workflowEngineService .history (UUID , OKAPI_TENANT , OKAPI_TOKEN );
@@ -591,10 +640,10 @@ void historyThrowsExceptionWithNullIncidentsForProcessTest() {
591640 when (workflowRepo .getViewById (anyString (), eq (WorkflowOperationalDto .class ))).thenReturn (workflowOperationalDto );
592641
593642 when (restTemplate .exchange (contains (PROCESS_DEFINITION ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
594- .thenReturn (processEntity );
643+ .thenReturn (processEntity );
595644
596- when (restTemplate .exchange (contains (HISTORY_INSTANCE ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
597- .thenReturn (historyEntity );
645+ when (restTemplate .exchange (contains (HISTORY_INSTANCE ), eq (HttpMethod .GET ), any (HttpEntity .class ), eq (ArrayNode .class ), anyMap ()))
646+ .thenReturn (historyEntity );
598647
599648 assertThrows (WorkflowEngineServiceException .class , () -> {
600649 workflowEngineService .history (UUID , OKAPI_TENANT , OKAPI_TOKEN );
0 commit comments