1 16 package org.apache.juddi.handler; 17 18 import org.apache.juddi.datatype.Address; 19 import org.apache.juddi.datatype.AddressLine; 20 import org.apache.juddi.datatype.RegistryObject; 21 import org.apache.juddi.util.xml.XMLUtils; 22 import org.w3c.dom.Element ; 23 24 27 public class AddressHandlerTests extends HandlerTestCase 28 { 29 private static final String TEST_ID = "juddi.handler.address.test"; 30 private AddressHandler handler = null; 31 32 public AddressHandlerTests(String arg0) 33 { 34 super(arg0); 35 } 36 37 public static void main(String [] args) 38 { 39 junit.textui.TestRunner.run(AddressHandlerTests.class); 40 } 41 42 public void setUp() 43 { 44 HandlerMaker maker = HandlerMaker.getInstance(); 45 handler = (AddressHandler)maker.lookup(AddressHandler.TAG_NAME); 46 } 47 48 private RegistryObject getRegistryObject() 49 { 50 51 Address object = new Address(); 52 object.setUseType("myAddressUseType"); 53 object.setSortCode("sortThis"); 54 object.setTModelKey(null); 55 object.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr")); 56 object.addAddressLine(new AddressLine("AddressLine2")); 57 58 return object; 59 60 } 61 62 private Element getMarshalledElement(RegistryObject regObject) 63 { 64 Element parent = XMLUtils.newRootElement(); 65 Element child = null; 66 67 if(regObject == null) 68 regObject = this.getRegistryObject(); 69 70 handler.marshal(regObject,parent); 71 child = (Element )parent.getFirstChild(); 72 parent.removeChild(child); 73 74 return child; 75 } 76 77 public void testMarshal() 78 { 79 Element child = getMarshalledElement(null); 80 81 String marshalledString = this.getXMLString(child); 82 83 assertNotNull("Marshalled Address ", marshalledString); 84 85 } 86 87 public void testUnMarshal() 88 { 89 90 Element child = getMarshalledElement(null); 91 RegistryObject regObject = handler.unmarshal(child); 92 93 assertNotNull("UnMarshalled Address ", regObject); 94 95 } 96 97 public void testMarshUnMarshal() 98 { 99 Element child = getMarshalledElement(null); 100 101 String marshalledString = this.getXMLString(child); 102 103 assertNotNull("Marshalled Address ", marshalledString); 104 105 RegistryObject regObject = handler.unmarshal(child); 106 107 child = getMarshalledElement(regObject); 108 109 String unMarshalledString = this.getXMLString(child); 110 111 assertNotNull("Unmarshalled Address ", unMarshalledString); 112 113 boolean equals = marshalledString.equals(unMarshalledString); 114 115 assertEquals("Expected result: ", marshalledString, unMarshalledString ); 116 } 117 118 } 119 | Popular Tags |