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.CategoryBag; 21 import org.apache.juddi.datatype.Description; 22 import org.apache.juddi.datatype.DiscoveryURL; 23 import org.apache.juddi.datatype.DiscoveryURLs; 24 import org.apache.juddi.datatype.Email; 25 import org.apache.juddi.datatype.IdentifierBag; 26 import org.apache.juddi.datatype.KeyedReference; 27 import org.apache.juddi.datatype.Name; 28 import org.apache.juddi.datatype.OverviewDoc; 29 import org.apache.juddi.datatype.Phone; 30 import org.apache.juddi.datatype.RegistryObject; 31 import org.apache.juddi.datatype.binding.AccessPoint; 32 import org.apache.juddi.datatype.binding.BindingTemplate; 33 import org.apache.juddi.datatype.binding.BindingTemplates; 34 import org.apache.juddi.datatype.binding.HostingRedirector; 35 import org.apache.juddi.datatype.binding.InstanceDetails; 36 import org.apache.juddi.datatype.binding.TModelInstanceDetails; 37 import org.apache.juddi.datatype.binding.TModelInstanceInfo; 38 import org.apache.juddi.datatype.business.BusinessEntity; 39 import org.apache.juddi.datatype.business.Contact; 40 import org.apache.juddi.datatype.business.Contacts; 41 import org.apache.juddi.datatype.service.BusinessService; 42 import org.apache.juddi.datatype.service.BusinessServices; 43 import org.apache.juddi.util.xml.XMLUtils; 44 import org.w3c.dom.Element ; 45 46 49 public class BusinessEntityHandlerTests extends HandlerTestCase 50 { 51 private static final String TEST_ID = "juddi.handler.BusinessEntity.test"; 52 private BusinessEntityHandler handler = null; 53 54 public BusinessEntityHandlerTests(String arg0) 55 { 56 super(arg0); 57 } 58 59 public static void main(String [] args) 60 { 61 junit.textui.TestRunner.run(BusinessEntityHandlerTests.class); 62 } 63 64 public void setUp() 65 { 66 HandlerMaker maker = HandlerMaker.getInstance(); 67 handler = (BusinessEntityHandler)maker.lookup(BusinessEntityHandler.TAG_NAME); 68 } 69 70 private RegistryObject getRegistryObject() 71 { 72 73 OverviewDoc overDoc = new OverviewDoc(); 74 overDoc.setOverviewURL("http://www.juddi.org/service.html"); 75 overDoc.addDescription(new Description("over-doc Descr")); 76 overDoc.addDescription(new Description("over-doc Descr Two","en")); 77 78 InstanceDetails instDetails = new InstanceDetails(); 79 instDetails.addDescription(new Description("inst-det descr")); 80 instDetails.addDescription(new Description("inst-det descr in italy","it")); 81 instDetails.setInstanceParms("inst-det parameters"); 82 instDetails.setOverviewDoc(overDoc); 83 84 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 85 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 86 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 87 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 88 tModInstInfo.setInstanceDetails(instDetails); 89 90 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 91 tModInstDet.addTModelInstanceInfo(tModInstInfo); 92 93 BindingTemplate binding = new BindingTemplate(); 94 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 95 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 96 binding.addDescription(new Description("whatever")); 97 binding.addDescription(new Description("whatever too","fr")); 98 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 99 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.juddi.org/service.wsdl")); 100 binding.setTModelInstanceDetails(tModInstDet); 101 102 BindingTemplates bindings = new BindingTemplates(); 103 bindings.addBindingTemplate(binding); 104 105 CategoryBag catBag = new CategoryBag(); 106 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 107 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2")); 108 109 IdentifierBag idBag = new IdentifierBag(); 110 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue")); 111 idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2")); 112 113 DiscoveryURLs discURLs = new DiscoveryURLs(); 114 discURLs.addDiscoveryURL(new DiscoveryURL("http","http://www.juddi.org/service.wsdl")); 115 discURLs.addDiscoveryURL(new DiscoveryURL("https","https://www.juddi.org/service.wsdl")); 116 discURLs.addDiscoveryURL(new DiscoveryURL("smtp","servicemngr@juddi.org")); 117 118 Address address = new Address(); 119 address.setUseType("myAddressUseType"); 120 address.setSortCode("sortThis"); 121 address.setTModelKey(null); 122 address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr")); 123 address.addAddressLine(new AddressLine("AddressLine2")); 124 125 Contact contact = new Contact(); 126 contact.setUseType("myAddressUseType"); 127 contact.setPersonNameValue("Person Whatever"); 128 contact.addDescription(new Description("Description1")); 129 contact.addDescription(new Description("Description2","es")); 130 contact.addEmail(new Email("person@whatever.com")); 131 contact.addPhone(new Phone("(123)456-7890")); 132 contact.addAddress(address); 133 134 Contacts contacts = new Contacts(); 135 contacts.addContact(contact); 136 137 BusinessService service = new BusinessService(); 138 service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f"); 139 service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77"); 140 service.setBindingTemplates(bindings); 141 service.setCategoryBag(catBag); 142 service.addName(new Name("serviceNm")); 143 service.addName(new Name("serviceNm2","en")); 144 service.addDescription(new Description("service whatever")); 145 service.addDescription(new Description("service whatever too","it")); 146 147 BusinessServices services = new BusinessServices(); 148 services.addBusinessService(service); 149 services.addBusinessService(service); 150 151 BusinessEntity object = new BusinessEntity(); 152 object.setBusinessKey("6c0ac186-d36b-4b81-bd27-066a5fe0fc1f"); 153 object.setAuthorizedName("Guest"); 154 object.setOperator("jUDDI"); 155 object.addName(new Name("businessNm")); 156 object.addName(new Name("businessNm2","en")); 157 object.addDescription(new Description("business whatever")); 158 object.addDescription(new Description("business whatever too","fr")); 159 object.setDiscoveryURLs(discURLs); 160 object.setCategoryBag(catBag); 161 object.setIdentifierBag(idBag); 162 object.setContacts(contacts); 163 object.setBusinessServices(services); 164 165 return object; 166 167 } 168 169 private Element getMarshalledElement(RegistryObject regObject) 170 { 171 Element parent = XMLUtils.newRootElement(); 172 Element child = null; 173 174 if(regObject == null) 175 regObject = this.getRegistryObject(); 176 177 handler.marshal(regObject,parent); 178 child = (Element )parent.getFirstChild(); 179 parent.removeChild(child); 180 181 return child; 182 } 183 184 public void testMarshal() 185 { 186 Element child = getMarshalledElement(null); 187 188 String marshalledString = this.getXMLString(child); 189 190 assertNotNull("Marshalled BusinessEntity ", marshalledString); 191 192 } 193 194 public void testUnMarshal() 195 { 196 197 Element child = getMarshalledElement(null); 198 RegistryObject regObject = handler.unmarshal(child); 199 200 assertNotNull("UnMarshalled BusinessEntity ", regObject); 201 202 } 203 204 public void testMarshUnMarshal() 205 { 206 Element child = getMarshalledElement(null); 207 208 String marshalledString = this.getXMLString(child); 209 210 assertNotNull("Marshalled BusinessEntity ", marshalledString); 211 212 RegistryObject regObject = handler.unmarshal(child); 213 214 child = getMarshalledElement(regObject); 215 216 String unMarshalledString = this.getXMLString(child); 217 218 assertNotNull("Unmarshalled BusinessEntity ", unMarshalledString); 219 220 boolean equals = marshalledString.equals(unMarshalledString); 221 222 assertEquals("Expected result: ", marshalledString, unMarshalledString ); 223 } 224 225 } 226 | Popular Tags |