1 22 package org.jboss.test.jaxr.scout.publish; 23 24 import org.jboss.test.jaxr.scout.JaxrBaseTestCase; 25 import org.jboss.test.jaxr.scout.util.ScoutUtil; 26 27 import javax.xml.registry.BusinessLifeCycleManager ; 28 import javax.xml.registry.BusinessQueryManager ; 29 import javax.xml.registry.Connection ; 30 import javax.xml.registry.JAXRException ; 31 import javax.xml.registry.LifeCycleManager ; 32 import javax.xml.registry.RegistryService ; 33 import javax.xml.registry.infomodel.Association ; 34 import javax.xml.registry.infomodel.Concept ; 35 import javax.xml.registry.infomodel.Key ; 36 import javax.xml.registry.infomodel.Organization ; 37 import java.util.ArrayList ; 38 import java.util.Collection ; 39 import java.util.Iterator ; 40 41 47 public class JaxrDeleteAssociationTestCase extends JaxrBaseTestCase 48 { 49 63 public void testDeleteAssociations() throws JAXRException 64 { 65 Key savekey = null; 66 Key assockey = null; 67 BusinessQueryManager bqm2 = null; 68 BusinessLifeCycleManager blm2 = null; 69 Collection sourceKeys = null; 70 Collection targetKeys = null; 71 72 73 try 74 { 75 login(); 76 getJAXREssentials(); 77 Connection con2 = loginSecondUser(); 79 RegistryService rs2 = con2.getRegistryService(); 80 blm2 = rs2.getBusinessLifeCycleManager(); 81 bqm2 = rs2.getBusinessQueryManager(); 82 String orgTarget = "Target Organization"; 83 String orgSource = "Source Organization"; 84 85 Organization target = blm2.createOrganization(blm.createInternationalString(orgTarget)); 86 Organization source = blm.createOrganization(blm.createInternationalString(orgSource)); 87 88 Collection orgs = new ArrayList (); 89 orgs.add(source); 90 br = blm.saveOrganizations(orgs); 91 if (br.getExceptions() != null) 92 { 93 fail(" Source::Save Organizations failed"); 94 } 95 sourceKeys = br.getCollection(); 96 Iterator iter = sourceKeys.iterator(); 97 while (iter.hasNext()) 98 { 99 savekey = (Key ) iter.next(); 100 } 101 String sourceid = savekey.getId(); 102 String objectType = LifeCycleManager.ORGANIZATION; 103 104 Organization pubSource = (Organization ) bqm.getRegistryObject(sourceid, objectType); 105 assertNotNull("Source Org", pubSource.getName().getValue()); 106 107 orgs.clear(); 108 orgs.add(target); 109 br = blm2.saveOrganizations(orgs); 110 if (br.getExceptions() != null) 111 { 112 fail("Target:: Save Organizations failed"); 113 } 114 targetKeys = br.getCollection(); 115 iter = targetKeys.iterator(); 116 while (iter.hasNext()) 117 { 118 savekey = (Key ) iter.next(); 119 } 120 String targetid = savekey.getId(); 121 Organization targetOrg = (Organization ) bqm2.getRegistryObject(targetid, objectType); 122 assertNotNull("Target Org", targetOrg.getName().getValue()); 123 124 Concept associationType = getAssociationConcept("Implements"); 125 assertNotNull("AssociationType", associationType); 126 127 Association a = blm.createAssociation(targetOrg, associationType); 128 a.setSourceObject(pubSource); 129 130 blm.confirmAssociation(a); 131 blm2.confirmAssociation(a); 132 133 Collection associations = new ArrayList (); 135 associations.add(a); 136 br = blm2.saveAssociations(associations, false); 137 138 if (br.getExceptions() != null) 139 { 140 fail("Second User :save Association failed"); 141 } 142 143 br = bqm.findCallerAssociations(null, 144 new Boolean (true), 145 new Boolean (true), 146 null); 147 148 if (br.getExceptions() == null) 149 { 150 Collection results = br.getCollection(); 151 if (results.size() > 0) 152 { 153 iter = results.iterator(); 154 while (iter.hasNext()) 155 { 156 Association a1 = (Association ) iter.next(); 157 assockey = a1.getKey(); 158 ScoutUtil.validateAssociation(a1, orgSource); 159 } 160 } 161 } 162 if (assockey != null) 163 { 164 Collection keys = new ArrayList (); 165 keys.add(assockey); 166 blm.deleteAssociations(keys); 167 br = bqm.findCallerAssociations(null, new Boolean (true), new Boolean (true), null); 168 if (br.getExceptions() == null) 169 { 170 Collection retAssocs = br.getCollection(); 171 if (retAssocs.size() == 0) 172 { 173 } else 175 fail("Associations should have been zero"); 176 } 177 } 178 179 } catch (Exception e) 180 { 181 e.printStackTrace(); 182 System.out.println("Caught unexpected exception: " + e.getMessage()); 183 fail(" failed "); 184 } finally 185 { 186 try 188 { 189 blm2.deleteOrganizations(targetKeys); 190 blm.deleteOrganizations(sourceKeys); 191 } catch (JAXRException je) 192 { 193 System.out.println("Error: Clean Up Failed"); 194 } 195 } 196 } 197 } 198 | Popular Tags |