This project has retired. For details please refer to its Attic page.
OwnershipTest xref
View Javadoc
1   /*
2    * Copyright 2001-2009 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.ws.scout.registry;
17  
18  import static org.junit.Assert.fail;
19  
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.Iterator;
23  import java.util.Locale;
24  
25  import javax.xml.registry.BulkResponse;
26  import javax.xml.registry.BusinessLifeCycleManager;
27  import javax.xml.registry.BusinessQueryManager;
28  import javax.xml.registry.JAXRException;
29  import javax.xml.registry.JAXRResponse;
30  import javax.xml.registry.LifeCycleManager;
31  import javax.xml.registry.RegistryService;
32  import javax.xml.registry.infomodel.InternationalString;
33  import javax.xml.registry.infomodel.Key;
34  import javax.xml.registry.infomodel.Organization;
35  
36  import org.apache.ws.scout.BaseTestCase;
37  import org.junit.After;
38  import org.junit.Before;
39  import org.junit.Test;
40  
41  /**
42   *
43   * Test for SCOUT-55 which attempts to test whether getRegistryObjects() returns caller structures, or all structures. 
44   * At the moment there appears no way of implementing this using the UDDI API, so the actual test is being checked in
45   * commented out (it will fail).    Would be good to have if we can figure out how to fix SCOUT-55.
46   *
47   * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
48   */
49  public class OwnershipTest extends BaseTestCase {
50  	RegistryService rs, rs2;
51  	private BusinessQueryManager bqm, bqm2;
52  	@SuppressWarnings("unused")
53  	private BusinessLifeCycleManager blm, blm2;
54  	Collection associationKeys = null;
55  	
56      @Before
57      public void setUp() {
58          super.setUp();
59          login();
60          loginSecondUser();
61  		try {
62  			rs = connection.getRegistryService();
63  	    	bqm = rs.getBusinessQueryManager();
64  	    	blm = rs.getBusinessLifeCycleManager();
65  	        
66  	    	rs2 = connection2.getRegistryService();
67  	        blm2 = rs2.getBusinessLifeCycleManager();
68  	        bqm2 = rs2.getBusinessQueryManager();
69  
70  		} catch (JAXRException e) {
71  			fail(e.getMessage());
72  		}
73      }
74      
75      @After
76      public void tearDown() {
77          super.tearDown();
78  
79      }
80      
81      private InternationalString getIString(String str)
82      throws JAXRException
83      {
84          return blm.createInternationalString(str);
85      }
86  
87      
88      private Organization createTempOrg(String tempOrgName, BusinessLifeCycleManager blm) throws JAXRException {
89          Key orgKey = null;
90          Organization org = blm.createOrganization(getIString(tempOrgName));
91          org.setDescription(getIString("Temporary organization to test saveService()"));
92  
93          Collection<Organization> orgs = new ArrayList<Organization>();
94          orgs.add(org);
95          BulkResponse br = blm.saveOrganizations(orgs);
96  
97          if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
98          {
99              orgKey = (Key) br.getCollection().iterator().next();
100             System.out.println("Temporary Organization Created with id=" + orgKey.getId());
101             org.setKey(orgKey);
102         }  else
103         {
104             System.err.println("JAXRExceptions " +
105                     "occurred during creation of temporary organization:");
106 
107             Iterator iter = br.getCollection().iterator();
108 
109             while (iter.hasNext()) {
110                 Exception e = (Exception) iter.next();
111                 System.err.println(e.toString());
112             }
113 
114             fail();
115         }
116         return org;
117     }
118 
119     private void deleteTempOrg(Key key) throws JAXRException {
120 
121         if (key == null) {
122                 return;
123         }
124 
125         String id = key.getId();
126 
127         System.out.println("\nDeleting temporary organization with id " + id + "\n");
128 
129         Collection<Key> keys = new ArrayList<Key>();
130         keys.add(key);
131         BulkResponse response = blm.deleteOrganizations(keys);
132 
133         Collection exceptions = response.getExceptions();
134         if (exceptions == null) {
135                 Collection retKeys = response.getCollection();
136                 Iterator keyIter = retKeys.iterator();
137                 Key orgKey = null;
138                 if (keyIter.hasNext()) {
139                         orgKey =
140                                 (javax.xml.registry.infomodel.Key) keyIter.next();
141                         id = orgKey.getId();
142                         System.out.println("Organization with ID=" + id + " was deleted");
143                 }
144         }
145     }
146     
147     @Test
148 	public void testGetRegistryObjects() {
149 
150     	login();
151         try {
152 
153         	Organization org1 = createTempOrg("OWNERSHIPTEST Organization 1", blm);
154         	Organization org2 = createTempOrg("OWNERSHIPTEST Organization 2", blm);
155         	
156         	BulkResponse br = bqm.getRegistryObjects(LifeCycleManager.ORGANIZATION);
157             if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
158             {
159             	System.out.println("BR.size : " + br.getCollection().size());
160             	Collection coll1 = br.getCollection();
161             	Iterator iterator = coll1.iterator();
162             	Collection<String> orgKeys = new ArrayList<String>();
163             	while (iterator.hasNext()) {
164             		Organization org = (Organization) iterator.next();
165             		System.out.println("BR " + org.getName().getValue(Locale.US));
166             		orgKeys.add(org.getKey().getId());
167             	}
168 
169             	if (br.getCollection().size() == 0) {
170             		fail("Found no organizations for user 1");
171             	}
172             	
173             	BulkResponse br2 = bqm2.getRegistryObjects(LifeCycleManager.ORGANIZATION);
174                 if (br2.getStatus() == JAXRResponse.STATUS_SUCCESS)
175                 {
176                 	Collection coll = br2.getCollection();
177                 	Iterator iterator2 = coll.iterator();
178                 	while (iterator2.hasNext()) {
179                 		Organization org = (Organization) iterator2.next();
180                 		System.out.println("BR2 " + org.getName().getValue(Locale.US));
181                 		if (orgKeys.contains(org.getKey().getId())) {
182                 			fail("Should not find organizations from user1");
183                 		}
184                 		
185                 	}
186                 }        	
187             	
188             	deleteTempOrg(org1.getKey());
189             	deleteTempOrg(org2.getKey());
190 
191             }
192         	
193         	
194         
195 		} catch (JAXRException e) {
196 			e.printStackTrace();
197 		}
198 		
199 	}
200 }