ContractToContainerMapper { public Container create(Contract contract) { Container container = new Container(); contract.accept(new ContractInputVisitorImpl(container, contractToWidgetMapper)); return container; } @Inject  ContractToContainerMapper(ContractInputToWidgetMapper contractToWidgetMapper); Container create(Contract contract);  }
@Test public void should_set_value_relative_to_business_data_in_edit_mode() throws Exception { ContractToContainerMapper contractToContainerMapper = makeContractToContainerMapper(); Container container = contractToContainerMapper.create(aSimpleContractWithDataRef(EditMode.EDIT)); Container formContainer = (Container) container.getRows().get(1).get(0); List<Element> firstRow = formContainer.getRows().get(0); Component firstNameInput = (Component) firstRow.get(0); PropertyValue pValue = firstNameInput.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("employee.firstName"); List<Element> fourthRow = formContainer.getRows().get(4); Container managerContainer = (Container) fourthRow.get(0); Element managerfirstName = managerContainer.getRows().get(0).get(0); pValue = managerfirstName.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("employee_manager.firstName"); List<Element> sixthRow = formContainer.getRows().get(6); Container addressContainer = (Container) sixthRow.get(0); PropertyValue repeatedCollection = addressContainer.getPropertyValues().get("repeatedCollection"); assertThat(repeatedCollection.getType()).isEqualTo("variable"); assertThat(repeatedCollection.getValue()).isEqualTo("employee_addresses"); Component streetInput = (Component) addressContainer.getRows().get(0).get(0); pValue = streetInput.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("$item.street"); }
@Test public void should_set_value_relative_to_formInput_in_create_mode() throws Exception { ContractToContainerMapper contractToContainerMapper = makeContractToContainerMapper(); Container container = contractToContainerMapper.create(aSimpleContractWithDataRef(EditMode.CREATE)); Container formContainer = (Container) container.getRows().get(1).get(0); List<Element> firstRow = formContainer.getRows().get(0); Component firstNameInput = (Component) firstRow.get(0); PropertyValue pValue = firstNameInput.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("formInput.employeeInput.firstName"); List<Element> fourthRow = formContainer.getRows().get(4); Container managerContainer = (Container) fourthRow.get(0); Element managerfirstName = managerContainer.getRows().get(0).get(0); pValue = managerfirstName.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("formInput.employeeInput.manager.firstName"); List<Element> sixthRow = formContainer.getRows().get(6); Container addressContainer = (Container) sixthRow.get(0); PropertyValue repeatedCollection = addressContainer.getPropertyValues().get("repeatedCollection"); assertThat(repeatedCollection.getType()).isEqualTo("variable"); assertThat(repeatedCollection.getValue()).isEqualTo("formInput.employeeInput.addresses"); Component streetInput = (Component) addressContainer.getRows().get(0).get(0); pValue = streetInput.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("$item.street"); }
@Test public void should_create_a_Select_widget_for_aggregated_dataRef() throws Exception { ContractToContainerMapper contractToContainerMapper = makeContractToContainerMapper(); Container container = contractToContainerMapper.create(aContractWithDataRefAndAggregation(EditMode.EDIT)); Container formContainer = (Container) container.getRows().get(1).get(0); List<Element> fourthRow = formContainer.getRows().get(3); Component managerSelect = (Component) fourthRow.get(0); assertThat(managerSelect.getId()).isEqualTo("pbSelect"); PropertyValue pValue = managerSelect.getPropertyValues().get("availableValues"); assertThat(pValue.getType()).isEqualTo("expression"); assertThat(pValue.getValue()).isEqualTo("employee_query"); pValue = managerSelect.getPropertyValues().get("value"); assertThat(pValue.getType()).isEqualTo("variable"); assertThat(pValue.getValue()).isEqualTo("employee.manager"); }