Collection targetKeys = null;
String targetId = null;
String sourceId = null;
BusinessQueryManager bqm2 = null;
BusinessLifeCycleManager blm2 = null;
Association association = null;
try
{
login();
getJAXREssentials();
// second user.
Connection con2 = loginSecondUser();
RegistryService rs2 = con2.getRegistryService();
blm2 = rs2.getBusinessLifeCycleManager();
bqm2 = rs2.getBusinessQueryManager();
Organization target = blm2.createOrganization(blm.createInternationalString(orgTarget));
Organization source = blm.createOrganization(blm.createInternationalString(orgSource));
Collection orgs = new ArrayList();
orgs.add(source);
br = blm.saveOrganizations(orgs);
if (br.getExceptions() != null)
{
fail(" Source:Save Orgs failed");
}
sourceKeys = br.getCollection();
Iterator iter = sourceKeys.iterator();
while (iter.hasNext())
{
savekey = (Key) iter.next();
}
sourceId = savekey.getId();
String objectType = LifeCycleManager.ORGANIZATION;
Organization pubSource = (Organization) bqm.getRegistryObject(sourceId, objectType);
assertNotNull("Source retrieved: ", pubSource.getName().getValue());
orgs.clear();
orgs.add(target);
br = blm2.saveOrganizations(orgs);
if (br.getExceptions() != null)
{
fail("Target:Save Orgs failed");
}
targetKeys = br.getCollection();
iter = targetKeys.iterator();
while (iter.hasNext())
{
savekey = (Key) iter.next();
}
targetId = savekey.getId();
Organization pubTarget = (Organization) bqm2.getRegistryObject(targetId, objectType);
assertNotNull("Target: ", pubTarget.getName().getValue());
Concept associationType = getAssociationConcept(type);
if (associationType == null)
fail(" getAssociationConcept returned null");
association = blm.createAssociation(pubTarget, associationType);
association.setSourceObject(pubSource);
blm2.confirmAssociation(association);
Collection associations = new ArrayList();
associations.add(association);
br = blm2.saveAssociations(associations, false);
if (br.getExceptions() != null)
{
fail(" Save Association did not complete due to errors");
}
associationKeys = br.getCollection();
iter = associationKeys.iterator();
Collection associationTypes = new ArrayList();
associationTypes.add(associationType);
//confirmedByCaller = false, confirmedByOtherParty = true.
br = bqm.findCallerAssociations(null,
new Boolean(false),
new Boolean(true), associationTypes);
if (br.getExceptions() != null)
{
fail(" Find Caller Association failed");
}
associations = br.getCollection();
if (associations.size() == 0)
{
fail(" Retrieving Associations failed");
}
iter = associations.iterator();
while (iter.hasNext())
{
association = (Association) iter.next();
}
assertNotNull("Association type:", association.getAssociationType().getValue());
if (association.isConfirmed())
{
fail("FAIL: isConfirmed returned true ");
}
if (association.isConfirmedBySourceOwner())
{
fail("FAIL: isConfirmedBySourceOwner returned true ");
}
blm.confirmAssociation(association);
br = blm.saveAssociations(associations, false);
if (br.getExceptions() != null)
{
fail("Error: saveAssociations failed ");
}
br = bqm.findCallerAssociations(null, new Boolean(true), new Boolean(true), associationTypes);
if (br.getExceptions() != null)
{
fail("Error: findCallerAssociations failed ");
}
associations = br.getCollection();
iter = associations.iterator();
while (iter.hasNext())
{
association = (Association) iter.next();
}
if (!(association.isConfirmed()))
{
fail("FAIL: isConfirmed incorrectly returned false ");
}
if (!(association.isConfirmedBySourceOwner()))
{
fail("FAIL: isConfirmedBySourceOwner incorrectly returned false ");
}
} catch (Exception e)
{
e.printStackTrace();
fail("Caught unexpected exception: " + e.getMessage());
} finally
{
// Clean up
try
{
blm2.deleteOrganizations(targetKeys);
blm.deleteOrganizations(sourceKeys);
if(association != null)
{
Key asskey = association.getKey();
List<Key> keyList = new ArrayList<Key>();
keyList.add(asskey);
blm.deleteAssociations(keyList);
}
} catch (JAXRException je)