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
12
13
14
15
16
17
18
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
37 Session session = SessionFactory.createSession(false);
38
39 Context context = ContextFactory.createContext();
40 context.setAttribute(Context.TYPE, m_contextId);
41
42
43 if (m_hasUserPass) {
44
45 String userpass = super.getOptionalProperty(m_contextId, Context.USERPASS);
46 if (userpass == null) {
47
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
65 this.updateContextAttributes(context);
66
67
68 session.addContext(context);
69 }
70 }