KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jaxr > scout > publish > infomodel > JaxrConfimAssociationTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 JavaDoc;
27 import javax.xml.registry.BusinessQueryManager JavaDoc;
28 import javax.xml.registry.Connection JavaDoc;
29 import javax.xml.registry.JAXRException JavaDoc;
30 import javax.xml.registry.LifeCycleManager JavaDoc;
31 import javax.xml.registry.RegistryService JavaDoc;
32 import javax.xml.registry.infomodel.Association JavaDoc;
33 import javax.xml.registry.infomodel.Concept JavaDoc;
34 import javax.xml.registry.infomodel.Key JavaDoc;
35 import javax.xml.registry.infomodel.Organization JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Collection JavaDoc;
38 import java.util.Iterator JavaDoc;
39
40 /**
41  * Tests confirming Association
42  *
43  * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
44  * @since Mar 9, 2005
45  */

46 public class JaxrConfimAssociationTestCase extends JaxrBaseTestCase
47 {
48     /**
49      * Testcase that tests the association between two organizations
50      *
51      * @throws JAXRException
52      */

53     public void testConfirmAssociation() throws JAXRException JavaDoc
54     {
55         String JavaDoc orgTarget = "Target Organization";
56         String JavaDoc orgSource = "Source Organization";
57         String JavaDoc type = "Implements";
58         Key JavaDoc savekey = null;
59
60         Collection JavaDoc associationKeys = null;
61         Collection JavaDoc sourceKeys = null;
62         Collection JavaDoc targetKeys = null;
63         String JavaDoc targetId = null;
64         String JavaDoc sourceId = null;
65         BusinessQueryManager JavaDoc bqm2 = null;
66         BusinessLifeCycleManager JavaDoc blm2 = null;
67
68
69         try
70         {
71             login();
72             getJAXREssentials();
73
74             // second user.
75
Connection JavaDoc con2 = loginSecondUser();
76             RegistryService JavaDoc rs2 = con2.getRegistryService();
77             blm2 = rs2.getBusinessLifeCycleManager();
78             bqm2 = rs2.getBusinessQueryManager();
79
80             Organization JavaDoc target = blm2.createOrganization(blm.createInternationalString(orgTarget));
81             Organization JavaDoc source = blm.createOrganization(blm.createInternationalString(orgSource));
82
83             Collection JavaDoc orgs = new ArrayList JavaDoc();
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 JavaDoc iter = sourceKeys.iterator();
93             while (iter.hasNext())
94             {
95                 savekey = (Key JavaDoc) iter.next();
96             }
97             sourceId = savekey.getId();
98
99             String JavaDoc objectType = LifeCycleManager.ORGANIZATION;
100             Organization JavaDoc pubSource = (Organization JavaDoc) 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 JavaDoc) iter.next();
115             }
116             targetId = savekey.getId();
117
118             Organization JavaDoc pubTarget = (Organization JavaDoc) bqm2.getRegistryObject(targetId, objectType);
119             assertNotNull("Target: ", pubTarget.getName().getValue());
120
121             Concept JavaDoc associationType = getAssociationConcept(type);
122             if (associationType == null)
123                 fail(" getAssociationConcept returned null");
124
125             Association JavaDoc a = blm.createAssociation(pubTarget, associationType);
126             a.setSourceObject(pubSource);
127
128             blm2.confirmAssociation(a);
129
130             Collection JavaDoc associations = new ArrayList JavaDoc();
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 JavaDoc associationTypes = new ArrayList JavaDoc();
142             associationTypes.add(associationType);
143             //confirmedByCaller = false, confirmedByOtherParty = true.
144
br = bqm.findCallerAssociations(null,
145                     new Boolean JavaDoc(false),
146                     new Boolean JavaDoc(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 JavaDoc) 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 JavaDoc(true), new Boolean JavaDoc(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 JavaDoc) 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 JavaDoc e)
204         {
205             e.printStackTrace();
206             fail("Caught unexpected exception: " + e.getMessage());
207         } finally
208         {
209             // Clean up
210
try
211             {
212                 blm2.deleteOrganizations(targetKeys);
213                 blm.deleteOrganizations(sourceKeys);
214             } catch (JAXRException JavaDoc je)
215             {
216                 fail("Error: not able to delete registry objects");
217             }
218         }
219     }
220
221 }
222
Popular Tags