1 22 package org.jboss.test.jaxr.scout.query.infomodel; 23 24 import org.jboss.test.jaxr.scout.JaxrBaseTestCase; 25 import org.jboss.test.jaxr.scout.util.ScoutUtil; 26 27 import javax.xml.registry.BulkResponse ; 28 import javax.xml.registry.BusinessLifeCycleManager ; 29 import javax.xml.registry.BusinessQueryManager ; 30 import javax.xml.registry.Connection ; 31 import javax.xml.registry.JAXRException ; 32 import javax.xml.registry.LifeCycleManager ; 33 import javax.xml.registry.RegistryService ; 34 import javax.xml.registry.infomodel.Association ; 35 import javax.xml.registry.infomodel.Concept ; 36 import javax.xml.registry.infomodel.Key ; 37 import javax.xml.registry.infomodel.Organization ; 38 import java.util.ArrayList ; 39 import java.util.Collection ; 40 import java.util.Iterator ; 41 42 47 public class JaxrFindAssociationsTestCase extends JaxrBaseTestCase 48 { 49 public void testFindAssociations() throws JAXRException 50 { 51 52 String orgSource = "Source Organization"; 53 String type = "Implements"; 54 55 Key savekey = null; 56 Key assockey = null; 57 58 BusinessQueryManager bqm2 = null; 59 BusinessLifeCycleManager blm2 = null; 60 Collection associationKeys = null; 61 Collection sourceKeys = null; 62 Collection targetKeys = null; 63 String targetId = null; 64 String sourceId = null; 65 String orgTarget = "Target Organization"; 66 67 try 68 { 69 login(); 70 getJAXREssentials(); 71 Connection con2 = loginSecondUser(); 73 RegistryService rs2 = con2.getRegistryService(); 74 blm2 = rs2.getBusinessLifeCycleManager(); 75 bqm2 = rs2.getBusinessQueryManager(); 76 77 Organization source = blm.createOrganization(blm.createInternationalString(orgSource)); 78 Organization target = blm2.createOrganization(blm.createInternationalString(orgTarget)); 79 80 Collection orgs = new ArrayList (); 82 orgs.add(source); 83 br = blm.saveOrganizations(orgs); 84 if (br.getExceptions() != null) 85 { 86 fail(" Source:Save Orgs failed"); 87 } 88 89 sourceKeys = br.getCollection(); 90 Iterator iter = sourceKeys.iterator(); 91 while (iter.hasNext()) 92 { 93 savekey = (Key )iter.next(); 94 } 95 sourceId = savekey.getId(); 96 String objectType = LifeCycleManager.ORGANIZATION; 97 Organization pubSource = (Organization )bqm.getRegistryObject(sourceId, objectType); 98 assertNotNull(pubSource.getName().getValue()); 99 100 orgs.clear(); 102 orgs.add(target); 103 br = blm2.saveOrganizations(orgs); 104 if (br.getExceptions() != null) 105 { 106 fail(" Target:Save Orgs failed"); 107 } 108 targetKeys = br.getCollection(); 109 iter = targetKeys.iterator(); 110 while (iter.hasNext()) 111 { 112 savekey = (Key )iter.next(); 113 } 114 targetId = savekey.getId(); 115 Organization pubTarget = (Organization )bqm2.getRegistryObject(targetId, objectType); 116 117 Concept associationType = getAssociationConcept(type); 118 if (associationType == null) 119 fail(" getAssociationConcept returned null associationType"); 120 121 Association a = blm.createAssociation(pubTarget, associationType); 122 a.setSourceObject(pubSource); 123 124 blm.confirmAssociation(a); blm2.confirmAssociation(a); 127 Collection associations = new ArrayList (); 129 associations.add(a); 130 br = blm2.saveAssociations(associations, false); 132 133 if (br.getExceptions() != null) 134 { 135 fail("Error:Save Associations failed \n"); 136 } 137 BulkResponse targetAssoc = bqm.findCallerAssociations(null, 138 new Boolean (true), 139 new Boolean (true), 140 null); 141 142 if (targetAssoc.getExceptions() == null) 143 { 144 Collection targetCol = targetAssoc.getCollection(); 145 if (targetCol.size() > 0) 146 { 147 iter = targetCol.iterator(); 148 while (iter.hasNext()) 149 { 150 Association a1 = (Association )iter.next(); 151 Organization o = (Organization )a1.getSourceObject(); 152 o = (Organization )a1.getTargetObject(); 153 Concept atype = a1.getAssociationType(); 154 assertNotNull("Concept Type stored in Association", atype); 155 } 156 } 157 } 158 159 160 br = null; 161 Collection associationTypes = new ArrayList (); 162 associationTypes.add(type); 163 br = bqm.findAssociations(null, sourceId, targetId, null); 164 if (br.getExceptions() != null) 165 { 166 fail("Error: findAssociations failed "); 167 } 168 associations = null; 169 associations = br.getCollection(); 170 if (associations.size() > 0) 171 { 172 iter = associations.iterator(); 173 while (iter.hasNext()) 174 { 175 Association a1 = (Association )iter.next(); 176 assockey = a1.getKey(); 177 ScoutUtil.validateAssociation(a1,orgSource); 178 } 179 } 180 } 181 catch (Exception e) 182 { 183 e.printStackTrace(); 184 fail(" Test failed "); 185 } 186 finally 187 { 188 try 190 { 191 if (assockey != null) 192 { 193 associationKeys = new ArrayList (); 194 associationKeys.add(assockey); 195 blm.deleteAssociations(associationKeys); 196 } 197 blm2.deleteOrganizations(targetKeys); 198 blm.deleteOrganizations(sourceKeys); 199 } 200 catch (JAXRException ex) 201 { 202 ex.printStackTrace(); 203 fail("Error: Cleanup failed"); 204 } 205 } 206 207 } 209 210 } 211 | Popular Tags |