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.Properties;
019:
020: import javax.xml.registry.Connection;
021: import javax.xml.registry.ConnectionFactory;
022: import javax.xml.registry.InvalidRequestException;
023: import javax.xml.registry.JAXRException;
024: import javax.xml.registry.UnsupportedCapabilityException;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * @version $Revision$ $Date$
030: */
031: public class ConnectionFactoryTest extends TestCase {
032: private ConnectionFactoryImpl factory;
033:
034: public void testNewInstanceWithDefault() throws JAXRException {
035: Properties props = System.getProperties();
036: props.remove("javax.xml.registry.ConnectionFactoryClass");
037: ConnectionFactory factory = ConnectionFactory.newInstance();
038: assertEquals(ConnectionFactoryImpl.class, factory.getClass());
039: }
040:
041: public void testNewInstanceWithProperty() throws JAXRException {
042: System.setProperty("javax.xml.registry.ConnectionFactoryClass",
043: ConnectionFactoryImpl.class.getName());
044: ConnectionFactory factory = ConnectionFactory.newInstance();
045: assertEquals(ConnectionFactoryImpl.class, factory.getClass());
046: }
047:
048: public void testSetQueryManagerURL() {
049: String url = "http://localhost";
050: factory.setQueryManagerURL(url);
051: assertEquals(url, factory.getQueryManagerURL());
052: assertEquals(url, factory.getProperties().getProperty(
053: "javax.xml.registry.queryManagerURL"));
054: }
055:
056: public void testSetLifeCycleURL() {
057: String url = "http://localhost";
058: factory.setLifeCycleManagerURL(url);
059: assertEquals(url, factory.getLifeCycleManagerURL());
060: assertEquals(url, factory.getProperties().getProperty(
061: "javax.xml.registry.lifeCycleManagerURL"));
062: }
063:
064: public void testSetSemanticEquivalences() {
065: String urns = "urn:uuid:0a1324f7-6d4a-4d73-a088-9ab1d00c9a91,urn:uuid:23a5feac-26b9-4525-82fc-997885a0e6a2"
066: + '|'
067: + "urn:uuid:1acf6ed2-cd6e-4797-aad8-8937a3cff88b,urn:uuid:152d6f28-cb56-4e5d-9f55-96b132def0e4";
068: factory.setSemanticEquivalences(urns);
069: assertEquals(urns, factory.getSemanticEquivalences());
070: assertEquals(urns, factory.getProperties().getProperty(
071: "javax.xml.registry.semanticEquivalences"));
072: }
073:
074: public void testSetAuthenticationMethod() {
075: String method = "HTTP_BASIC";
076: factory.setAuthenticationMethod(method);
077: assertEquals(method, factory.getAuthenticationMethod());
078: assertEquals(method, factory.getProperties().getProperty(
079: "javax.xml.registry.security.authenticationMethod"));
080: }
081:
082: public void testSetPostalAddressScheme() {
083: String scheme = "User Defined";
084: factory.setPostalAddressScheme(scheme);
085: assertEquals(scheme, factory.getPostalAddressScheme());
086: assertEquals(scheme, factory.getProperties().getProperty(
087: "javax.xml.registry.postalAddressScheme"));
088: }
089:
090: public void testMaxRows() {
091: Integer maxRows = new Integer(1234);
092: factory.setMaxRows(maxRows);
093: assertEquals(maxRows, factory.getMaxRows());
094: assertEquals(maxRows.toString(), factory.getProperties()
095: .getProperty("javax.xml.registry.uddi.maxRows"));
096: }
097:
098: public void testNullQueryManagerURL() {
099: factory.setQueryManagerURL(null);
100: assertFalse(factory.getProperties().containsKey(
101: "javax.xml.registry.queryManagerURL"));
102: }
103:
104: public void testNullLifeCycleManagerURL() {
105: factory.setLifeCycleManagerURL(null);
106: assertFalse(factory.getProperties().containsKey(
107: "javax.xml.registry.lifeCycleManagerURL"));
108: }
109:
110: public void testNullSemanticEquivalences() {
111: factory.setSemanticEquivalences(null);
112: assertFalse(factory.getProperties().containsKey(
113: "javax.xml.registry.semanticEquivalences"));
114: }
115:
116: public void testNullAuthenticationMethod() {
117: factory.setAuthenticationMethod(null);
118: assertFalse(factory.getProperties().containsKey(
119: "javax.xml.registry.security.authenticationMethod"));
120: }
121:
122: public void testNullMaxRows() {
123: factory.setMaxRows(null);
124: assertFalse(factory.getProperties().containsKey(
125: "javax.xml.registry.uddi.maxRows"));
126: }
127:
128: public void testNullPostalAddressScheme() {
129: factory.setPostalAddressScheme(null);
130: assertFalse(factory.getProperties().containsKey(
131: "javax.xml.registry.postalAddressScheme"));
132: }
133:
134: public void testCreateConnection() throws JAXRException {
135: factory.setQueryManagerURL("http://localhost");
136: factory.setLifeCycleManagerURL("http://localhost");
137: Connection c = factory.createConnection();
138: try {
139: assertEquals(ConnectionImpl.class, c.getClass());
140: } finally {
141: c.close();
142: }
143: }
144:
145: public void testCreateConnectionWithNullLifeCycleURL()
146: throws JAXRException {
147: factory.setQueryManagerURL("http://localhost");
148: factory.setLifeCycleManagerURL(null);
149: Connection c = factory.createConnection();
150: try {
151: assertEquals(ConnectionImpl.class, c.getClass());
152: } finally {
153: c.close();
154: }
155: }
156:
157: // KS: This is no longer invalid..
158: //
159: // public void testCreateConnectionWithInvalidQueryURL() {
160: // factory.setQueryManagerURL("foo:bar");
161: // try {
162: // factory.createConnection();
163: // fail("did not reject invalid URL");
164: // } catch (InvalidRequestException e) {
165: // // OK
166: // } catch (JAXRException e) {
167: // fail("threw JAXRException");
168: // }
169: // }
170: //
171: // public void testCreateConnectionWithInvalidLifeCycleURL() {
172: // factory.setQueryManagerURL("http://localhost");
173: // factory.setLifeCycleManagerURL("foo:bar");
174: // try {
175: // factory.createConnection();
176: // fail("did not reject invalid URL");
177: // } catch (InvalidRequestException e) {
178: // // OK
179: // } catch (JAXRException e) {
180: // fail("threw JAXRException");
181: // }
182: // }
183:
184: public void testCreateConnectionWithNullQueryURL() {
185: try {
186: factory.createConnection();
187: fail("did not reject invalid URL");
188: } catch (InvalidRequestException e) {
189: // OK
190: } catch (JAXRException e) {
191: fail("threw JAXRException");
192: }
193: }
194:
195: public void testCreateFederatedConnection() {
196: try {
197: factory.createFederatedConnection(null);
198: fail("did not get expected Exception");
199: } catch (UnsupportedCapabilityException e) {
200: // OK
201: } catch (JAXRException e) {
202: fail("threw JAXRException");
203: }
204: }
205:
206: protected void setUp() throws Exception {
207: super .setUp();
208: factory = new ConnectionFactoryImpl();
209: }
210:
211: protected void tearDown() throws Exception {
212: factory = null;
213: super.tearDown();
214: }
215: }
|