1 22 package org.jboss.test.jaxr.scout.publish; 23 24 import org.jboss.test.jaxr.scout.JaxrBaseTestCase; 25 26 import javax.xml.registry.BulkResponse ; 27 import javax.xml.registry.JAXRException ; 28 import javax.xml.registry.LifeCycleManager ; 29 import javax.xml.registry.infomodel.Concept ; 30 import javax.xml.registry.infomodel.Key ; 31 import javax.xml.registry.infomodel.Organization ; 32 import javax.xml.registry.infomodel.Service ; 33 import javax.xml.registry.infomodel.ServiceBinding ; 34 import javax.xml.registry.infomodel.SpecificationLink ; 35 import java.util.ArrayList ; 36 import java.util.Collection ; 37 import java.util.Iterator ; 38 39 40 46 public class JaxrSaveServiceBindingTestCase extends JaxrBaseTestCase 47 { 48 51 public void testSaveServiceBinding() throws JAXRException 52 { 53 String serviceName = "jbosstestService"; 54 String sbDescription = "jbosstest sb description"; 55 56 String conceptName = "jbosstest concept"; 57 Collection sbKeys = null; 58 Collection serviceKeys = null; 59 Collection orgKeys = null; 60 Collection conceptKeys = null; 61 Key conceptKey = null; 62 Key serviceKey = null; 63 Key orgKey = null; 64 65 String accessURI = "http://myhost/jaxrTest.jsp"; 66 login(); 67 68 69 try 70 { 71 getJAXREssentials(); 72 String orgname = "Jaxr Org"; 73 Organization org = blm.createOrganization(getIString(orgname)); 74 Collection orgs = new ArrayList (); 75 orgs.add(org); 76 BulkResponse br = blm.saveOrganizations(orgs); 77 if (br.getExceptions() != null) 78 { 79 fail("Save Organizations failed "); 80 } 81 orgKeys = br.getCollection(); 82 Iterator iter = orgKeys.iterator(); 83 while (iter.hasNext()) 84 { 85 orgKey = (Key ) iter.next(); 86 } 87 88 89 org = (Organization ) bqm.getRegistryObject(orgKey.getId(), LifeCycleManager.ORGANIZATION); 90 91 Service service = blm.createService(serviceName); 92 org.addService(service); 93 Collection services = new ArrayList (); 94 services.add(service); 95 br = blm.saveServices(services); 96 if (br.getExceptions() != null) 97 { 98 fail("Save Services failed "); 99 } 100 serviceKeys = br.getCollection(); 101 iter = serviceKeys.iterator(); 102 while (iter.hasNext()) 103 { 104 serviceKey = (Key ) iter.next(); 105 } 106 107 service = (Service ) bqm.getRegistryObject(serviceKey.getId(), LifeCycleManager.SERVICE); 108 109 Concept testConcept = (Concept ) blm.createObject(LifeCycleManager.CONCEPT); 111 testConcept.setName(blm.createInternationalString(conceptName)); 112 Collection concepts = new ArrayList (); 113 concepts.add(testConcept); 114 br = blm.saveConcepts(concepts); 115 if (br.getExceptions() != null) 116 { 117 fail("Save Concepts failed "); 118 } 119 conceptKeys = br.getCollection(); 120 iter = conceptKeys.iterator(); 121 while (iter.hasNext()) 122 { 123 conceptKey = (Key ) iter.next(); 124 } 125 126 testConcept = (Concept ) bqm.getRegistryObject(conceptKey.getId(), LifeCycleManager.CONCEPT); 127 SpecificationLink sl = blm.createSpecificationLink(); 128 sl.setSpecificationObject(testConcept); 129 ServiceBinding sb = blm.createServiceBinding(); 130 sb.setDescription(blm.createInternationalString(sbDescription)); 131 sb.setAccessURI(accessURI); 132 sb.addSpecificationLink(sl); 133 service.addServiceBinding(sb); 134 Collection sbs = new ArrayList (); 135 sbs.add(sb); 136 br = blm.saveServiceBindings(sbs); 137 if (br.getExceptions() != null) 138 { 139 fail("Save ServiceBindings failed "); 140 } 141 142 143 Collection specifications = new ArrayList (); 144 specifications.add(testConcept); 145 146 br = bqm.findServiceBindings(serviceKey, null, null, specifications); 147 sbs = br.getCollection(); 148 iter = sbs.iterator(); 149 while (iter.hasNext()) 150 { 151 sb = (ServiceBinding ) iter.next(); 152 Service storedService = sb.getService(); 153 if (!(storedService.getName().getValue().equals(serviceName))) 154 { 155 fail("Error: service name"); 156 } 157 Organization storedOrg = storedService.getProvidingOrganization(); 158 if (!(storedOrg.getName().getValue().equals(orgname))) 159 { 160 fail("Error: unexpected organization name \n"); 161 } 162 if (!(sb.getDescription().getValue().equals(sbDescription))) 163 { 164 fail("Error: servicebinding description"); 165 } 166 if (!(sb.getAccessURI().equals(accessURI))) 167 { 168 fail("Error: unexpected accessURI name"); 169 } 170 } 171 172 sbs = new ArrayList (); 174 sb.setAccessURI("http://newURI"); 175 sbs.add(sb); 176 br = blm.saveServiceBindings(sbs); 177 br = bqm.findServiceBindings(serviceKey, null, null, specifications); 178 sbs = br.getCollection(); 179 iter = sbs.iterator(); 180 while (iter.hasNext()) 181 { 182 sb = (ServiceBinding ) iter.next(); 183 Service storedService = sb.getService(); 184 if (!(storedService.getName().getValue().equals(serviceName))) 185 { 186 fail("Error: service name"); 187 } 188 Organization storedOrg = storedService.getProvidingOrganization(); 189 if (!(storedOrg.getName().getValue().equals(orgname))) 190 { 191 fail("Error: unexpected organization name \n"); 192 } 193 if (!(sb.getDescription().getValue().equals(sbDescription))) 194 { 195 fail("Error: servicebinding description"); 196 } 197 if (!(sb.getAccessURI().equals("http://newURI"))) 198 { 199 fail("Error: unexpected accessURI name"); 200 } 201 } 202 } catch (Exception e) 203 { 204 e.printStackTrace(); 205 fail("Test has failed due to an exception "); 206 } finally 207 { 208 try 209 { 210 if (conceptKeys != null) 211 { 212 blm.deleteConcepts(conceptKeys); 213 } 214 if (sbKeys != null) 215 { 216 blm.deleteServiceBindings(sbKeys); 217 } 218 if (serviceKeys != null) 219 { 220 blm.deleteServices(serviceKeys); 221 } 222 if (orgKeys != null) 223 { 224 blm.deleteOrganizations(orgKeys); 225 } 226 227 } catch (JAXRException je) 228 { 229 fail("Cleanup of JAXR objects failed"); 230 } 231 } 232 } } 234 | Popular Tags |