This project has retired. For details please refer to its
Attic page.
ConnectionFactoryTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ws.scout.registry;
18
19 import java.util.Properties;
20
21 import javax.xml.registry.Connection;
22 import javax.xml.registry.ConnectionFactory;
23 import javax.xml.registry.InvalidRequestException;
24 import javax.xml.registry.JAXRException;
25 import javax.xml.registry.UnsupportedCapabilityException;
26
27 import junit.framework.TestCase;
28
29
30
31
32 public class ConnectionFactoryTest extends TestCase {
33 private ConnectionFactoryImpl factory;
34
35 public void testNewInstanceWithDefault() throws JAXRException {
36 Properties props = System.getProperties();
37 props.remove("javax.xml.registry.ConnectionFactoryClass");
38 ConnectionFactory factory = ConnectionFactory.newInstance();
39 assertEquals(ConnectionFactoryImpl.class, factory.getClass());
40 }
41
42 public void testNewInstanceWithProperty() throws JAXRException {
43 System.setProperty("javax.xml.registry.ConnectionFactoryClass", ConnectionFactoryImpl.class.getName());
44 ConnectionFactory factory = ConnectionFactory.newInstance();
45 assertEquals(ConnectionFactoryImpl.class, factory.getClass());
46 }
47
48 public void testSetQueryManagerURL() {
49 String url = "http://localhost";
50 Properties properties = new Properties();
51 properties.setProperty(ConnectionFactoryImpl.QUERYMANAGER_PROPERTY, url);
52 factory.setProperties(properties);
53 assertEquals(url, factory.getProperties().getProperty("javax.xml.registry.queryManagerURL"));
54 }
55
56 public void testSetLifeCycleURL() {
57 String url = "http://localhost";
58 Properties properties = new Properties();
59 properties.setProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY, url);
60 factory.setProperties(properties);
61 assertEquals(url, factory.getProperties().getProperty("javax.xml.registry.lifeCycleManagerURL"));
62 }
63
64 public void testSetSemanticEquivalences() {
65 String urns =
66 "urn:uuid:0a1324f7-6d4a-4d73-a088-9ab1d00c9a91,urn:uuid:23a5feac-26b9-4525-82fc-997885a0e6a2" + '|' +
67 "urn:uuid:1acf6ed2-cd6e-4797-aad8-8937a3cff88b,urn:uuid:152d6f28-cb56-4e5d-9f55-96b132def0e4";
68 Properties properties = new Properties();
69 properties.setProperty(ConnectionFactoryImpl.SEMANTICEQUIVALENCES_PROPERTY, urns);
70 factory.setProperties(properties);
71 assertEquals(urns, factory.getProperties().getProperty("javax.xml.registry.semanticEquivalences"));
72 }
73
74 public void testSetAuthenticationMethod() {
75 String method = "HTTP_BASIC";
76 Properties properties = new Properties();
77 properties.setProperty(ConnectionFactoryImpl.AUTHENTICATIONMETHOD_PROPERTY, method);
78 factory.setProperties(properties);
79 assertEquals(method, factory.getProperties().getProperty("javax.xml.registry.security.authenticationMethod"));
80 }
81
82 public void testSetPostalAddressScheme() {
83 String scheme = "User Defined";
84 Properties properties = new Properties();
85 properties.setProperty(ConnectionFactoryImpl.POSTALADDRESSSCHEME_PROPERTY, scheme);
86 factory.setProperties(properties);
87 assertEquals(scheme, factory.getProperties().getProperty("javax.xml.registry.postalAddressScheme"));
88 }
89
90 public void testMaxRows() {
91 Integer maxRows = 1234;
92 Properties properties = new Properties();
93 properties.setProperty(ConnectionFactoryImpl.MAXROWS_PROPERTY, String.valueOf(maxRows));
94 factory.setProperties(properties);
95 assertEquals(maxRows.toString(), factory.getProperties().getProperty("javax.xml.registry.uddi.maxRows"));
96 }
97
98 public void testNullQueryManagerURL() {
99 factory.setProperties(null);
100 assertFalse(factory.getProperties().containsKey("javax.xml.registry.queryManagerURL"));
101 }
102
103 public void testNullLifeCycleManagerURL() {
104 factory.setProperties(null);
105 assertFalse(factory.getProperties().containsKey("javax.xml.registry.lifeCycleManagerURL"));
106 }
107
108 public void testNullSemanticEquivalences() {
109 factory.setProperties(null);
110 assertFalse(factory.getProperties().containsKey("javax.xml.registry.semanticEquivalences"));
111 }
112
113 public void testNullAuthenticationMethod() {
114 factory.setProperties(null);
115 assertFalse(factory.getProperties().containsKey("javax.xml.registry.security.authenticationMethod"));
116 }
117
118 public void testNullMaxRows() {
119 factory.setProperties(null);
120 assertFalse(factory.getProperties().containsKey("javax.xml.registry.uddi.maxRows"));
121 }
122
123 public void testNullPostalAddressScheme() {
124 factory.setProperties(null);
125 assertFalse(factory.getProperties().containsKey("javax.xml.registry.postalAddressScheme"));
126 }
127
128 public void testCreateConnection() throws JAXRException {
129 Properties properties = new Properties();
130 properties.setProperty(ConnectionFactoryImpl.QUERYMANAGER_PROPERTY, "http://localhost");
131 properties.setProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY , "http://localhost");
132 factory.setProperties(properties);
133 Connection c = factory.createConnection();
134 try {
135 assertEquals(ConnectionImpl.class, c.getClass());
136 } finally {
137 c.close();
138 }
139 }
140
141 public void testCreateConnectionWithNullLifeCycleURL() throws JAXRException {
142 Properties properties = new Properties();
143 properties.setProperty(ConnectionFactoryImpl.QUERYMANAGER_PROPERTY, "http://localhost");
144 Connection c = null;
145 try {
146 factory.setProperties(properties);
147 c = factory.createConnection();
148 assertEquals(ConnectionImpl.class, c.getClass());
149 } catch (Exception e) {
150 fail("it's ok to have a null lifeCycleURL");
151 } finally {
152 if (c!=null) c.close();
153 }
154 }
155
156 public void testCreateConnectionWithNullQueryURL() {
157 try {
158 factory.createConnection();
159 fail("should have thrown an InvalidRequestException");
160 } catch (InvalidRequestException ire) {
161
162 } catch (Exception e) {
163 fail("threw Exception");
164 }
165 }
166
167 public void testCreateFederatedConnection() {
168 try {
169 factory.createFederatedConnection(null);
170 fail("did not get expected Exception");
171 } catch (UnsupportedCapabilityException e) {
172
173 } catch (JAXRException e) {
174 fail("threw JAXRException");
175 }
176 }
177
178 protected void setUp() throws Exception {
179 super.setUp();
180 factory = new ConnectionFactoryImpl();
181 }
182
183 protected void tearDown() throws Exception {
184 factory = null;
185 super.tearDown();
186 }
187 }