1 17 package org.apache.servicemix.components.mps; 18 19 import java.io.StringReader ; 20 21 import javax.jbi.JBIException; 22 import javax.jbi.messaging.NormalizedMessage; 23 import javax.xml.parsers.DocumentBuilder ; 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.transform.dom.DOMSource ; 26 27 import junit.framework.TestCase; 28 29 import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl; 30 import org.w3c.dom.Document ; 31 import org.xml.sax.InputSource ; 32 33 38 public class PropertyValueTest extends TestCase { 39 40 private final static String TEST_STRING = "PROP_TEST_STRING"; 41 private final static String PROPNAME = "property1"; 42 47 private NormalizedMessage getTestMessage() { 48 NormalizedMessage message = new NormalizedMessageImpl(); 49 message.setProperty(PROPNAME,TEST_STRING); 50 String xml = "<this><is><some attr='1234'>xml123</some></is></this>"; 51 try { 52 DocumentBuilder db; 53 db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 54 Document dom = db.parse(new InputSource (new StringReader (xml))); 55 message.setContent(new DOMSource (dom)); 56 } catch (Exception e) { 57 fail(e.getLocalizedMessage()); 58 } 59 return message; 60 } 61 62 66 public void testStaticString() { 67 PropertyValue pv = new StaticStringPropertyValue("someValueX"); 68 try { 69 assertTrue(pv.getPropertyValue(getTestMessage()).equals("someValueX")); 70 } catch (JBIException e) { 71 fail(e.getLocalizedMessage()); 72 } 73 } 74 75 79 public void testExistingCopier() { 80 PropertyValue pv = new ExistingPropertyCopier(PROPNAME); 81 try { 82 assertTrue(pv.getPropertyValue(getTestMessage()).equals(TEST_STRING)); 83 } catch (JBIException e) { 84 fail(e.getLocalizedMessage()); 85 } 86 } 87 88 92 public void testXPathElementPropertyValue() { 93 PropertyValue pv = new XPathContentMessagePropertyValue("/this/is/some"); 94 try { 95 assertTrue(pv.getPropertyValue(getTestMessage()).equals("xml123")); 96 } catch (JBIException e) { 97 fail(e.getLocalizedMessage()); 98 } 99 } 100 101 105 public void testXPathAttrPropertyValue() { 106 PropertyValue pv = new XPathContentMessagePropertyValue("/this/is/some/@attr"); 107 try { 108 assertTrue(pv.getPropertyValue(getTestMessage()).equals("1234")); 109 } catch (JBIException e) { 110 fail(e.getLocalizedMessage()); 111 } 112 } 113 114 118 public void testXPathConcatPropertyValue() { 119 PropertyValue pv = new XPathContentMessagePropertyValue("concat('x','y')"); 120 try { 121 assertTrue(pv.getPropertyValue(getTestMessage()).equals("xy")); 122 } catch (JBIException e) { 123 fail(e.getLocalizedMessage()); 124 } 125 } 126 127 } 128 | Popular Tags |