BusinessDataToWidgetMapper { public List<Element> toElement(LeafContractInput contractInput) { return contractInput.isMultiple() ? toMultipleComponent(contractInput) : toSimpleComponent(contractInput); } BusinessDataToWidgetMapper(DimensionFactory dimensionFactory, BusinessObjectContainer businessObjectContainer); Container generateMasterDetailsPattern(NodeBusinessObjectInput nodeBusinessObjectInput, List<List<Element>> rows); List<Element> toElement(LeafContractInput contractInput);  }
@Test public void should_string_contract_input_create_an_input_widget_id() throws Exception { BusinessDataToWidgetMapper contractInputToWidgetMapper = makeBusinessDataToWidgetMapper(new BusinessObjectContainer()); List<Element> element = contractInputToWidgetMapper.toElement(aStringContractInput("firstName")); Component a = (Component) element.get(0); assertThat(a.getId()).isEqualTo("pbInput"); }
@Test public void should_configure_value_property_of_input_with_$item_when_generating_a_multiple_string_in_a_multiple_leaf_contract_input() { BusinessDataToWidgetMapper businessDataToWidgetMapper = makeBusinessDataToWidgetMapper(new BusinessObjectContainer()); ContractInput contractInput = aContractInput("names").mulitple().withType(String.class.getName()).build(); NodeBusinessObjectInput node = new NodeBusinessObjectInput("com.company.model.person", "person"); node.setMultiple(true); node.addInput(contractInput); List<Element> elements = businessDataToWidgetMapper.toElement((LeafContractInput) contractInput); Container container = (Container) elements.get(1); assertThat(container).isInstanceOf(Container.class); PropertyValue repeatedCollectionPropetyValue = container.getPropertyValues().get("repeatedCollection"); assertThat(repeatedCollectionPropetyValue.getType()).isEqualTo("variable"); assertThat(repeatedCollectionPropetyValue.getValue()).isEqualTo("person_selected.names"); Element input = container.getRows().get(0).get(0); PropertyValue inputPropertyValue = input.getPropertyValues().get("value"); assertThat(inputPropertyValue.getValue()).isEqualTo("$item"); }
@Test public void should_generated_repeatable_container_when_contract_input_is_multiple() { BusinessObjectContainer boc = new BusinessObjectContainer(); BusinessDataToWidgetMapper businessDataToWidgetMapper = makeBusinessDataToWidgetMapper(boc); NodeBusinessObjectInput node = new NodeBusinessObjectInput("com.invoice.model.customer", "customer"); node.setMultiple(true); node.addInput(aContractInput("labels").withType(String.class.getName()).mulitple().build()); LeafContractInput contractInput = (LeafContractInput) node.getInput().get(0); List<Element> elements = businessDataToWidgetMapper.toElement(contractInput); assertThat(elements.size()).isEqualTo(2); assertThat(((Component) elements.get(0)).getId()).isEqualTo("pbTitle"); Container multipleContainer = (Container) elements.get(1); assertThat(multipleContainer.getPropertyValues().get("repeatedCollection").getValue()).isEqualTo("customer_selected.labels"); }