PartInfoElement { public static OMElement createElement(final OMElement plElement, final IPayload data) { final OMFactory f = plElement.getOMFactory(); final OMElement piElement = f.createOMElement(Q_ELEMENT_NAME, plElement); String href = data.getPayloadURI(); if (href != null && !href.isEmpty()) { if (IPayload.Containment.ATTACHMENT == data.getContainment()) href = "cid:" + href; else if (IPayload.Containment.EXTERNAL != data.getContainment()) href = "#" + href; piElement.addAttribute(HREF_ATTR, href, null); } final ISchemaReference schemaRef = data.getSchemaReference(); if (schemaRef != null) SchemaElement.createElement(piElement, schemaRef); final IDescription descr = data.getDescription(); if (descr != null && !Utils.isNullOrEmpty(descr.getText())) DescriptionElement.createElement(piElement, descr); final Collection<IProperty> partProps = data.getProperties(); if (!Utils.isNullOrEmpty(partProps)) PartPropertiesElement.createElement(piElement, partProps); return piElement; }  static OMElement createElement(final OMElement plElement, final IPayload data); static Iterator<OMElement> getElements(final OMElement plElement); static org.holodeckb2b.common.messagemodel.Payload readElement(final OMElement piElement); static final QName Q_ELEMENT_NAME; }
@Test public void testCreateEmptyElement() throws Exception { OMElement piElement = PartInfoElement.createElement(plElement, new Payload()); System.out.println("piElement: " + piElement); assertNotNull(piElement); }
@Test public void testCreateElementForAttachmentContainmentType() throws Exception { Payload partInfo = new Payload(); partInfo.setContainment(IPayload.Containment.ATTACHMENT); String payloadURI = "path_to_file"; partInfo.setPayloadURI(payloadURI); OMElement piElement = PartInfoElement.createElement(plElement, partInfo); assertNotNull(piElement); assertEquals("cid:" + payloadURI, piElement.getAttribute(new QName("href")).getAttributeValue()); }
@Test public void testCreateElementForExternalContainmentType() throws Exception { Payload partInfo = new Payload(); addOptionalAttributesToPartInfo(partInfo); partInfo.setContainment(IPayload.Containment.EXTERNAL); String payloadURI = "path_to_file"; partInfo.setPayloadURI(payloadURI); OMElement piElement = PartInfoElement.createElement(plElement, partInfo); assertNotNull(piElement); assertEquals(payloadURI, piElement.getAttribute(new QName("href")).getAttributeValue()); checkPresenceOfOptionalOMElements(piElement); }
@Test public void testCreateElementForBodyContainmentType() throws Exception { Payload partInfo = new Payload(); addOptionalAttributesToPartInfo(partInfo); partInfo.setContainment(IPayload.Containment.BODY); String payloadURI = "path_to_file"; partInfo.setPayloadURI(payloadURI); OMElement piElement = PartInfoElement.createElement(plElement, partInfo); assertNotNull(piElement); assertEquals("#" + payloadURI, piElement.getAttribute(new QName("href")).getAttributeValue()); checkPresenceOfOptionalOMElements(piElement); }