WorkflowDefinitionsDataProvider implements DDMDataProvider { @Override public DDMDataProviderResponse getData( DDMDataProviderRequest ddmDataProviderRequest) throws DDMDataProviderException { List<KeyValuePair> keyValuePairs = new ArrayList<>(); Locale locale = ddmDataProviderRequest.getLocale(); keyValuePairs.add( new KeyValuePair( "no-workflow", LanguageUtil.get(locale, "no-workflow"))); DDMDataProviderResponse.Builder builder = DDMDataProviderResponse.Builder.newBuilder(); if (workflowDefinitionManager == null) { builder = builder.withOutput("Default-Output", keyValuePairs); return builder.build(); } try { List<WorkflowDefinition> workflowDefinitions = workflowDefinitionManager.getActiveWorkflowDefinitions( ddmDataProviderRequest.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); String languageId = LocaleUtil.toLanguageId(locale); for (WorkflowDefinition workflowDefinition : workflowDefinitions) { String value = workflowDefinition.getName() + StringPool.AT + workflowDefinition.getVersion(); keyValuePairs.add( new KeyValuePair( value, workflowDefinition.getTitle(languageId))); } builder = builder.withOutput("Default-Output", keyValuePairs); } catch (WorkflowException workflowException) { throw new DDMDataProviderException(workflowException); } return builder.build(); }  @Override DDMDataProviderResponse getData(
			DDMDataProviderRequest ddmDataProviderRequest); @Override Class<?> getSettings();  }
@Test public void testGetWorkflowDefinitions() throws Exception { DDMDataProviderRequest.Builder builder = DDMDataProviderRequest.Builder.newBuilder(); DDMDataProviderRequest ddmDataProviderRequest = builder.withLocale( _locale ).withCompanyId( 1L ).build(); _workflowDefinitionsDataProvider.workflowDefinitionManager = _workflowDefinitionManager; WorkflowDefinition workflowDefinition1 = mock(WorkflowDefinition.class); _setUpWorkflowDefinition( workflowDefinition1, "definition1", 1, "Definition 1"); WorkflowDefinition workflowDefinition2 = mock(WorkflowDefinition.class); _setUpWorkflowDefinition( workflowDefinition2, "definition2", 2, "Definition 2"); when( _workflowDefinitionManager.getActiveWorkflowDefinitions( 1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null) ).thenReturn( Arrays.asList(workflowDefinition1, workflowDefinition2) ); DDMDataProviderResponse ddmDataProviderResponse = _workflowDefinitionsDataProvider.getData(ddmDataProviderRequest); Assert.assertTrue(ddmDataProviderResponse.hasOutput("Default-Output")); Optional<List<KeyValuePair>> optional = ddmDataProviderResponse.getOutputOptional( "Default-Output", List.class); Assert.assertTrue(optional.isPresent()); List<KeyValuePair> keyValuePairs = new ArrayList<KeyValuePair>() { { add(new KeyValuePair("no-workflow", "No Workflow")); add(new KeyValuePair("definition1@1", "Definition 1")); add(new KeyValuePair("definition2@2", "Definition 2")); } }; Assert.assertEquals(keyValuePairs, optional.get()); }
@Test public void testNullWorkflowDefinitionManager() throws Exception { DDMDataProviderRequest.Builder builder = DDMDataProviderRequest.Builder.newBuilder(); DDMDataProviderRequest ddmDataProviderRequest = builder.withLocale( _locale ).build(); DDMDataProviderResponse ddmDataProviderResponse = _workflowDefinitionsDataProvider.getData(ddmDataProviderRequest); Assert.assertTrue(ddmDataProviderResponse.hasOutput("Default-Output")); Optional<List<KeyValuePair>> optional = ddmDataProviderResponse.getOutputOptional( "Default-Output", List.class); Assert.assertTrue(optional.isPresent()); List<KeyValuePair> keyValuePairs = new ArrayList<KeyValuePair>() { { add(new KeyValuePair("no-workflow", "No Workflow")); } }; Assert.assertEquals(keyValuePairs, optional.get()); }
@Test(expected = DDMDataProviderException.class) public void testThrowDDMDataProviderException() throws Exception { DDMDataProviderRequest.Builder builder = DDMDataProviderRequest.Builder.newBuilder(); DDMDataProviderRequest ddmDataProviderRequest = builder.withLocale( _locale ).withCompanyId( 1L ).build(); _workflowDefinitionsDataProvider.workflowDefinitionManager = _workflowDefinitionManager; when( _workflowDefinitionManager.getActiveWorkflowDefinitions( 1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null) ).thenThrow( WorkflowException.class ); _workflowDefinitionsDataProvider.getData(ddmDataProviderRequest); }