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   /* ***************************************************
8   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
9   * ***             http://cc.in2p3.fr/             ***
10  * ***************************************************
11  * File:   ContextInfoTest
12  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
13  * Date:   11 sept. 2008
14  * ***************************************************
15  * Description:                                      */
16  /**
17   *
18   */
19  public abstract class ContextInfoTest extends ContextTest {
20      private static String ALL_CONTEXTS = "all";
21      
22      protected ContextInfoTest() throws Exception {
23          super(ALL_CONTEXTS);
24      }
25  
26      protected ContextInfoTest(String contextId) throws Exception {
27          super(contextId);
28      }
29      
30      @Test
31      public void info() throws Exception {
32          
33          // Keep old mechanism for printing all contexts in default session
34          if (this.m_contextId.equals(ALL_CONTEXTS)) {
35              Session session = SessionFactory.createSession();
36              Context[] contexts = session.listContexts();
37              for (int i=0; i<contexts.length; i++) {
38                  Context context = contexts[i];
39      
40                  // print title
41                  System.out.println("Security context: "+context.getAttribute(Context.TYPE));
42      
43                  System.out.println(context);
44              }
45              session.close();
46          } else {
47              Session session = SessionFactory.createSession(false);
48              Context context = ContextFactory.createContext();
49              context.setAttribute(Context.TYPE, m_contextId);
50          
51              // set context-specific attributes
52              this.updateContextAttributes(context);
53      
54              // trigger initialization of context
55              try {
56                  session.addContext(context);
57              } catch(Exception e) {
58                  System.out.println("  Context not initialized ["+e.getMessage()+"]");
59              }
60          
61              // print context
62              System.out.println(context);
63              session.close();
64          }
65      }
66  }