001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jaxr.scout.publish;
023:
024: import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
025: import org.jboss.test.jaxr.scout.util.ScoutUtil;
026:
027: import javax.xml.registry.BusinessLifeCycleManager;
028: import javax.xml.registry.BusinessQueryManager;
029: import javax.xml.registry.Connection;
030: import javax.xml.registry.JAXRException;
031: import javax.xml.registry.LifeCycleManager;
032: import javax.xml.registry.RegistryService;
033: import javax.xml.registry.infomodel.Association;
034: import javax.xml.registry.infomodel.Concept;
035: import javax.xml.registry.infomodel.Key;
036: import javax.xml.registry.infomodel.Organization;
037: import java.util.ArrayList;
038: import java.util.Collection;
039: import java.util.Iterator;
040:
041: /**
042: * Tests Save and Delete of Associations
043: *
044: * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
045: * @since Mar 9, 2005
046: */
047: public class JaxrDeleteAssociationTestCase extends JaxrBaseTestCase {
048: /**
049: * Usecase:
050: * 1. Authenticate two users
051: * 2. First user creates an org (Source org)
052: * 3. Second user creates an org (Target org)
053: * 4. First user creates an association using the target org
054: * 5. Both the users confirm the association
055: * 6. Second user saves the association
056: * 7. First user deletes the association
057: * 8. When the first user asks the registry for associations,
058: * need to get back empty!
059: *
060: * @throws JAXRException
061: */
062: public void testDeleteAssociations() throws JAXRException {
063: Key savekey = null;
064: Key assockey = null;
065: BusinessQueryManager bqm2 = null;
066: BusinessLifeCycleManager blm2 = null;
067: Collection sourceKeys = null;
068: Collection targetKeys = null;
069:
070: try {
071: login();
072: getJAXREssentials();
073: // second user.
074: Connection con2 = loginSecondUser();
075: RegistryService rs2 = con2.getRegistryService();
076: blm2 = rs2.getBusinessLifeCycleManager();
077: bqm2 = rs2.getBusinessQueryManager();
078: String orgTarget = "Target Organization";
079: String orgSource = "Source Organization";
080:
081: Organization target = blm2.createOrganization(blm
082: .createInternationalString(orgTarget));
083: Organization source = blm.createOrganization(blm
084: .createInternationalString(orgSource));
085:
086: Collection orgs = new ArrayList();
087: orgs.add(source);
088: br = blm.saveOrganizations(orgs);
089: if (br.getExceptions() != null) {
090: fail(" Source::Save Organizations failed");
091: }
092: sourceKeys = br.getCollection();
093: Iterator iter = sourceKeys.iterator();
094: while (iter.hasNext()) {
095: savekey = (Key) iter.next();
096: }
097: String sourceid = savekey.getId();
098: String objectType = LifeCycleManager.ORGANIZATION;
099:
100: Organization pubSource = (Organization) bqm
101: .getRegistryObject(sourceid, objectType);
102: assertNotNull("Source Org", pubSource.getName().getValue());
103:
104: orgs.clear();
105: orgs.add(target);
106: br = blm2.saveOrganizations(orgs);
107: if (br.getExceptions() != null) {
108: fail("Target:: Save Organizations failed");
109: }
110: targetKeys = br.getCollection();
111: iter = targetKeys.iterator();
112: while (iter.hasNext()) {
113: savekey = (Key) iter.next();
114: }
115: String targetid = savekey.getId();
116: Organization targetOrg = (Organization) bqm2
117: .getRegistryObject(targetid, objectType);
118: assertNotNull("Target Org", targetOrg.getName().getValue());
119:
120: Concept associationType = getAssociationConcept("Implements");
121: assertNotNull("AssociationType", associationType);
122:
123: Association a = blm.createAssociation(targetOrg,
124: associationType);
125: a.setSourceObject(pubSource);
126:
127: blm.confirmAssociation(a);
128: blm2.confirmAssociation(a);
129:
130: // publish the Association
131: Collection associations = new ArrayList();
132: associations.add(a);
133: br = blm2.saveAssociations(associations, false);
134:
135: if (br.getExceptions() != null) {
136: fail("Second User :save Association failed");
137: }
138:
139: br = bqm.findCallerAssociations(null, new Boolean(true),
140: new Boolean(true), null);
141:
142: if (br.getExceptions() == null) {
143: Collection results = br.getCollection();
144: if (results.size() > 0) {
145: iter = results.iterator();
146: while (iter.hasNext()) {
147: Association a1 = (Association) iter.next();
148: assockey = a1.getKey();
149: ScoutUtil.validateAssociation(a1, orgSource);
150: }
151: }
152: }
153: if (assockey != null) {
154: Collection keys = new ArrayList();
155: keys.add(assockey);
156: blm.deleteAssociations(keys);
157: br = bqm.findCallerAssociations(null,
158: new Boolean(true), new Boolean(true), null);
159: if (br.getExceptions() == null) {
160: Collection retAssocs = br.getCollection();
161: if (retAssocs.size() == 0) {
162: //Pass
163: } else
164: fail("Associations should have been zero");
165: }
166: }
167:
168: } catch (Exception e) {
169: e.printStackTrace();
170: System.out.println("Caught unexpected exception: "
171: + e.getMessage());
172: fail(" failed ");
173: } finally {
174: // Clean up
175: try {
176: blm2.deleteOrganizations(targetKeys);
177: blm.deleteOrganizations(sourceKeys);
178: } catch (JAXRException je) {
179: System.out.println("Error: Clean Up Failed");
180: }
181: }
182: }
183: }
|