1 22 package org.jboss.test.jaxr.scout.publish.infomodel; 23 24 import org.jboss.test.jaxr.scout.JaxrBaseTestCase; 25 26 import javax.xml.registry.BusinessLifeCycleManager ; 27 import javax.xml.registry.BusinessQueryManager ; 28 import javax.xml.registry.Connection ; 29 import javax.xml.registry.JAXRException ; 30 import javax.xml.registry.LifeCycleManager ; 31 import javax.xml.registry.RegistryService ; 32 import javax.xml.registry.infomodel.Association ; 33 import javax.xml.registry.infomodel.Concept ; 34 import javax.xml.registry.infomodel.Key ; 35 import javax.xml.registry.infomodel.Organization ; 36 import java.util.ArrayList ; 37 import java.util.Collection ; 38 import java.util.Iterator ; 39 40 46 public class JaxrConfimAssociationTestCase extends JaxrBaseTestCase 47 { 48 53 public void testConfirmAssociation() throws JAXRException 54 { 55 String orgTarget = "Target Organization"; 56 String orgSource = "Source Organization"; 57 String type = "Implements"; 58 Key savekey = null; 59 60 Collection associationKeys = null; 61 Collection sourceKeys = null; 62 Collection targetKeys = null; 63 String targetId = null; 64 String sourceId = null; 65 BusinessQueryManager bqm2 = null; 66 BusinessLifeCycleManager blm2 = null; 67 68 69 try 70 { 71 login(); 72 getJAXREssentials(); 73 74 Connection con2 = loginSecondUser(); 76 RegistryService rs2 = con2.getRegistryService(); 77 blm2 = rs2.getBusinessLifeCycleManager(); 78 bqm2 = rs2.getBusinessQueryManager(); 79 80 Organization target = blm2.createOrganization(blm.createInternationalString(orgTarget)); 81 Organization source = blm.createOrganization(blm.createInternationalString(orgSource)); 82 83 Collection orgs = new ArrayList (); 84 orgs.add(source); 85 br = blm.saveOrganizations(orgs); 86 if (br.getExceptions() != null) 87 { 88 fail(" Source:Save Orgs failed"); 89 } 90 91 sourceKeys = br.getCollection(); 92 Iterator iter = sourceKeys.iterator(); 93 while (iter.hasNext()) 94 { 95 savekey = (Key ) iter.next(); 96 } 97 sourceId = savekey.getId(); 98 99 String objectType = LifeCycleManager.ORGANIZATION; 100 Organization pubSource = (Organization ) bqm.getRegistryObject(sourceId, objectType); 101 assertNotNull("Source retrieved: ", pubSource.getName().getValue()); 102 103 orgs.clear(); 104 orgs.add(target); 105 br = blm2.saveOrganizations(orgs); 106 if (br.getExceptions() != null) 107 { 108 fail("Target:Save Orgs failed"); 109 } 110 targetKeys = br.getCollection(); 111 iter = targetKeys.iterator(); 112 while (iter.hasNext()) 113 { 114 savekey = (Key ) iter.next(); 115 } 116 targetId = savekey.getId(); 117 118 Organization pubTarget = (Organization ) bqm2.getRegistryObject(targetId, objectType); 119 assertNotNull("Target: ", pubTarget.getName().getValue()); 120 121 Concept associationType = getAssociationConcept(type); 122 if (associationType == null) 123 fail(" getAssociationConcept returned null"); 124 125 Association a = blm.createAssociation(pubTarget, associationType); 126 a.setSourceObject(pubSource); 127 128 blm2.confirmAssociation(a); 129 130 Collection associations = new ArrayList (); 131 associations.add(a); 132 br = blm2.saveAssociations(associations, false); 133 if (br.getExceptions() != null) 134 { 135 fail(" Save Association did not complete due to errors"); 136 } 137 138 associationKeys = br.getCollection(); 139 iter = associationKeys.iterator(); 140 141 Collection associationTypes = new ArrayList (); 142 associationTypes.add(associationType); 143 br = bqm.findCallerAssociations(null, 145 new Boolean (false), 146 new Boolean (true), associationTypes); 147 if (br.getExceptions() != null) 148 { 149 fail(" Find Caller Association failed"); 150 } 151 associations = br.getCollection(); 152 if (associations.size() == 0) 153 { 154 fail(" Retrieving Associations failed"); 155 } 156 iter = associations.iterator(); 157 while (iter.hasNext()) 158 { 159 a = (Association ) iter.next(); 160 } 161 162 assertNotNull("Association type:", a.getAssociationType().getValue()); 163 if (a.isConfirmed()) 164 { 165 fail("FAIL: isConfirmed returned true "); 166 } 167 if (a.isConfirmedBySourceOwner()) 168 { 169 fail("FAIL: isConfirmedBySourceOwner returned true "); 170 } 171 172 blm.confirmAssociation(a); 173 br = blm.saveAssociations(associations, false); 174 if (br.getExceptions() != null) 175 { 176 fail("Error: saveAssociations failed "); 177 } 178 179 180 br = bqm.findCallerAssociations(null, new Boolean (true), new Boolean (true), associationTypes); 181 182 if (br.getExceptions() != null) 183 { 184 fail("Error: findCallerAssociations failed "); 185 } 186 187 associations = br.getCollection(); 188 iter = associations.iterator(); 189 while (iter.hasNext()) 190 { 191 a = (Association ) iter.next(); 192 } 193 194 if (!(a.isConfirmed())) 195 { 196 fail("FAIL: isConfirmed incorrectly returned false "); 197 } 198 199 if (!(a.isConfirmedBySourceOwner())) 200 { 201 fail("FAIL: isConfirmedBySourceOwner incorrectly returned false "); 202 } 203 } catch (Exception e) 204 { 205 e.printStackTrace(); 206 fail("Caught unexpected exception: " + e.getMessage()); 207 } finally 208 { 209 try 211 { 212 blm2.deleteOrganizations(targetKeys); 213 blm.deleteOrganizations(sourceKeys); 214 } catch (JAXRException je) 215 { 216 fail("Error: not able to delete registry objects"); 217 } 218 } 219 } 220 221 } 222 | Popular Tags |