001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.registry;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020:
021: import javax.xml.registry.BulkResponse;
022: import javax.xml.registry.InvalidRequestException;
023: import javax.xml.registry.JAXRException;
024: import javax.xml.registry.LifeCycleManager;
025: import javax.xml.registry.RegistryService;
026: import javax.xml.registry.UnsupportedCapabilityException;
027: import javax.xml.registry.infomodel.Association;
028: import javax.xml.registry.infomodel.Classification;
029: import javax.xml.registry.infomodel.ClassificationScheme;
030: import javax.xml.registry.infomodel.Concept;
031: import javax.xml.registry.infomodel.EmailAddress;
032: import javax.xml.registry.infomodel.ExternalIdentifier;
033: import javax.xml.registry.infomodel.ExternalLink;
034: import javax.xml.registry.infomodel.Key;
035: import javax.xml.registry.infomodel.Organization;
036: import javax.xml.registry.infomodel.PersonName;
037: import javax.xml.registry.infomodel.Service;
038: import javax.xml.registry.infomodel.ServiceBinding;
039: import javax.xml.registry.infomodel.User;
040:
041: import junit.framework.TestCase;
042:
043: import org.apache.ws.scout.registry.infomodel.AssociationImpl;
044: import org.apache.ws.scout.registry.infomodel.ClassificationImpl;
045: import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
046: import org.apache.ws.scout.registry.infomodel.ConceptImpl;
047: import org.apache.ws.scout.registry.infomodel.EmailAddressImpl;
048: import org.apache.ws.scout.registry.infomodel.ExternalIdentifierImpl;
049: import org.apache.ws.scout.registry.infomodel.ExternalLinkImpl;
050: import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
051: import org.apache.ws.scout.registry.infomodel.KeyImpl;
052: import org.apache.ws.scout.registry.infomodel.LocalizedStringImpl;
053: import org.apache.ws.scout.registry.infomodel.OrganizationImpl;
054: import org.apache.ws.scout.registry.infomodel.PersonNameImpl;
055: import org.apache.ws.scout.registry.infomodel.PostalAddressImpl;
056: import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
057: import org.apache.ws.scout.registry.infomodel.ServiceImpl;
058: import org.apache.ws.scout.registry.infomodel.SlotImpl;
059: import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
060: import org.apache.ws.scout.registry.infomodel.TelephoneNumberImpl;
061: import org.apache.ws.scout.registry.infomodel.UserImpl;
062:
063: /**
064: *
065: * @version $Rev$ $Date$ $Author$
066: */
067: public class LifeCycleManagerTest extends TestCase {
068: private LifeCycleManager manager;
069:
070: public void testCreateObjectAssociation() throws JAXRException {
071: Association assoc = (Association) manager
072: .createObject(LifeCycleManager.ASSOCIATION);
073: assertEquals(AssociationImpl.class, assoc.getClass());
074: assertSame(manager, assoc.getLifeCycleManager());
075: }
076:
077: public void testCreateObjectAuditableEvent() throws JAXRException {
078: try {
079: manager.createObject(LifeCycleManager.AUDITABLE_EVENT);
080: fail();
081: } catch (UnsupportedCapabilityException e) {
082: // OK
083: }
084: }
085:
086: public void testCreateObjectClassification() throws JAXRException {
087: Classification classification = (Classification) manager
088: .createObject(LifeCycleManager.CLASSIFICATION);
089: assertEquals(ClassificationImpl.class, classification
090: .getClass());
091: assertSame(manager, classification.getLifeCycleManager());
092: }
093:
094: public void testCreateObjectClassificationScheme()
095: throws JAXRException {
096: ClassificationScheme classificationScheme = (ClassificationScheme) manager
097: .createObject(LifeCycleManager.CLASSIFICATION_SCHEME);
098: assertEquals(ClassificationSchemeImpl.class,
099: classificationScheme.getClass());
100: assertSame(manager, classificationScheme.getLifeCycleManager());
101: }
102:
103: public void testCreateObjectConcept() throws JAXRException {
104: Concept concept = (Concept) manager
105: .createObject(LifeCycleManager.CONCEPT);
106: assertEquals(ConceptImpl.class, concept.getClass());
107: assertSame(manager, concept.getLifeCycleManager());
108: }
109:
110: public void testCreateObjectEmailAddress() throws JAXRException {
111: assertEquals(EmailAddressImpl.class, ((EmailAddress) manager
112: .createObject(LifeCycleManager.EMAIL_ADDRESS))
113: .getClass());
114: }
115:
116: public void testCreateObjectExternalIdentifier()
117: throws JAXRException {
118: ExternalIdentifier externalIdentifier = ((ExternalIdentifier) manager
119: .createObject(LifeCycleManager.EXTERNAL_IDENTIFIER));
120: assertEquals(ExternalIdentifierImpl.class, externalIdentifier
121: .getClass());
122: assertSame(manager, externalIdentifier.getLifeCycleManager());
123: }
124:
125: public void testCreateObjectExternalLink() throws JAXRException {
126: ExternalLink externalLink = (ExternalLink) manager
127: .createObject(LifeCycleManager.EXTERNAL_LINK);
128: assertEquals(ExternalLinkImpl.class, externalLink.getClass());
129: assertSame(manager, externalLink.getLifeCycleManager());
130: }
131:
132: public void testCreateObjectExtrinsicObject() throws JAXRException {
133: try {
134: manager.createObject(LifeCycleManager.EXTRINSIC_OBJECT);
135: fail();
136: } catch (UnsupportedCapabilityException e) {
137: // OK
138: }
139: }
140:
141: public void testCreateObjectInternationalString()
142: throws JAXRException {
143: assertEquals(InternationalStringImpl.class, manager
144: .createObject(LifeCycleManager.INTERNATIONAL_STRING)
145: .getClass());
146: }
147:
148: public void testCreateObjectKey() throws JAXRException {
149: assertEquals(KeyImpl.class, manager.createObject(
150: LifeCycleManager.KEY).getClass());
151: }
152:
153: public void testCreateObjectLocalizedString() throws JAXRException {
154: assertEquals(LocalizedStringImpl.class, manager.createObject(
155: LifeCycleManager.LOCALIZED_STRING).getClass());
156: }
157:
158: public void testCreateObjectOrganization() throws JAXRException {
159: Organization organization = (Organization) manager
160: .createObject(LifeCycleManager.ORGANIZATION);
161: assertEquals(OrganizationImpl.class, organization.getClass());
162: assertSame(manager, organization.getLifeCycleManager());
163: }
164:
165: public void testCreateObjectPersonName() throws JAXRException {
166:
167: PersonName pn = (PersonName) manager
168: .createObject(LifeCycleManager.PERSON_NAME);
169: assertEquals(PersonNameImpl.class, pn.getClass());
170: }
171:
172: public void testCreateObjectPostalAddress() throws JAXRException {
173: assertEquals(PostalAddressImpl.class, manager.createObject(
174: LifeCycleManager.POSTAL_ADDRESS).getClass());
175: }
176:
177: public void testCreateObjectRegistryEntry() throws JAXRException {
178: try {
179: manager.createObject(LifeCycleManager.REGISTRY_ENTRY);
180: fail();
181: } catch (UnsupportedCapabilityException e) {
182: // OK
183: }
184: }
185:
186: public void testCreateObjectRegistryPackage() throws JAXRException {
187: try {
188: manager.createObject(LifeCycleManager.REGISTRY_PACKAGE);
189: fail();
190: } catch (UnsupportedCapabilityException e) {
191: // OK
192: }
193:
194: try {
195: manager.createRegistryPackage(new InternationalStringImpl(
196: "Foo"));
197: fail();
198: } catch (UnsupportedCapabilityException e) {
199: // OK
200: }
201:
202: try {
203: manager.createRegistryPackage("Foo");
204: fail();
205: } catch (UnsupportedCapabilityException e) {
206: // OK
207: }
208:
209: }
210:
211: public void testCreateObjectService() throws JAXRException {
212: Service service = (Service) manager
213: .createObject(LifeCycleManager.SERVICE);
214: assertEquals(ServiceImpl.class, service.getClass());
215: assertSame(manager, service.getLifeCycleManager());
216: }
217:
218: public void testCreateObjectServiceBinding() throws JAXRException {
219: ServiceBinding service = (ServiceBinding) manager
220: .createObject(LifeCycleManager.SERVICE_BINDING);
221: assertEquals(ServiceBindingImpl.class, service.getClass());
222: assertSame(manager, service.getLifeCycleManager());
223: }
224:
225: public void testCreateObjectSlot() throws JAXRException {
226: assertEquals(SlotImpl.class, manager.createObject(
227: LifeCycleManager.SLOT).getClass());
228: }
229:
230: public void testCreateObjectSpecificationLink()
231: throws JAXRException {
232: assertEquals(SpecificationLinkImpl.class, manager.createObject(
233: LifeCycleManager.SPECIFICATION_LINK).getClass());
234: }
235:
236: public void testCreateObjectTelephoneNumber() throws JAXRException {
237: assertEquals(TelephoneNumberImpl.class, manager.createObject(
238: LifeCycleManager.TELEPHONE_NUMBER).getClass());
239: }
240:
241: public void testCreateObjectUser() throws JAXRException {
242: User user = (User) manager.createObject(LifeCycleManager.USER);
243: assertEquals(UserImpl.class, user.getClass());
244: assertSame(manager, user.getLifeCycleManager());
245: }
246:
247: public void testCreateObjectInvalid() throws JAXRException {
248: try {
249: manager.createObject("Foo");
250: fail();
251: } catch (InvalidRequestException e) {
252: // OK
253: }
254: }
255:
256: public void testDeprecateObjects() throws JAXRException {
257: try {
258: manager.deprecateObjects(new ArrayList<Key>());
259: fail();
260: } catch (UnsupportedCapabilityException e) {
261: // OK
262: }
263: }
264:
265: public void testUnDeprecateObjects() throws JAXRException {
266: try {
267: manager.unDeprecateObjects(new ArrayList<Key>());
268: fail();
269: } catch (UnsupportedCapabilityException e) {
270: // OK
271: }
272: }
273:
274: protected class ConcreteLifeCycleManager extends
275: LifeCycleManagerImpl {
276:
277: public ConcreteLifeCycleManager(RegistryService rs) {
278: super (rs);
279: }
280:
281: public BulkResponse saveObjects(Collection objects)
282: throws JAXRException {
283: return new BulkResponseImpl();
284: }
285:
286: public BulkResponse deleteObjects(Collection keys,
287: String objectType) throws JAXRException {
288: return new BulkResponseImpl();
289: }
290: }
291:
292: protected void setUp() throws Exception {
293: super .setUp();
294: manager = new ConcreteLifeCycleManager(new RegistryServiceImpl(
295: null, null, -1));
296: }
297: }
|