This project has retired. For details please refer to its Attic page.
BaseTestCase 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;
18  
19  import java.net.PasswordAuthentication;
20  import java.util.HashSet;
21  import java.util.Map;
22  import java.util.Properties;
23  import java.util.Set;
24  
25  import javax.xml.registry.BusinessLifeCycleManager;
26  import javax.xml.registry.BusinessQueryManager;
27  import javax.xml.registry.Connection;
28  import javax.xml.registry.ConnectionFactory;
29  import javax.xml.registry.JAXRException;
30  
31  import org.apache.ws.scout.registry.RegistryImpl;
32  /**
33   * Test to check Jaxr Publish
34   * Open source UDDI Browser  <http://www.uddibrowser.org>
35   * can be used to check your results
36   * @author <mailto:kurt.stam@jboss.com>Kurt Stam
37   * @since Sept 21, 2006
38   */
39  public class BaseTestCase
40  {	
41      protected Connection connection;
42      protected Connection connection2;
43      
44      protected BusinessLifeCycleManager blm;
45      protected BusinessQueryManager bqm;
46  
47      //Set some default values
48  	protected String uddiversion = null;
49   
50      protected String userid = System.getProperty("uddi.test.uid")  == null ? "jdoe"     : System.getProperty("uddi.test.uid");
51      protected String passwd = System.getProperty("uddi.test.pass") == null ? "password" : System.getProperty("uddi.test.pass");
52      
53      protected String userid2 = System.getProperty("uddi.test.uid2")  == null ? "jdoe2"     : System.getProperty("uddi.test.uid2");
54      protected String passwd2 = System.getProperty("uddi.test.pass2") == null ? "password2" : System.getProperty("uddi.test.pass2");
55      
56      protected int maxRows   = 100;
57  
58      /**
59       * Reads scout properties, and creates a connection using these properties.
60       *
61       */
62      public void setUp()
63      {
64          System.out.println("************************************************************");
65          try
66          {
67          	String envUDDIVersion =  System.getenv("uddi.version");
68          	if (envUDDIVersion==null) envUDDIVersion = "2";
69          	uddiversion = envUDDIVersion + ".0";
70          	String propertiesFile = "/scoutv" + envUDDIVersion + ".properties";
71          	
72          	System.out.println("Reading Scout Properties from: " + propertiesFile);
73          	
74              Properties scoutProperties = new Properties();
75              scoutProperties.load(getClass().getResourceAsStream(propertiesFile));
76            
77              if (scoutProperties.getProperty("userid")!=null) {
78                  userid = scoutProperties.getProperty("userid");
79              }
80              if (scoutProperties.getProperty("password")!=null) {
81                  passwd = scoutProperties.getProperty("password");
82              }
83              
84  //            if (scoutProperties.getProperty("userid2")!=null) {
85  //                userid = scoutProperties.getProperty("userid2");
86  //            }
87  //            if (scoutProperties.getProperty("password2")!=null) {
88  //                passwd = scoutProperties.getProperty("password2");
89  //            }
90  
91              // Create the connection, passing it the configuration properties
92              ConnectionFactory factory = ConnectionFactory.newInstance();
93              factory.setProperties(scoutProperties);
94              connection = factory.createConnection();
95              connection2 = factory.createConnection();
96          } catch (Exception e)
97          {
98              e.printStackTrace();
99          }
100     }
101     /**
102      * Closes down the connection to the registry.
103      *
104      */
105     public void tearDown()
106     {
107     	
108         try
109         {
110             if (connection != null)
111                 connection.close();
112             
113         } catch (Exception e)
114         {
115 
116         }
117     }
118     
119     /**
120      * Does authentication with the uddi registry
121      */
122     public void login()
123     {
124         PasswordAuthentication passwdAuth = new PasswordAuthentication(userid,
125                 passwd.toCharArray());
126         Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
127         creds.add(passwdAuth);
128 
129         try
130         {
131             connection.setCredentials(creds);
132         } catch (JAXRException e)
133         {
134             e.printStackTrace();
135         }
136     }
137     
138     /**
139      * Does authentication with the uddi registry
140      */
141     public void loginSecondUser()
142     {
143         PasswordAuthentication passwdAuth = new PasswordAuthentication(userid2,
144                 passwd2.toCharArray());
145         Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
146         creds.add(passwdAuth);
147 
148         try
149         {
150             connection2.setCredentials(creds);
151         } catch (JAXRException e)
152         {
153             e.printStackTrace();
154         }
155     }
156 }