WorkflowDefinitionResource extends JaxRsResource { @GET @ApiOperation(value = "List workflow definitions", response = ListWorkflowDefinitionResponse.class, responseContainer = "List", notes = "Returns workflow definition(s): all possible states, transitions between states and other setting metadata. The workflow definition can deployed in nFlow engine or historical workflow definition stored in the database.") public Response listWorkflowDefinitions(@QueryParam("type") @ApiParam(value = "Included workflow types") List<String> types) { return handleExceptions( () -> ok(super.listWorkflowDefinitions(types, workflowDefinitions, converter, workflowDefinitionDao))); } @Inject  WorkflowDefinitionResource(WorkflowDefinitionService workflowDefinitions, ListWorkflowDefinitionConverter converter,
      WorkflowDefinitionDao workflowDefinitionDao); @GET @ApiOperation(value = "List workflow definitions", response = ListWorkflowDefinitionResponse.class, responseContainer = "List", notes = "Returns workflow definition(s): all possible states, transitions between states and other setting metadata. The workflow definition can deployed in nFlow engine or historical workflow definition stored in the database.") Response listWorkflowDefinitions(@QueryParam("type") @ApiParam(value = "Included workflow types") List<String> types);  }
@Test public void listWorkflowDefinitionsFindsExistingDefinition() { List<ListWorkflowDefinitionResponse> ret = resource.listWorkflowDefinitions(asList("dummy")).readEntity(definitionListType); assertThat(ret.size(), is(1)); verify(workflowDefinitionDao, never()).queryStoredWorkflowDefinitions(anyCollection()); }
@Test public void listWorkflowDefinitionsDoesNotFindNonExistentDefinition() { List<ListWorkflowDefinitionResponse> ret = resource.listWorkflowDefinitions(asList("nonexistent")).readEntity(definitionListType); assertThat(ret.size(), is(0)); verify(workflowDefinitionDao).queryStoredWorkflowDefinitions(stringList.capture()); assertThat(stringList.getValue(), containsElements(asList("nonexistent"))); }
@Test public void listWorkflowDefinitionsFindsExistingDefinitionWithoutArguments() { List<ListWorkflowDefinitionResponse> ret = resource.listWorkflowDefinitions(emptyList()).readEntity(definitionListType); assertThat(ret.size(), is(1)); verify(workflowDefinitionDao).queryStoredWorkflowDefinitions(stringList.capture()); assertThat(stringList.getValue().size(), is(0)); }
@Test public void listWorkflowDefinitionsFindsExistingAndStoredDefinitionsWithoutArguments() { StoredWorkflowDefinition storedDefinitionDummy = mock(StoredWorkflowDefinition.class); StoredWorkflowDefinition storedDefinitionNew = mock(StoredWorkflowDefinition.class); when(workflowDefinitionDao.queryStoredWorkflowDefinitions(anyCollection())).thenReturn(asList(storedDefinitionDummy, storedDefinitionNew)); ListWorkflowDefinitionResponse storedResponseDummy = mock(ListWorkflowDefinitionResponse.class, "dbDummy"); ListWorkflowDefinitionResponse storedResponseNew = mock(ListWorkflowDefinitionResponse.class, "dbNew"); storedDefinitionDummy.type = "dummy"; when(converter.convert(storedDefinitionNew)).thenReturn(storedResponseNew); storedDefinitionNew.type = "new"; Collection<ListWorkflowDefinitionResponse> ret = resource.listWorkflowDefinitions(emptyList()).readEntity(definitionListType); assertThat(ret, hasItems(storedResponseNew, dummyResponse)); assertThat(ret, not(hasItem(storedResponseDummy))); }
@Test public void listWorkflowDefinitionsFindsExistingAndStoredDefinitionsWithDbType() { StoredWorkflowDefinition storedDefinitionNew = mock(StoredWorkflowDefinition.class); when(workflowDefinitionDao.queryStoredWorkflowDefinitions(anyCollection())).thenReturn(asList(storedDefinitionNew)); ListWorkflowDefinitionResponse storedResponseNew = mock(ListWorkflowDefinitionResponse.class, "dbNew"); when(converter.convert(storedDefinitionNew)).thenReturn(storedResponseNew); storedDefinitionNew.type = "new"; List<ListWorkflowDefinitionResponse> ret = resource.listWorkflowDefinitions(asList("new")).readEntity(definitionListType); assertThat(ret, hasItems(storedResponseNew)); }