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