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.infomodel;
023:
024: import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
025:
026: import javax.xml.registry.BusinessLifeCycleManager;
027: import javax.xml.registry.BusinessQueryManager;
028: import javax.xml.registry.Connection;
029: import javax.xml.registry.JAXRException;
030: import javax.xml.registry.LifeCycleManager;
031: import javax.xml.registry.RegistryService;
032: import javax.xml.registry.infomodel.Association;
033: import javax.xml.registry.infomodel.Concept;
034: import javax.xml.registry.infomodel.Key;
035: import javax.xml.registry.infomodel.Organization;
036: import java.util.ArrayList;
037: import java.util.Collection;
038: import java.util.Iterator;
039:
040: /**
041: * Tests confirming Association
042: *
043: * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
044: * @since Mar 9, 2005
045: */
046: public class JaxrConfimAssociationTestCase extends JaxrBaseTestCase {
047: /**
048: * Testcase that tests the association between two organizations
049: *
050: * @throws JAXRException
051: */
052: public void testConfirmAssociation() throws JAXRException {
053: String orgTarget = "Target Organization";
054: String orgSource = "Source Organization";
055: String type = "Implements";
056: Key savekey = null;
057:
058: Collection associationKeys = null;
059: Collection sourceKeys = null;
060: Collection targetKeys = null;
061: String targetId = null;
062: String sourceId = null;
063: BusinessQueryManager bqm2 = null;
064: BusinessLifeCycleManager blm2 = null;
065:
066: try {
067: login();
068: getJAXREssentials();
069:
070: // second user.
071: Connection con2 = loginSecondUser();
072: RegistryService rs2 = con2.getRegistryService();
073: blm2 = rs2.getBusinessLifeCycleManager();
074: bqm2 = rs2.getBusinessQueryManager();
075:
076: Organization target = blm2.createOrganization(blm
077: .createInternationalString(orgTarget));
078: Organization source = blm.createOrganization(blm
079: .createInternationalString(orgSource));
080:
081: Collection orgs = new ArrayList();
082: orgs.add(source);
083: br = blm.saveOrganizations(orgs);
084: if (br.getExceptions() != null) {
085: fail(" Source:Save Orgs failed");
086: }
087:
088: sourceKeys = br.getCollection();
089: Iterator iter = sourceKeys.iterator();
090: while (iter.hasNext()) {
091: savekey = (Key) iter.next();
092: }
093: sourceId = savekey.getId();
094:
095: String objectType = LifeCycleManager.ORGANIZATION;
096: Organization pubSource = (Organization) bqm
097: .getRegistryObject(sourceId, objectType);
098: assertNotNull("Source retrieved: ", pubSource.getName()
099: .getValue());
100:
101: orgs.clear();
102: orgs.add(target);
103: br = blm2.saveOrganizations(orgs);
104: if (br.getExceptions() != null) {
105: fail("Target:Save Orgs failed");
106: }
107: targetKeys = br.getCollection();
108: iter = targetKeys.iterator();
109: while (iter.hasNext()) {
110: savekey = (Key) iter.next();
111: }
112: targetId = savekey.getId();
113:
114: Organization pubTarget = (Organization) bqm2
115: .getRegistryObject(targetId, objectType);
116: assertNotNull("Target: ", pubTarget.getName().getValue());
117:
118: Concept associationType = getAssociationConcept(type);
119: if (associationType == null)
120: fail(" getAssociationConcept returned null");
121:
122: Association a = blm.createAssociation(pubTarget,
123: associationType);
124: a.setSourceObject(pubSource);
125:
126: blm2.confirmAssociation(a);
127:
128: Collection associations = new ArrayList();
129: associations.add(a);
130: br = blm2.saveAssociations(associations, false);
131: if (br.getExceptions() != null) {
132: fail(" Save Association did not complete due to errors");
133: }
134:
135: associationKeys = br.getCollection();
136: iter = associationKeys.iterator();
137:
138: Collection associationTypes = new ArrayList();
139: associationTypes.add(associationType);
140: //confirmedByCaller = false, confirmedByOtherParty = true.
141: br = bqm.findCallerAssociations(null, new Boolean(false),
142: new Boolean(true), associationTypes);
143: if (br.getExceptions() != null) {
144: fail(" Find Caller Association failed");
145: }
146: associations = br.getCollection();
147: if (associations.size() == 0) {
148: fail(" Retrieving Associations failed");
149: }
150: iter = associations.iterator();
151: while (iter.hasNext()) {
152: a = (Association) iter.next();
153: }
154:
155: assertNotNull("Association type:", a.getAssociationType()
156: .getValue());
157: if (a.isConfirmed()) {
158: fail("FAIL: isConfirmed returned true ");
159: }
160: if (a.isConfirmedBySourceOwner()) {
161: fail("FAIL: isConfirmedBySourceOwner returned true ");
162: }
163:
164: blm.confirmAssociation(a);
165: br = blm.saveAssociations(associations, false);
166: if (br.getExceptions() != null) {
167: fail("Error: saveAssociations failed ");
168: }
169:
170: br = bqm.findCallerAssociations(null, new Boolean(true),
171: new Boolean(true), associationTypes);
172:
173: if (br.getExceptions() != null) {
174: fail("Error: findCallerAssociations failed ");
175: }
176:
177: associations = br.getCollection();
178: iter = associations.iterator();
179: while (iter.hasNext()) {
180: a = (Association) iter.next();
181: }
182:
183: if (!(a.isConfirmed())) {
184: fail("FAIL: isConfirmed incorrectly returned false ");
185: }
186:
187: if (!(a.isConfirmedBySourceOwner())) {
188: fail("FAIL: isConfirmedBySourceOwner incorrectly returned false ");
189: }
190: } catch (Exception e) {
191: e.printStackTrace();
192: fail("Caught unexpected exception: " + e.getMessage());
193: } finally {
194: // Clean up
195: try {
196: blm2.deleteOrganizations(targetKeys);
197: blm.deleteOrganizations(sourceKeys);
198: } catch (JAXRException je) {
199: fail("Error: not able to delete registry objects");
200: }
201: }
202: }
203:
204: }
|