ContractInputToWidgetMapper { public Element toDocument(LeafContractInput contractInput) { return contractInput.isMultiple() ? toMultipleDocument(contractInput) : toSingleDocument(contractInput); } @Inject  ContractInputToWidgetMapper(DimensionFactory dimensionFactory, JacksonObjectMapper objectMapperWrapper); Element toElement(ContractInput contractInput, List<List<Element>> rows); Element toDocument(LeafContractInput contractInput); Container toContainer(NodeContractInput nodeContractInput, List<List<Element>> rows); Component createSubmitButton(ButtonAction actionType); Component createSubmitErrorAlert(); boolean canCreateComponent(ContractInput contractInput); Component createRemoveButton(); Component createAddButton(ContractInput contractInput);  }
@Test public void should_create_single_document_to_edit() { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); LeafContractInput fileContractInput = ContractInputBuilder.aFileContractInput("aDocument.txt"); ContractInputDataHandler dataHandler = new ContractInputDataHandler(fileContractInput); assertThat(dataHandler.isDocumentEdition()).isFalse(); fileContractInput.setDataReference(new DataReference("myDoc", File.class.getName())); fileContractInput.setMode(EditMode.EDIT); assertThat(dataHandler.isDocumentEdition()).isTrue(); Container container = (Container) contractInputToWidgetMapper.toDocument(fileContractInput); Component titleComponent = (Component) container.getRows().get(0).get(0); assertThat(titleComponent.getId()).isEqualTo("pbTitle"); PropertyValue textProperty = titleComponent.getPropertyValues().get("text"); assertThat(textProperty.getValue()).isEqualTo("My Doc"); Component fileViewerComponent = (Component) container.getRows().get(1).get(0); assertThat(fileViewerComponent.getId()).isEqualTo("pbFileViewer"); PropertyValue documentProperty = fileViewerComponent.getPropertyValues().get("document"); assertThat(documentProperty.getValue()).isEqualTo("context.myDoc_ref"); Component fileUploadComponent = (Component) container.getRows().get(2).get(0); assertThat(fileUploadComponent.getId()).isEqualTo("pbUpload"); PropertyValue labelHiddenProperty = fileUploadComponent.getPropertyValues().get("labelHidden"); assertThat(labelHiddenProperty.getValue()).isEqualTo(Boolean.TRUE); PropertyValue valueProperty = fileUploadComponent.getPropertyValues().get("value"); assertThat(valueProperty.getValue()).isEqualTo("context.myDoc_ref.newValue"); }
@Test public void should_create_multiple_document_to_edit_container() { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); LeafContractInput fileContractInput = ContractInputBuilder.aFileContractInput("aDocument.txt"); fileContractInput.setMultiple(true); fileContractInput.setMode(EditMode.EDIT); ContractInputDataHandler dataHandler = new ContractInputDataHandler(fileContractInput); fileContractInput.setDataReference(new DataReference("myDoc", File.class.getName())); assertThat(dataHandler.isDocumentEdition()).isTrue(); Element element = contractInputToWidgetMapper.toDocument(fileContractInput); assertThat(element).isInstanceOf(Container.class); Container container = (Container) element; assertThat(container.getRows()).hasSize(2); assertThat(container.isRepeated()).isFalse(); Component title = (Component) container.getRows().get(0).get(0); assertThat(title.getId()).isEqualTo("pbTitle"); Container multipleContainer = (Container) container.getRows().get(1).get(0); Map<String, PropertyValue> propertyValues = multipleContainer.getPropertyValues(); PropertyValue repeatedCollectionProperty = propertyValues.get("repeatedCollection"); assertThat(repeatedCollectionProperty.getValue()).isEqualTo("context.myDoc_ref"); Component fileViewerComponent = (Component) multipleContainer.getRows().get(0).get(0); assertThat(fileViewerComponent.getId()).isEqualTo("pbFileViewer"); PropertyValue documentProperty = fileViewerComponent.getPropertyValues().get("document"); assertThat(documentProperty.getValue()).isEqualTo("$item"); Component fileUploadComponent = (Component) multipleContainer.getRows().get(1).get(0); assertThat(fileUploadComponent.getId()).isEqualTo("pbUpload"); PropertyValue labelHiddenProperty = fileUploadComponent.getPropertyValues().get("labelHidden"); assertThat(labelHiddenProperty.getValue()).isEqualTo(Boolean.TRUE); PropertyValue valueProperty = fileUploadComponent.getPropertyValues().get("value"); assertThat(valueProperty.getValue()).isEqualTo("$item.newValue"); }