SerializeInformationTransformer extends InformationTransformer { public String transform(Object information, java.util.Map<String, Object> headers, ActivityType activityType) { String ret=transformToString(information, false); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Transform headers? '"+getIncludeHeaders()); } if (getIncludeHeaders()) { if (headers == null) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Configuration indicates to include headers, but no headers supplied"); } } else if (activityType == null) { LOG.severe("Cannot include headers as no activity type supplied"); } else { java.util.Iterator<String> iter=headers.keySet().iterator(); while (iter.hasNext()) { String headerName=iter.next(); Object headerValue=headers.get(headerName); String transformed=transformToString(headerValue, true); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Transformed header='"+headerName+"' value='"+headerValue+"' into='"+transformed+"'"); } if (transformed != null) { String encoding="text"; if (headerValue instanceof org.w3c.dom.Node || headerValue instanceof DOMSource) { encoding = "dom"; } activityType.getProperties().put(headerName, transformed); activityType.getProperties().put(getHeaderFormatPropertyName(headerName), encoding); } } } } return (ret); }  void setIncludeHeaders(boolean b); boolean getIncludeHeaders(); String transform(Object information, java.util.Map<String, Object> headers, ActivityType activityType);  }
@Test public void testSerializeString() { SerializeInformationTransformer transformer=new SerializeInformationTransformer(); String info="Hello"; String result=transformer.transform(info); if (result == null) { fail("Result is null"); } if (!result.equals(info)) { fail("Result mismatch: "+info+" but got "+result); } }
@Test public void testSerializeDOM() { SerializeInformationTransformer transformer=new SerializeInformationTransformer(); String info="<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello/>"; org.w3c.dom.Document doc=null; try { javax.xml.parsers.DocumentBuilderFactory factory= javax.xml.parsers.DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder builder= factory.newDocumentBuilder(); java.io.InputStream is= new java.io.ByteArrayInputStream(info.getBytes()); doc = builder.parse(is); is.close(); } catch (Exception e) { fail("Failed to build dom: "+e); } String result=transformer.transform(doc.getDocumentElement()); if (result == null) { fail("Result is null"); } if (!result.equals(info)) { fail("Result mismatch: "+info+" but got "+result); } }
@Test public void testSerializeDOMSource() { SerializeInformationTransformer transformer=new SerializeInformationTransformer(); String info="<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello/>"; org.w3c.dom.Document doc=null; try { javax.xml.parsers.DocumentBuilderFactory factory= javax.xml.parsers.DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder builder= factory.newDocumentBuilder(); java.io.InputStream is= new java.io.ByteArrayInputStream(info.getBytes()); doc = builder.parse(is); is.close(); } catch (Exception e) { fail("Failed to build dom: "+e); } String result=transformer.transform(new DOMSource(doc.getDocumentElement())); if (result == null) { fail("Result is null"); } if (!result.equals(info)) { fail("Result mismatch: "+info+" but got "+result); } }
@Test public void testSerializeObject() { SerializeInformationTransformer transformer=new SerializeInformationTransformer(); TestObject tobj=new TestObject(); String info=null; try { info = ActivityUtil.objectToJSONString(tobj); } catch (Exception e) { fail("Failed to get json: "+e); } String result=transformer.transform(tobj); if (result == null) { fail("Result is null"); } if (!result.equals(info)) { fail("Result mismatch: "+info+" but got "+result); } }