KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > registry > ConnectionFactoryTest


1 /**
2  *
3  * Copyright 2004 Jeremy Boynes
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 javax.xml.registry;
18
19 import java.util.Collection;
20 import java.util.Properties;
21
22 import junit.framework.TestCase;
23 import org.apache.ws.scout.registry.ConnectionFactoryImpl;
24
25 /**
26  * @version $Revision$ $Date$
27  */

28 public class ConnectionFactoryTest extends TestCase {
29     private static final String CONNECTIONFACTORYCLASS_PROPERTY = "javax.xml.registry.ConnectionFactoryClass";
30
31     private Properties originalProperties;
32     private Properties props;
33
34     public void testNewInstanceWithDefault() throws JAXRException {
35         ConnectionFactory factory = ConnectionFactory.newInstance();
36         assertEquals(ConnectionFactoryImpl.class, factory.getClass());
37     }
38
39     public void testNewInstanceWithClass() throws JAXRException {
40         System.setProperty(CONNECTIONFACTORYCLASS_PROPERTY, MockFactory.class.getName());
41         ConnectionFactory factory = ConnectionFactory.newInstance();
42         assertEquals(MockFactory.class, factory.getClass());
43     }
44
45     protected void setUp() throws Exception {
46         super.setUp();
47         originalProperties = System.getProperties();
48         props = new Properties(originalProperties);
49         props.remove(CONNECTIONFACTORYCLASS_PROPERTY);
50         System.setProperties(props);
51     }
52
53     protected void tearDown() throws Exception {
54         System.setProperties(originalProperties);
55         super.tearDown();
56     }
57
58     public static class MockFactory extends ConnectionFactory {
59         public Connection createConnection() throws JAXRException {
60             throw new UnsupportedOperationException();
61         }
62
63         public FederatedConnection createFederatedConnection(Collection connections) throws JAXRException {
64             throw new UnsupportedOperationException();
65         }
66
67         public Properties getProperties() throws JAXRException {
68             throw new UnsupportedOperationException();
69         }
70
71         public void setProperties(Properties properties) throws JAXRException {
72             throw new UnsupportedOperationException();
73         }
74     }
75 }
76
Popular Tags