}
}
@Test
public void testFindCallerAssociations() {
BulkResponse br = null;
try {
// Are there any associations so far?
try {
br = bqm.findCallerAssociations(null,
new Boolean(true),
new Boolean(true),
null);
if (br.getCollection().size() != 0) {
fail("Should not reach here - no associations created yet.");
}
} catch (Exception e) {
}
String orgOne = "Organization One";
String orgTwo = "Organization Two";
Organization source = blm.createOrganization(blm.createInternationalString(orgOne));
Organization target = blm2.createOrganization(blm2.createInternationalString(orgTwo));
Collection orgs = new ArrayList();
orgs.add(source);
br = blm.saveOrganizations(orgs);
if (br.getExceptions() != null)
{
fail("Save Organization failed");
}
Collection sourceKeys = br.getCollection();
Iterator iter = sourceKeys.iterator();
Key savekey = null;
while (iter.hasNext())
{
savekey = (Key) iter.next();
}
String sourceid = savekey.getId();
Organization queried = (Organization) bqm.getRegistryObject(sourceid, LifeCycleManager.ORGANIZATION);
assertNotNull("Source Org", queried.getName().getValue());
Collection orgstwo = new ArrayList();
orgstwo.add(target);
br = blm2.saveOrganizations(orgstwo);
if (br.getExceptions() != null)
{
fail("Save Organizations failed");
}
Collection targetKeys = br.getCollection();
iter = targetKeys.iterator();
while (iter.hasNext())
{
savekey = (Key) iter.next();
}
String targetid = savekey.getId();
Organization targetOrg = (Organization) bqm2.getRegistryObject(targetid, LifeCycleManager.ORGANIZATION);
assertNotNull("Target Org", targetOrg.getName().getValue());
Concept associationType = null;
ClassificationScheme associationTypes =
bqm.findClassificationSchemeByName(null, "AssociationType");
Collection types = associationTypes.getChildrenConcepts();
iter = types.iterator();
Concept concept = null;
while (iter.hasNext())
{
concept = (Concept) iter.next();
if (concept.getName().getValue().equals("Implements"))
{
associationType = concept;
}
}
Association a = blm.createAssociation(targetOrg, associationType);
a.setSourceObject(queried);
blm2.confirmAssociation(a);
// publish the Association
Collection associations = new ArrayList();
associations.add(a);
br = blm2.saveAssociations(associations, false);
if (br.getExceptions() != null)
{
fail("Save association failed");
}
associationKeys = br.getCollection();
iter = associationKeys.iterator();
Collection aTypes = new ArrayList();
aTypes.add(associationType);