View Javadoc

1   package org.ogf.saga.context;
2   
3   import org.junit.Test;
4   import org.ogf.saga.session.Session;
5   import org.ogf.saga.session.SessionFactory;
6   
7   import javax.swing.*;
8   import java.awt.*;
9   
10  /* ***************************************************
11  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
12  * ***             http://cc.in2p3.fr/             ***
13  * ***************************************************
14  * File:   ContextInitTest
15  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
16  * Date:   11 sept. 2008
17  * ***************************************************
18  * Description:                                      */
19  /**
20   *
21   */
22  public abstract class ContextInitTest extends ContextTest {
23      private boolean m_hasUserPass;
24  
25      protected ContextInitTest(String contextId) throws Exception {
26          this(contextId, true);
27      }
28  
29      protected ContextInitTest(String contextId, boolean hasUserPass) throws Exception {
30          super(contextId);
31          m_hasUserPass = hasUserPass;
32      }
33  
34      @Test
35      public void init() throws Exception {
36      	// create empty session
37      	Session session = SessionFactory.createSession(false);
38          // create context
39          Context context = ContextFactory.createContext();
40          context.setAttribute(Context.TYPE, m_contextId);
41  
42          // set attribute UserPass
43          if (m_hasUserPass) {
44              // test-only passwords can be retrieved from test properties
45              String userpass = super.getOptionalProperty(m_contextId, Context.USERPASS);
46              if (userpass == null) {
47                  // prompt for UserPass
48                  final String prompt = "Please enter UserPass (WARNING: clear text!)";
49                  try {
50                      userpass = JOptionPane.showInputDialog(prompt);
51                  } catch (HeadlessException e) {
52                      userpass = System.getProperty("userpass");
53                      if (userpass == null) {
54                          throw e;
55                      }
56                  }
57                  if (userpass==null || userpass.trim().length()==0) {
58                      fail("Test aborted by tester");
59                  }
60              }
61              context.setAttribute(Context.USERPASS, userpass);
62          }
63  
64          // set context-specific attributes
65          this.updateContextAttributes(context);
66  
67          // init context
68          session.addContext(context);
69      }
70  }