ContractToPageMapper { public Page createFormPage(String name, Contract contract, FormScope scope) { switch (scope) { case OVERVIEW: return new CaseOverviewPageCreationStrategy(contractToContainerMapper).create(name, contract); case PROCESS: return new ProcessInstantiationFormCreationStrategy(contractToWidgetMapper, contractToContainerMapper, mapper, businessQueryDataFactory).create(name, contract); case TASK: default: return new TaskFormCreationStrategy(contractToWidgetMapper, contractToContainerMapper, mapper, dimensionFactory, businessQueryDataFactory).create(name, contract); } } @Inject  ContractToPageMapper(ContractInputToWidgetMapper contractToWidgetMapper, ContractToContainerMapper contractToContainerMapper,
            JacksonObjectMapper mapper, DimensionFactory dimensionFactory,BusinessQueryDataFactory businessQueryDataFactory); Page createFormPage(String name, Contract contract, FormScope scope);  }
@Test public void visit_a_contract_when_creating_a_page() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContract(), FormScope.TASK); assertThat(getTaskFormContainerContent(page).getRows()).hasSize(6); }
@Test public void should_create_a_page_with_the_form_type() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithMultipleInput(), FormScope.TASK); assertThat(page.getType()).isEqualTo("form"); }
@Test public void should_create_a_page_with_a_form_container() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithMultipleInput(), FormScope.TASK); assertThat(page.getRows()).hasSize(2); assertThat(page.getRows().get(1).get(0)).isInstanceOf(FormContainer.class); }
@Test public void create_a_page_with_form_input_and_output() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithMultipleInput(), FormScope.TASK); assertThat(page.getVariables()).contains(entry("formInput", aJSONVariable().value(objectMapper.prettyPrint("{\"names\":[]}")).build())); assertThat(page.getVariables()).contains(entry("formOutput", anExpressionVariable().value("return {\n\tnames: $data.formInput.names\n}").build())); }
@Test public void create_a_page_with_a_context_url_data_for_task() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithMultipleInput(), FormScope.TASK); assertThat(page.getVariables()).contains(entry("context", anURLVariable().value("../API/bpm/userTask/{{taskId}}/context").build())); }
@Test public void create_a_page_with_a_id_expression_data_for_task_scope() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithMultipleInput(), FormScope.TASK); assertThat(page.getVariables()).contains(entry("taskId", aUrlParameterVariable().value("id").build())); }
@Test public void create_a_page_without_a_context_url_data_for_process_scope() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContract(), FormScope.PROCESS); assertThat(page.getVariables()).doesNotContain(entry("context", anURLVariable().value("/bonita/API/bpm/userTask/{{taskId}}/context").build())); }
@Test public void create_a_page_without_an_id_expression_data_for_process() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContract(), FormScope.PROCESS); assertThat(page.getVariables()).doesNotContain(entry("taskId", aUrlParameterVariable().value("id").build())); }
@Test public void create_a_page_without_output_data_for_overview_scope() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContract().build(), FormScope.OVERVIEW); assertThat(page.getVariables()).isEmpty(); }
@Test public void create_a_page_with_a_submit_button_sending_contract() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithMultipleInput(), FormScope.TASK); Component submitButon = (Component) getTaskFormContainerContent(page).getRows().get(3).get(0); assertThat(submitButon.getId()).isEqualTo("pbButton"); assertThat(submitButon.getPropertyValues()).contains( entry(ParameterConstants.DATA_TO_SEND_PARAMETER, anExpressionPropertyValue("formOutput")), entry(ParameterConstants.ACTION_PARAMETER, aConstantPropertyValue(ButtonAction.SUBMIT_TASK.getValue())), entry(ParameterConstants.TARGET_URL_ON_SUCCESS_PARAMETER, aInterpolationPropertyValue("/bonita"))); }
@Test public void create_a_page_and_fetch_associated_task() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContract(), FormScope.TASK); assertThat(page.getVariables()).contains(entry("task", anURLVariable().value("../API/bpm/userTask/{{taskId}}").build())); }
@Test public void create_a_page_display_task_name() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); TitleWidget title = new TitleWidget(); title.setLevel("Level 1"); title.setText("{{ task.displayName }}"); title.setAlignment(Alignment.CENTER); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContract(), FormScope.TASK); assertThat(grabTaskInformation(page).getRows().get(0).get(0).getPropertyValues().containsKey("class")).isFalse(); assertThat(grabTaskInformation(page).getRows().get(0).get(0)).isEqualToIgnoringGivenFields(title.toComponent(new DimensionFactory()), "reference"); }
@Test public void create_a_page_display_task_description() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); TextWidget description = new TextWidget(); description.setText("{{ task.displayDescription }}"); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContract(), FormScope.TASK); assertThat(grabTaskInformation(page).getRows().get(1).get(0)).isEqualToIgnoringGivenFields(description.toComponent(new DimensionFactory()), "reference"); }
@Test public void should_create_an_empty_container_when_contract_is_empty_and_scope_is_overview() throws Exception { Contract anEmptyContract = aContract().build(); Page page = makeContractToPageMapper().createFormPage("myPage", anEmptyContract, FormScope.OVERVIEW); Container container = (Container) page.getRows().get(0).get(0); assertThat(container.getRows().get(0)).isEqualTo(new ArrayList<>()); }
@Test public void should_create_a_page_with_a_business_data_when_contract_contains_data_reference_on_a_task() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContractWithDataRef(EditMode.EDIT), FormScope.TASK); assertThat(page.getVariables()).contains(entry("employee",anURLVariable().value("../{{context.employee_ref.link}}").build())); assertThat(page.getVariables()).contains(entry("employee_addresses",anURLVariable().value("{{employee|lazyRef:'addresses'}}").build())); assertThat(page.getVariables()).contains(entry("employee_manager",anURLVariable().value("{{employee|lazyRef:'manager'}}").build())); assertThat(page.getVariables()).contains(entry("employee_manager_addresses",anURLVariable().value("{{employee_manager|lazyRef:'addresses'}}").build())); assertThat(page.getVariables()).doesNotContain(entry("employee_addresses_country",anURLVariable().value("{{employee_addresses|lazyRef:'country'}}").build())); }
@Test public void should_create_a_page_with_a_query_varaible_when_contract_contains_data_reference_with_aggregation() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aContractWithDataRefAndAggregation(EditMode.EDIT), FormScope.TASK); assertThat(page.getVariables()).contains(entry("employee_query",anURLVariable().value("../API/bdm/businessData/org.test.Employee?q=find&p=0&c=99").build())); }
@Test public void should_create_a_page_without_formInput_when_contract_contains__only_data_reference_on_a_task() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContractWithDataRef(EditMode.EDIT), FormScope.TASK); assertThat(page.getVariables().keySet()).doesNotContain("formInput"); }
@Test public void should_create_a_Text_widget_for_submit_error() throws Exception { ContractToPageMapper contractToPageMapper = makeContractToPageMapper(); Page page = contractToPageMapper.createFormPage("myPage", aSimpleContractWithDataRef(EditMode.EDIT), FormScope.TASK); assertThat(page.getVariables().keySet()).contains("submit_errors_list"); FormContainer formContainer = (FormContainer) page.getRows().get(1).get(0); Component submitButton = (Component) formContainer.getContainer().getRows().get(2).get(0); assertThat(submitButton.getId()).isEqualTo("pbButton"); PropertyValue dataFromErrorProperty = submitButton.getPropertyValues().get("dataFromError"); assertThat(dataFromErrorProperty).isNotNull(); assertThat(dataFromErrorProperty.getValue()).isEqualTo("formOutput._submitError"); Component errorText = (Component) formContainer.getContainer().getRows().get(3).get(0); assertThat(errorText.getId()).isEqualTo("pbText"); PropertyValue hiddenProperty = errorText.getPropertyValues().get("hidden"); assertThat(hiddenProperty).isNotNull(); assertThat(hiddenProperty.getValue()).isEqualTo("!formOutput._submitError.message"); }