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.Description; 21 import org.apache.juddi.datatype.Email; 22 import org.apache.juddi.datatype.Phone; 23 import org.apache.juddi.datatype.RegistryObject; 24 import org.apache.juddi.datatype.business.Contact; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 31 public class ContactHandlerTests extends HandlerTestCase 32 { 33 private static final String TEST_ID = "juddi.handler.Contact.test"; 34 private ContactHandler handler = null; 35 36 public ContactHandlerTests(String arg0) 37 { 38 super(arg0); 39 } 40 41 public static void main(String [] args) 42 { 43 junit.textui.TestRunner.run(ContactHandlerTests.class); 44 } 45 46 public void setUp() 47 { 48 HandlerMaker maker = HandlerMaker.getInstance(); 49 handler = (ContactHandler)maker.lookup(ContactHandler.TAG_NAME); 50 } 51 52 private RegistryObject getRegistryObject() 53 { 54 55 56 Address address = new Address(); 57 address.setUseType("myAddressUseType"); 58 address.setSortCode("sortThis"); 59 address.setTModelKey(null); 60 address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr")); 61 address.addAddressLine(new AddressLine("AddressLine2")); 62 63 Contact object = new Contact(); 64 object.setUseType("myAddressUseType"); 65 object.setPersonNameValue("Person Whatever"); 66 object.addDescription(new Description("Description1")); 67 object.addDescription(new Description("Description2","es")); 68 object.addEmail(new Email("person@whatever.com")); 69 object.addPhone(new Phone("(123)456-7890")); 70 object.addAddress(address); 71 72 return object; 73 74 } 75 76 private Element getMarshalledElement(RegistryObject regObject) 77 { 78 Element parent = XMLUtils.newRootElement(); 79 Element child = null; 80 81 if(regObject == null) 82 regObject = this.getRegistryObject(); 83 84 handler.marshal(regObject,parent); 85 child = (Element )parent.getFirstChild(); 86 parent.removeChild(child); 87 88 return child; 89 } 90 91 public void testMarshal() 92 { 93 Element child = getMarshalledElement(null); 94 95 String marshalledString = this.getXMLString(child); 96 97 assertNotNull("Marshalled Contact ", marshalledString); 98 99 } 100 101 public void testUnMarshal() 102 { 103 104 Element child = getMarshalledElement(null); 105 RegistryObject regObject = handler.unmarshal(child); 106 107 assertNotNull("UnMarshalled Contact ", regObject); 108 109 } 110 111 public void testMarshUnMarshal() 112 { 113 Element child = getMarshalledElement(null); 114 115 String marshalledString = this.getXMLString(child); 116 117 assertNotNull("Marshalled Contact ", marshalledString); 118 119 RegistryObject regObject = handler.unmarshal(child); 120 121 child = getMarshalledElement(regObject); 122 123 String unMarshalledString = this.getXMLString(child); 124 125 assertNotNull("Unmarshalled Contact ", unMarshalledString); 126 127 boolean equals = marshalledString.equals(unMarshalledString); 128 129 assertEquals("Expected result: ", marshalledString, unMarshalledString ); 130 } 131 132 } 133 | Popular Tags |