public WorkflowDef lookupForWorkflowDefinition(String name, Integer version) { Optional<WorkflowDef> potentialDef = version == null ? lookupLatestWorkflowDefinition(name) : lookupWorkflowDefinition(name, version); //Check if the workflow definition is valid WorkflowDef workflowDefinition = potentialDef .orElseThrow(() -> { logger.error("There is no workflow defined with name {} and version {}", name, version); return new ApplicationException( ApplicationException.Code.NOT_FOUND, String.format("No such workflow defined. name=%s, version=%s", name, version) ); } ); return workflowDefinition; }
@Test(expected = IllegalArgumentException.class) public void testLookupWorkflowDefinition() { try{ String workflowName = "test"; when(metadataDAO.get(workflowName, 0)).thenReturn(Optional.of(new WorkflowDef())); Optional<WorkflowDef> optionalWorkflowDef = metadataMapperService.lookupWorkflowDefinition(workflowName, 0); assertTrue(optionalWorkflowDef.isPresent()); metadataMapperService.lookupWorkflowDefinition(null, 0); } catch (ConstraintViolationException ex){ Assert.assertEquals(1, ex.getConstraintViolations().size()); Set<String> messages = getConstraintViolationMessages(ex.getConstraintViolations()); assertTrue(messages.contains("WorkflowIds list cannot be null.")); } }
public WorkflowDef lookupForWorkflowDefinition(String name, Integer version) { Optional<WorkflowDef> potentialDef = version == null ? lookupLatestWorkflowDefinition(name) : lookupWorkflowDefinition(name, version); //Check if the workflow definition is valid WorkflowDef workflowDefinition = potentialDef .orElseThrow(() -> { logger.error("There is no workflow defined with name {} and version {}", name, version); return new ApplicationException( ApplicationException.Code.NOT_FOUND, String.format("No such workflow defined. name=%s, version=%s", name, version) ); } ); return workflowDefinition; }