KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jaxr > scout > publish > JaxrDeleteAssociationTestCase


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;
23
24 import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
25 import org.jboss.test.jaxr.scout.util.ScoutUtil;
26
27 import javax.xml.registry.BusinessLifeCycleManager JavaDoc;
28 import javax.xml.registry.BusinessQueryManager JavaDoc;
29 import javax.xml.registry.Connection JavaDoc;
30 import javax.xml.registry.JAXRException JavaDoc;
31 import javax.xml.registry.LifeCycleManager JavaDoc;
32 import javax.xml.registry.RegistryService JavaDoc;
33 import javax.xml.registry.infomodel.Association JavaDoc;
34 import javax.xml.registry.infomodel.Concept JavaDoc;
35 import javax.xml.registry.infomodel.Key JavaDoc;
36 import javax.xml.registry.infomodel.Organization JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Collection JavaDoc;
39 import java.util.Iterator JavaDoc;
40
41 /**
42  * Tests Save and Delete of Associations
43  *
44  * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
45  * @since Mar 9, 2005
46  */

47 public class JaxrDeleteAssociationTestCase extends JaxrBaseTestCase
48 {
49     /**
50      * Usecase:
51      * 1. Authenticate two users
52      * 2. First user creates an org (Source org)
53      * 3. Second user creates an org (Target org)
54      * 4. First user creates an association using the target org
55      * 5. Both the users confirm the association
56      * 6. Second user saves the association
57      * 7. First user deletes the association
58      * 8. When the first user asks the registry for associations,
59      * need to get back empty!
60      *
61      * @throws JAXRException
62      */

63     public void testDeleteAssociations() throws JAXRException JavaDoc
64     {
65         Key JavaDoc savekey = null;
66         Key JavaDoc assockey = null;
67         BusinessQueryManager JavaDoc bqm2 = null;
68         BusinessLifeCycleManager JavaDoc blm2 = null;
69         Collection JavaDoc sourceKeys = null;
70         Collection JavaDoc targetKeys = null;
71
72
73         try
74         {
75             login();
76             getJAXREssentials();
77             // second user.
78
Connection JavaDoc con2 = loginSecondUser();
79             RegistryService JavaDoc rs2 = con2.getRegistryService();
80             blm2 = rs2.getBusinessLifeCycleManager();
81             bqm2 = rs2.getBusinessQueryManager();
82             String JavaDoc orgTarget = "Target Organization";
83             String JavaDoc orgSource = "Source Organization";
84
85             Organization JavaDoc target = blm2.createOrganization(blm.createInternationalString(orgTarget));
86             Organization JavaDoc source = blm.createOrganization(blm.createInternationalString(orgSource));
87
88             Collection JavaDoc orgs = new ArrayList JavaDoc();
89             orgs.add(source);
90             br = blm.saveOrganizations(orgs);
91             if (br.getExceptions() != null)
92             {
93                 fail(" Source::Save Organizations failed");
94             }
95             sourceKeys = br.getCollection();
96             Iterator JavaDoc iter = sourceKeys.iterator();
97             while (iter.hasNext())
98             {
99                 savekey = (Key JavaDoc) iter.next();
100             }
101             String JavaDoc sourceid = savekey.getId();
102             String JavaDoc objectType = LifeCycleManager.ORGANIZATION;
103
104             Organization JavaDoc pubSource = (Organization JavaDoc) bqm.getRegistryObject(sourceid, objectType);
105             assertNotNull("Source Org", pubSource.getName().getValue());
106
107             orgs.clear();
108             orgs.add(target);
109             br = blm2.saveOrganizations(orgs);
110             if (br.getExceptions() != null)
111             {
112                 fail("Target:: Save Organizations failed");
113             }
114             targetKeys = br.getCollection();
115             iter = targetKeys.iterator();
116             while (iter.hasNext())
117             {
118                 savekey = (Key JavaDoc) iter.next();
119             }
120             String JavaDoc targetid = savekey.getId();
121             Organization JavaDoc targetOrg = (Organization JavaDoc) bqm2.getRegistryObject(targetid, objectType);
122             assertNotNull("Target Org", targetOrg.getName().getValue());
123
124             Concept JavaDoc associationType = getAssociationConcept("Implements");
125             assertNotNull("AssociationType", associationType);
126
127             Association JavaDoc a = blm.createAssociation(targetOrg, associationType);
128             a.setSourceObject(pubSource);
129
130             blm.confirmAssociation(a);
131             blm2.confirmAssociation(a);
132
133             // publish the Association
134
Collection JavaDoc associations = new ArrayList JavaDoc();
135             associations.add(a);
136             br = blm2.saveAssociations(associations, false);
137
138             if (br.getExceptions() != null)
139             {
140                 fail("Second User :save Association failed");
141             }
142
143             br = bqm.findCallerAssociations(null,
144                     new Boolean JavaDoc(true),
145                     new Boolean JavaDoc(true),
146                     null);
147
148             if (br.getExceptions() == null)
149             {
150                 Collection JavaDoc results = br.getCollection();
151                 if (results.size() > 0)
152                 {
153                     iter = results.iterator();
154                     while (iter.hasNext())
155                     {
156                         Association JavaDoc a1 = (Association JavaDoc) iter.next();
157                         assockey = a1.getKey();
158                         ScoutUtil.validateAssociation(a1, orgSource);
159                     }
160                 }
161             }
162             if (assockey != null)
163             {
164                 Collection JavaDoc keys = new ArrayList JavaDoc();
165                 keys.add(assockey);
166                 blm.deleteAssociations(keys);
167                 br = bqm.findCallerAssociations(null, new Boolean JavaDoc(true), new Boolean JavaDoc(true), null);
168                 if (br.getExceptions() == null)
169                 {
170                     Collection JavaDoc retAssocs = br.getCollection();
171                     if (retAssocs.size() == 0)
172                     {
173                         //Pass
174
} else
175                         fail("Associations should have been zero");
176                 }
177             }
178
179         } catch (Exception JavaDoc e)
180         {
181             e.printStackTrace();
182             System.out.println("Caught unexpected exception: " + e.getMessage());
183             fail(" failed ");
184         } finally
185         {
186             // Clean up
187
try
188             {
189                 blm2.deleteOrganizations(targetKeys);
190                 blm.deleteOrganizations(sourceKeys);
191             } catch (JAXRException JavaDoc je)
192             {
193                 System.out.println("Error: Clean Up Failed");
194             }
195         }
196     }
197 }
198
Popular Tags