001: package org.apache.ws.scout.registry;
002:
003: import static org.junit.Assert.assertEquals;
004: import static org.junit.Assert.fail;
005:
006: import java.util.ArrayList;
007: import java.util.Collection;
008: import java.util.Iterator;
009:
010: import javax.xml.registry.BulkResponse;
011: import javax.xml.registry.JAXRException;
012: import javax.xml.registry.JAXRResponse;
013: import javax.xml.registry.RegistryService;
014: import javax.xml.registry.infomodel.Association;
015: import javax.xml.registry.infomodel.ClassificationScheme;
016: import javax.xml.registry.infomodel.Concept;
017: import javax.xml.registry.infomodel.InternationalString;
018: import javax.xml.registry.infomodel.Key;
019: import javax.xml.registry.infomodel.Organization;
020: import javax.xml.registry.infomodel.Service;
021: import javax.xml.registry.infomodel.ServiceBinding;
022:
023: import junit.framework.JUnit4TestAdapter;
024:
025: import org.apache.ws.scout.BaseTestCase;
026: import org.apache.ws.scout.Creator;
027: import org.junit.After;
028: import org.junit.Before;
029: import org.junit.Test;
030:
031: /**
032: * Tests the BusinessLifecycleManagerImpl class
033: */
034: public class BusinessLifeCyleManagerlTest extends BaseTestCase {
035: @Before
036: public void setUp() {
037: super .setUp();
038: }
039:
040: @After
041: public void tearDown() {
042: super .tearDown();
043: }
044:
045: @SuppressWarnings("unchecked")
046: @Test
047: public void saveDeleteOrganizations() {
048: login();
049: Collection<Key> orgKeys = new ArrayList<Key>();
050: try {
051: RegistryService rs = connection.getRegistryService();
052: blm = rs.getBusinessLifeCycleManager();
053: Creator creator = new Creator(blm);
054: Collection<Organization> orgs = new ArrayList<Organization>();
055: Organization organization = creator.createOrganization(this
056: .getClass().getName());
057: orgs.add(organization);
058:
059: //save the Organization
060: BulkResponse br = blm.saveOrganizations(orgs);
061: assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
062: orgKeys = (Collection<Key>) br.getCollection();
063: } catch (Exception e) {
064: e.printStackTrace();
065: fail(e.getMessage());
066: }
067:
068: try {
069: RegistryService rs = connection.getRegistryService();
070: blm = rs.getBusinessLifeCycleManager();
071: BulkResponse br = blm.deleteOrganizations(orgKeys);
072: assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
073: } catch (Exception e) {
074: e.printStackTrace();
075: fail(e.getMessage());
076: }
077: }
078:
079: @SuppressWarnings("unchecked")
080: @Test
081: public void saveDeleteClassificationSchemes() {
082: login();
083:
084: try {
085: RegistryService rs = connection.getRegistryService();
086: blm = rs.getBusinessLifeCycleManager();
087:
088: ClassificationScheme cScheme = blm
089: .createClassificationScheme(
090: "testScheme -- APACHE SCOUT TEST",
091: "Sample Classification Scheme");
092:
093: ArrayList<ClassificationScheme> cSchemes = new ArrayList<ClassificationScheme>();
094: cSchemes.add(cScheme);
095: //save
096: BulkResponse br = blm.saveClassificationSchemes(cSchemes);
097: assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
098: //remove
099: BulkResponse br2 = blm
100: .deleteClassificationSchemes((Collection<Key>) br
101: .getCollection());
102: assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
103: } catch (JAXRException je) {
104: fail(je.getMessage());
105: }
106: }
107:
108: @SuppressWarnings("unchecked")
109: @Test
110: public void saveDeleteServices() {
111: login();
112:
113: try {
114: RegistryService rs = connection.getRegistryService();
115: blm = rs.getBusinessLifeCycleManager();
116: Creator creator = new Creator(blm);
117: Collection<Organization> orgs = new ArrayList<Organization>();
118: Organization organization = creator.createOrganization(this
119: .getClass().getName());
120: orgs.add(organization);
121: // save the Organization
122: BulkResponse br = blm.saveOrganizations(orgs);
123: assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
124: organization.setKey((Key) br.getCollection().iterator()
125: .next());
126:
127: Service service = creator.createService(this .getClass()
128: .getName());
129: ArrayList<Service> services = new ArrayList<Service>();
130: organization.addService(service);
131: services.add(service);
132: //save service
133: BulkResponse br2 = blm.saveServices(services);
134: assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
135: //remove service
136: BulkResponse br3 = blm.deleteServices((Collection<Key>) br2
137: .getCollection());
138: assertEquals(BulkResponse.STATUS_SUCCESS, br3.getStatus());
139: //remove organization
140: BulkResponse br4 = blm
141: .deleteOrganizations((Collection<Key>) br
142: .getCollection());
143: assertEquals(JAXRResponse.STATUS_SUCCESS, br4.getStatus());
144: } catch (JAXRException je) {
145: fail(je.getMessage());
146: }
147: }
148:
149: @SuppressWarnings("unchecked")
150: @Test
151: public void saveDeleteServiceBindings() {
152: login();
153:
154: try {
155: RegistryService rs = connection.getRegistryService();
156: blm = rs.getBusinessLifeCycleManager();
157: Creator creator = new Creator(blm);
158: Collection<Organization> orgs = new ArrayList<Organization>();
159: Organization organization = creator.createOrganization(this
160: .getClass().getName());
161: orgs.add(organization);
162: // save the Organization
163: BulkResponse br = blm.saveOrganizations(orgs);
164: assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
165: organization.setKey((Key) br.getCollection().iterator()
166: .next());
167:
168: Service service = creator.createService(this .getClass()
169: .getName());
170: ArrayList<Service> services = new ArrayList<Service>();
171: organization.addService(service);
172: services.add(service);
173: //save service
174: BulkResponse br2 = blm.saveServices(services);
175: assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
176:
177: service.setKey((Key) br2.getCollection().iterator().next());
178:
179: //save serviceBinding
180: ServiceBinding serviceBinding = creator
181: .createServiceBinding();
182: service.addServiceBinding(serviceBinding);
183: ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
184: serviceBindings.add(serviceBinding);
185: BulkResponse br5 = blm.saveServiceBindings(serviceBindings);
186: assertEquals(BulkResponse.STATUS_SUCCESS, br5.getStatus());
187:
188: //remove serviceBindings
189: BulkResponse br6 = blm
190: .deleteServiceBindings((Collection<Key>) br5
191: .getCollection());
192: assertEquals(BulkResponse.STATUS_SUCCESS, br6.getStatus());
193:
194: //remove service
195: BulkResponse br3 = blm.deleteServices((Collection<Key>) br2
196: .getCollection());
197: assertEquals(BulkResponse.STATUS_SUCCESS, br3.getStatus());
198: //remove organization
199: BulkResponse br4 = blm
200: .deleteOrganizations((Collection<Key>) br
201: .getCollection());
202: assertEquals(JAXRResponse.STATUS_SUCCESS, br4.getStatus());
203: } catch (JAXRException je) {
204: fail(je.getMessage());
205: }
206: }
207:
208: @SuppressWarnings("unchecked")
209: @Test
210: public void saveDeleteConcepts() {
211: login();
212: try {
213: RegistryService rs = connection.getRegistryService();
214: blm = rs.getBusinessLifeCycleManager();
215: Collection<Concept> concepts = new ArrayList<Concept>();
216: Concept concept = blm
217: .createConcept(null, "TestConcept", "");
218: InternationalString is = blm
219: .createInternationalString("This is the concept for Apache Scout Test");
220: concept.setDescription(is);
221: concepts.add(concept);
222:
223: BulkResponse br = blm.saveConcepts(concepts);
224: assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
225:
226: BulkResponse br2 = blm.deleteConcepts((Collection<Key>) br
227: .getCollection());
228: assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
229: } catch (JAXRException je) {
230: fail(je.getMessage());
231: }
232: }
233:
234: @SuppressWarnings("unchecked")
235: @Test
236: public void saveDeleteAssociations() {
237: login();
238: try {
239: RegistryService rs = connection.getRegistryService();
240: blm = rs.getBusinessLifeCycleManager();
241: bqm = rs.getBusinessQueryManager();
242: Creator creator = new Creator(blm);
243:
244: System.out
245: .println("\nCreating temporary organizations...\n");
246: Organization sOrg = creator.createOrganization("sourceOrg");
247: Organization tOrg = creator.createOrganization("targetOrg");
248: Collection<Organization> organizations = new ArrayList<Organization>();
249: organizations.add(sOrg);
250: organizations.add(tOrg);
251: BulkResponse br = blm.saveOrganizations(organizations);
252: assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
253: //setting the keys on the organizations
254: Collection<Key> keys = (Collection<Key>) br.getCollection();
255: Iterator<Key> iterator = keys.iterator();
256: sOrg.setKey(iterator.next());
257: tOrg.setKey(iterator.next());
258: //creating the RelatedTo Association between these two organizations
259: Concept type = bqm
260: .findConceptByPath("AssociationType/RelatedTo");
261: Association association = blm.createAssociation(tOrg, type);
262: sOrg.addAssociation(association);
263: ArrayList<Association> associations = new ArrayList<Association>();
264: associations.add(association);
265: //save associations
266: BulkResponse br2 = blm.saveAssociations(associations, true);
267: assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
268:
269: //delete association
270: BulkResponse br3 = blm
271: .deleteAssociations((Collection<Key>) br2
272: .getCollection());
273: assertEquals(BulkResponse.STATUS_SUCCESS, br3.getStatus());
274:
275: //delete organizations
276: BulkResponse br4 = blm
277: .deleteOrganizations((Collection<Key>) br
278: .getCollection());
279: assertEquals(BulkResponse.STATUS_SUCCESS, br4.getStatus());
280:
281: } catch (JAXRException je) {
282: fail(je.getMessage());
283: }
284: }
285:
286: public static junit.framework.Test suite() {
287: return new JUnit4TestAdapter(BusinessLifeCyleManagerlTest.class);
288: }
289:
290: }
|