1   /**
2    * This file is part of the equanda project.
3    *
4    * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
7    *
8    * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
9    * ANY KIND, either express or implied. See the License for the specific language governing rights and
10   * limitations under the License.
11   *
12   * Alternatively, the contents of this file may be used under the terms of
13   * either the GNU General Public License Version 2 or later (the "GPL"), or
14   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
15   * in which case the provisions of the GPL or the LGPL are applicable instead
16   * of those above. If you wish to allow use of your version of this file only
17   * under the terms of either the GPL or the LGPL, and not to allow others to
18   * use your version of this file under the terms of the MPL, indicate your
19   * decision by deleting the provisions above and replace them with the notice
20   * and other provisions required by the GPL or the LGPL. If you do not delete
21   * the provisions above, a recipient may use your version of this file under
22   * the terms of any one of the MPL, the GPL or the LGPL.
23   */
24  
25  package org.equanda.test.xejb;
26  
27  import junit.framework.TestCase;
28  import org.equanda.util.ymport.ImportCredentials;
29  import org.jboss.security.SecurityAssociation;
30  import org.jboss.security.SimplePrincipal;
31  
32  import java.io.IOException;
33  import java.io.InputStream;
34  import java.util.Properties;
35  
36  
37  /**
38   * Base testcase which assures the user is logged in to the application server.
39   *
40   * @author <a href="mailto:joachim@progs.be">Joachim Van der Auwera</a>
41   */
42  public class TestAdapter
43      extends TestCase
44  {
45      private static ImportCredentials importCredentials;
46  
47      protected void setUp()
48          throws Exception
49      {
50          super.setUp();
51          login();
52      }
53  
54      public static void login()
55      {
56          try
57          {
58              Properties prop = new Properties();
59              InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "jndi.properties" );
60              String login = null, paswd = null;
61              if ( is != null )
62              {
63                  prop.load( is );
64                  login = prop.getProperty( "jboss.login" );
65                  paswd = prop.getProperty( "jboss.password" );
66              }
67              if ( login == null ) login = "local";
68              if ( paswd == null ) paswd = "local";
69  
70              importCredentials = new ImportCredentials( login, paswd );
71  
72              SecurityAssociation.setPrincipal( new SimplePrincipal( login ) );
73              SecurityAssociation.setCredential( paswd.toCharArray() );
74          }
75          catch ( IOException ioe )
76          {
77              System.err.println( "oops, can't access jndi.properties file" );
78          }
79      }
80  
81      public static ImportCredentials getImportCredentials()
82      {
83          return importCredentials;
84      }
85  
86      public void testNoTest()
87      {
88          assertTrue( true ); // simple test to assure there is no error about the testcase being empty
89      }
90  }