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