@Test public void testDisplayOutputsHiddenEmptyValues() { FormData configuration = new FormData(); configuration.setMode(DisplayMode.Edit); com.xpn.xwiki.api.Document doc = Mockito.mock(com.xpn.xwiki.api.Document.class); configuration.setDocument(doc); Mockito.when(doc.getObjects("PhenoTips.PhenotypeMetaClass")).thenReturn(new Vector<com.xpn.xwiki.api.Object>()); configuration.setPositiveFieldName("PhenoTips.PatientClass_0_phenotype"); Collection<Map<String, ?>> data = Collections.emptySet(); Vocabulary ontologyService = Mockito.mock(Vocabulary.class); Mockito.doReturn(new LinkedList<VocabularyTerm>()).when(ontologyService) .search(Matchers.anyMapOf(String.class, Object.class)); PropertyDisplayer displayer = new PropertyDisplayer(data, configuration, ontologyService); String output = displayer.display(); Assert.assertTrue(StringUtils.isNotBlank(output)); LSInput input = this.domls.createLSInput(); input.setStringData("<div>" + output + "</div>"); Document xmldoc = XMLUtils.parse(input); NodeList inputs = xmldoc.getElementsByTagName("input"); Assert.assertEquals(1, inputs.getLength()); Element positive = (Element) inputs.item(0); Assert.assertEquals("PhenoTips.PatientClass_0_phenotype", positive.getAttribute("name")); Assert.assertEquals("", positive.getAttribute("value")); Assert.assertEquals("hidden", positive.getAttribute("type")); configuration.setNegativeFieldName("PhenoTips.PatientClass_0_negative_phenotype"); displayer = new PropertyDisplayer(data, configuration, ontologyService); output = displayer.display(); Assert.assertTrue(StringUtils.isNotBlank(output)); input = this.domls.createLSInput(); input.setStringData("<div>" + output + "</div>"); xmldoc = XMLUtils.parse(input); inputs = xmldoc.getElementsByTagName("input"); Assert.assertEquals(2, inputs.getLength()); positive = (Element) inputs.item(0); Assert.assertEquals("PhenoTips.PatientClass_0_phenotype", positive.getAttribute("name")); Assert.assertEquals("", positive.getAttribute("value")); Assert.assertEquals("hidden", positive.getAttribute("type")); Element negative = (Element) inputs.item(1); Assert.assertEquals("PhenoTips.PatientClass_0_negative_phenotype", negative.getAttribute("name")); Assert.assertEquals("", negative.getAttribute("value")); Assert.assertEquals("hidden", negative.getAttribute("type")); configuration.setMode(DisplayMode.View); displayer = new PropertyDisplayer(data, configuration, ontologyService); output = displayer.display(); Assert.assertTrue(StringUtils.isBlank(output)); }
public String display() { StringBuilder str = new StringBuilder(128); for (FormSection section : this.sections) { str.append(section.display(this.data.getMode(), this.fieldNames)); } if (DisplayMode.Edit.equals(this.data.getMode())) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[0] + "\" value=\"\" />"); if (this.fieldNames[1] != null) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[1] + "\" value=\"\" />"); } } return str.toString(); }
PropertyDisplayer { public String display() { StringBuilder str = new StringBuilder(128); for (FormSection section : this.sections) { str.append(section.display(this.data.getMode(), this.fieldNames)); } if (DisplayMode.Edit.equals(this.data.getMode())) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[0] + "\" value=\"\" />"); if (this.fieldNames[1] != null) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[1] + "\" value=\"\" />"); } } return str.toString(); } }
PropertyDisplayer { public String display() { StringBuilder str = new StringBuilder(128); for (FormSection section : this.sections) { str.append(section.display(this.data.getMode(), this.fieldNames)); } if (DisplayMode.Edit.equals(this.data.getMode())) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[0] + "\" value=\"\" />"); if (this.fieldNames[1] != null) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[1] + "\" value=\"\" />"); } } return str.toString(); } PropertyDisplayer(Collection<Map<String, ?>> template, FormData data, Vocabulary ontologyService); }
PropertyDisplayer { public String display() { StringBuilder str = new StringBuilder(128); for (FormSection section : this.sections) { str.append(section.display(this.data.getMode(), this.fieldNames)); } if (DisplayMode.Edit.equals(this.data.getMode())) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[0] + "\" value=\"\" />"); if (this.fieldNames[1] != null) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[1] + "\" value=\"\" />"); } } return str.toString(); } PropertyDisplayer(Collection<Map<String, ?>> template, FormData data, Vocabulary ontologyService); String display(); }
PropertyDisplayer { public String display() { StringBuilder str = new StringBuilder(128); for (FormSection section : this.sections) { str.append(section.display(this.data.getMode(), this.fieldNames)); } if (DisplayMode.Edit.equals(this.data.getMode())) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[0] + "\" value=\"\" />"); if (this.fieldNames[1] != null) { str.append("<input type=\"hidden\" name=\"" + this.fieldNames[1] + "\" value=\"\" />"); } } return str.toString(); } PropertyDisplayer(Collection<Map<String, ?>> template, FormData data, Vocabulary ontologyService); String display(); static final String INDEXED_CATEGORY_KEY; }