This project has retired. For details please refer to its Attic page.
LifeCycleManagerTest xref
View Javadoc
1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.ws.scout.registry;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  import javax.xml.registry.BulkResponse;
23  import javax.xml.registry.InvalidRequestException;
24  import javax.xml.registry.JAXRException;
25  import javax.xml.registry.LifeCycleManager;
26  import javax.xml.registry.RegistryService;
27  import javax.xml.registry.UnsupportedCapabilityException;
28  import javax.xml.registry.infomodel.Association;
29  import javax.xml.registry.infomodel.Classification;
30  import javax.xml.registry.infomodel.ClassificationScheme;
31  import javax.xml.registry.infomodel.Concept;
32  import javax.xml.registry.infomodel.EmailAddress;
33  import javax.xml.registry.infomodel.ExternalIdentifier;
34  import javax.xml.registry.infomodel.ExternalLink;
35  import javax.xml.registry.infomodel.Key;
36  import javax.xml.registry.infomodel.Organization;
37  import javax.xml.registry.infomodel.PersonName;
38  import javax.xml.registry.infomodel.Service;
39  import javax.xml.registry.infomodel.ServiceBinding;
40  import javax.xml.registry.infomodel.User;
41  
42  import junit.framework.TestCase;
43  
44  import org.apache.ws.scout.registry.infomodel.AssociationImpl;
45  import org.apache.ws.scout.registry.infomodel.ClassificationImpl;
46  import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
47  import org.apache.ws.scout.registry.infomodel.ConceptImpl;
48  import org.apache.ws.scout.registry.infomodel.EmailAddressImpl;
49  import org.apache.ws.scout.registry.infomodel.ExternalIdentifierImpl;
50  import org.apache.ws.scout.registry.infomodel.ExternalLinkImpl;
51  import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
52  import org.apache.ws.scout.registry.infomodel.KeyImpl;
53  import org.apache.ws.scout.registry.infomodel.LocalizedStringImpl;
54  import org.apache.ws.scout.registry.infomodel.OrganizationImpl;
55  import org.apache.ws.scout.registry.infomodel.PersonNameImpl;
56  import org.apache.ws.scout.registry.infomodel.PostalAddressImpl;
57  import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
58  import org.apache.ws.scout.registry.infomodel.ServiceImpl;
59  import org.apache.ws.scout.registry.infomodel.SlotImpl;
60  import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
61  import org.apache.ws.scout.registry.infomodel.TelephoneNumberImpl;
62  import org.apache.ws.scout.registry.infomodel.UserImpl;
63  
64  /**
65   *
66   * @version $Rev$ $Date$ $Author$
67   */
68  public class LifeCycleManagerTest extends TestCase {
69      private LifeCycleManager manager;
70  
71      public void testCreateObjectAssociation() throws JAXRException {
72          Association assoc = (Association) manager.createObject(LifeCycleManager.ASSOCIATION);
73          assertEquals(AssociationImpl.class, assoc.getClass());
74          assertSame(manager, assoc.getLifeCycleManager());
75      }
76  
77      public void testCreateObjectAuditableEvent() throws JAXRException {
78          try {
79              manager.createObject(LifeCycleManager.AUDITABLE_EVENT);
80              fail();
81          } catch (UnsupportedCapabilityException e) {
82              // OK
83          }
84      }
85  
86      public void testCreateObjectClassification() throws JAXRException {
87          Classification classification = (Classification) manager.createObject(LifeCycleManager.CLASSIFICATION);
88          assertEquals(ClassificationImpl.class, classification.getClass());
89          assertSame(manager, classification.getLifeCycleManager());
90      }
91  
92      public void testCreateObjectClassificationScheme() throws JAXRException {
93          ClassificationScheme classificationScheme = (ClassificationScheme) manager.createObject(LifeCycleManager.CLASSIFICATION_SCHEME);
94          assertEquals(ClassificationSchemeImpl.class, classificationScheme.getClass());
95          assertSame(manager, classificationScheme.getLifeCycleManager());
96      }
97  
98      public void testCreateObjectConcept() throws JAXRException {
99          Concept concept = (Concept) manager.createObject(LifeCycleManager.CONCEPT);
100         assertEquals(ConceptImpl.class, concept.getClass());
101         assertSame(manager, concept.getLifeCycleManager());
102     }
103 
104     public void testCreateObjectEmailAddress() throws JAXRException {
105         assertEquals(EmailAddressImpl.class, ((EmailAddress) manager.createObject(LifeCycleManager.EMAIL_ADDRESS)).getClass());
106     }
107 
108     public void testCreateObjectExternalIdentifier() throws JAXRException {
109         ExternalIdentifier externalIdentifier = ((ExternalIdentifier) manager.createObject(LifeCycleManager.EXTERNAL_IDENTIFIER));
110         assertEquals(ExternalIdentifierImpl.class, externalIdentifier.getClass());
111         assertSame(manager, externalIdentifier.getLifeCycleManager());
112     }
113 
114     public void testCreateObjectExternalLink() throws JAXRException {
115         ExternalLink externalLink = (ExternalLink) manager.createObject(LifeCycleManager.EXTERNAL_LINK);
116         assertEquals(ExternalLinkImpl.class, externalLink.getClass());
117         assertSame(manager, externalLink.getLifeCycleManager());
118     }
119 
120     public void testCreateObjectExtrinsicObject() throws JAXRException {
121         try {
122             manager.createObject(LifeCycleManager.EXTRINSIC_OBJECT);
123             fail();
124         } catch (UnsupportedCapabilityException e) {
125             // OK
126         }
127     }
128 
129     public void testCreateObjectInternationalString() throws JAXRException {
130         assertEquals(InternationalStringImpl.class, manager.createObject(LifeCycleManager.INTERNATIONAL_STRING).getClass());
131     }
132 
133     public void testCreateObjectKey() throws JAXRException {
134         assertEquals(KeyImpl.class, manager.createObject(LifeCycleManager.KEY).getClass());
135     }
136 
137     public void testCreateObjectLocalizedString() throws JAXRException {
138         assertEquals(LocalizedStringImpl.class, manager.createObject(LifeCycleManager.LOCALIZED_STRING).getClass());
139     }
140 
141     public void testCreateObjectOrganization() throws JAXRException {
142         Organization organization = (Organization) manager.createObject(LifeCycleManager.ORGANIZATION);
143         assertEquals(OrganizationImpl.class, organization.getClass());
144         assertSame(manager, organization.getLifeCycleManager());
145     }
146 
147     public void testCreateObjectPersonName() throws JAXRException {
148 
149         PersonName pn = (PersonName) manager.createObject(LifeCycleManager.PERSON_NAME);
150         assertEquals(PersonNameImpl.class, pn.getClass());
151     }
152 
153     public void testCreateObjectPostalAddress() throws JAXRException {
154         assertEquals(PostalAddressImpl.class, manager.createObject(LifeCycleManager.POSTAL_ADDRESS).getClass());
155     }
156 
157     public void testCreateObjectRegistryEntry() throws JAXRException {
158         try {
159             manager.createObject(LifeCycleManager.REGISTRY_ENTRY);
160             fail();
161         } catch (UnsupportedCapabilityException e) {
162             // OK
163         }
164     }
165 
166     public void testCreateObjectRegistryPackage() throws JAXRException {
167         try {
168             manager.createObject(LifeCycleManager.REGISTRY_PACKAGE);
169             fail();
170         } catch (UnsupportedCapabilityException e) {
171             // OK
172         }
173 
174         try {
175             manager.createRegistryPackage(new InternationalStringImpl("Foo"));
176             fail();
177         } catch (UnsupportedCapabilityException e) {
178             // OK
179         }
180 
181         try {
182             manager.createRegistryPackage("Foo");
183             fail();
184         } catch (UnsupportedCapabilityException e) {
185             // OK
186         }
187 
188     }
189 
190     public void testCreateObjectService() throws JAXRException {
191         Service service = (Service) manager.createObject(LifeCycleManager.SERVICE);
192         assertEquals(ServiceImpl.class, service.getClass());
193         assertSame(manager, service.getLifeCycleManager());
194     }
195 
196     public void testCreateObjectServiceBinding() throws JAXRException {
197         ServiceBinding service = (ServiceBinding) manager.createObject(LifeCycleManager.SERVICE_BINDING);
198         assertEquals(ServiceBindingImpl.class, service.getClass());
199         assertSame(manager, service.getLifeCycleManager());
200     }
201 
202     public void testCreateObjectSlot() throws JAXRException {
203         assertEquals(SlotImpl.class, manager.createObject(LifeCycleManager.SLOT).getClass());
204     }
205 
206     public void testCreateObjectSpecificationLink() throws JAXRException {
207         assertEquals(SpecificationLinkImpl.class, manager.createObject(LifeCycleManager.SPECIFICATION_LINK).getClass());
208     }
209 
210     public void testCreateObjectTelephoneNumber() throws JAXRException {
211         assertEquals(TelephoneNumberImpl.class, manager.createObject(LifeCycleManager.TELEPHONE_NUMBER).getClass());
212     }
213 
214     public void testCreateObjectUser() throws JAXRException {
215         User user = (User) manager.createObject(LifeCycleManager.USER);
216         assertEquals(UserImpl.class, user.getClass());
217         assertSame(manager, user.getLifeCycleManager());
218     }
219 
220     public void testCreateObjectInvalid() throws JAXRException {
221         try {
222             manager.createObject("Foo");
223             fail();
224         } catch (InvalidRequestException e) {
225             // OK
226         }
227     }
228 
229     public void testDeprecateObjects() throws JAXRException {
230         try {
231             manager.deprecateObjects(new ArrayList<Key>());
232             fail();
233         } catch (UnsupportedCapabilityException e) {
234             // OK
235         }
236     }
237 
238     public void testUnDeprecateObjects() throws JAXRException {
239         try {
240             manager.unDeprecateObjects(new ArrayList<Key>());
241             fail();
242         } catch (UnsupportedCapabilityException e) {
243             // OK
244         }
245     }
246 
247     protected class ConcreteLifeCycleManager extends LifeCycleManagerImpl {
248 
249         public ConcreteLifeCycleManager(RegistryService rs) {
250             super(rs);
251         }
252 
253         public BulkResponse saveObjects(Collection objects) throws JAXRException {
254             return new BulkResponseImpl();
255         }
256 
257         public BulkResponse deleteObjects(Collection keys, String objectType) throws JAXRException {
258             return new BulkResponseImpl();
259         }
260     }
261     protected void setUp() throws Exception {
262         super.setUp();
263         manager = new ConcreteLifeCycleManager(new RegistryServiceImpl(null, null, -1, "3.0"));
264     }
265 }