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;
017:
018: import java.net.PasswordAuthentication;
019: import java.util.HashSet;
020: import java.util.Properties;
021: import java.util.Set;
022:
023: import javax.xml.registry.BusinessLifeCycleManager;
024: import javax.xml.registry.BusinessQueryManager;
025: import javax.xml.registry.Connection;
026: import javax.xml.registry.ConnectionFactory;
027: import javax.xml.registry.JAXRException;
028:
029: /**
030: * Test to check Jaxr Publish
031: * Open source UDDI Browser <http://www.uddibrowser.org>
032: * can be used to check your results
033: * @author <mailto:kurt.stam@jboss.com>Kurt Stam
034: * @since Sept 21, 2006
035: */
036: public class BaseTestCase {
037: protected Connection connection;
038: protected BusinessLifeCycleManager blm;
039: protected BusinessQueryManager bqm;
040:
041: //Set some default values
042: protected String userid = System.getProperty("uddi.test.uid") == null ? "jdoe"
043: : System.getProperty("uddi.test.uid");
044: protected String passwd = System.getProperty("uddi.test.pass") == null ? "password"
045: : System.getProperty("uddi.test.pass");
046: protected int maxRows = 100;
047:
048: /**
049: * Reads scout properties, and creates a connection using these properties.
050: *
051: */
052: public void setUp() {
053: System.out
054: .println("************************************************************");
055: try {
056: Properties scoutProperties = new Properties();
057: scoutProperties.load(getClass().getResourceAsStream(
058: "/scout.properties"));
059:
060: Properties juddiProperties = new Properties();
061: juddiProperties.load(getClass().getResourceAsStream(
062: "/juddi.properties"));
063:
064: final String INQUERY_URI = scoutProperties
065: .getProperty("inquery.uri");
066: final String PUBLISH_URI = scoutProperties
067: .getProperty("publish.uri");
068: final String TRANSPORT_CLASS = scoutProperties
069: .getProperty("transport.class");
070:
071: if (scoutProperties.getProperty("userid") != null) {
072: userid = scoutProperties.getProperty("userid");
073: }
074: if (scoutProperties.getProperty("password") != null) {
075: passwd = scoutProperties.getProperty("password");
076: }
077:
078: // Define connection configuration properties
079: // To query, you need only the query URL
080: Properties props = new Properties();
081:
082: props
083: .setProperty(
084: "javax.xml.registry.queryManagerURL",
085: System
086: .getProperty("javax.xml.registry.queryManagerURL") == null ? INQUERY_URI
087: : System
088: .getProperty("javax.xml.registry.queryManagerURL"));
089: props
090: .setProperty(
091: "javax.xml.registry.lifeCycleManagerURL",
092: System
093: .getProperty("javax.xml.registry.lifeCycleManagerURL") == null ? PUBLISH_URI
094: : System
095: .getProperty("javax.xml.registry.lifeCycleManagerURL"));
096: props
097: .setProperty(
098: "javax.xml.registry.factoryFactoryClass",
099: "org.apache.ws.scout.? it isregistry.ConnectionFactoryImpl");
100: props.setProperty("scout.proxy.transportClass",
101: TRANSPORT_CLASS);
102: props.setProperty("javax.xml.registry.uddi.maxRows", String
103: .valueOf(maxRows));
104:
105: // Create the connection, passing it the configuration properties
106: ConnectionFactory factory = ConnectionFactory.newInstance();
107: factory.setProperties(props);
108: connection = factory.createConnection();
109: } catch (Exception e) {
110: e.printStackTrace();
111: }
112: }
113:
114: /**
115: * Closes down the connection to the registry.
116: *
117: */
118: public void tearDown() {
119: try {
120: if (connection != null)
121: connection.close();
122:
123: } catch (Exception e) {
124:
125: }
126: }
127:
128: /**
129: * Does authentication with the uddi registry
130: */
131: public void login() {
132: PasswordAuthentication passwdAuth = new PasswordAuthentication(
133: userid, passwd.toCharArray());
134: Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
135: creds.add(passwdAuth);
136:
137: try {
138: connection.setCredentials(creds);
139: } catch (JAXRException e) {
140: e.printStackTrace();
141: }
142: }
143:
144: }
|