1 /*------------------------------------------------------------------------------
2 Name: TestLogout.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6 package org.xmlBlaster.test.authentication;
7
8 import java.util.logging.Logger;
9
10 import junit.framework.TestCase;
11
12 import org.xmlBlaster.client.I_Callback;
13 import org.xmlBlaster.client.I_XmlBlasterAccess;
14 import org.xmlBlaster.client.key.UpdateKey;
15 import org.xmlBlaster.client.qos.ConnectQos;
16 import org.xmlBlaster.client.qos.UpdateQos;
17 import org.xmlBlaster.util.Global;
18 import org.xmlBlaster.util.XmlBlasterException;
19
20
21 /**
22 */
23 public class TestLogout extends TestCase implements I_Callback
24 {
25 private static String ME = "TestLogout";
26 private final Global glob;
27 private static Logger log = Logger.getLogger(TestLogout.class.getName());
28
29 private I_XmlBlasterAccess con;
30
31 /**
32 * Constructs the TestLogout object from out main().
33 */
34 public TestLogout(Global glob) {
35 super("TestLogout");
36 this.glob = glob;
37
38 }
39
40 /**
41 * Constructs the TestLogout object from junit.
42 */
43 public TestLogout(String name) {
44 super(name);
45 this.glob = new Global();
46
47 }
48
49 /**
50 * Connect to xmlBlaster.
51 */
52 protected void setUp() {
53 try {
54 con = glob.getXmlBlasterAccess(); // Find orb
55 /*
56 con.initFailSave(new I_ConnectionStateListener() {
57 public void reConnected() {
58 log.info("I_ConnectionStateListener: We were lucky, reconnected to " + glob.getId());
59 try {
60 con.flushQueue(); // send all tailback messages
61 } catch (XmlBlasterException e) {
62 log.severe("Exception during reconnection recovery: " + e.getMessage());
63 }
64 }
65 public void lostConnection() {
66 log.warning("I_ConnectionStateListener: Lost connection to " + glob.getId());
67 }
68 });
69 */
70 ConnectQos qos = new ConnectQos(glob, ME, "secret");
71 con.connect(qos, this); // Login to xmlBlaster
72 log.info("Successful login");
73 }
74 catch (XmlBlasterException e) {
75 log.severe(e.toString());
76 e.printStackTrace();
77 }
78 }
79
80 /**
81 * Tears down the fixture.
82 * <p />
83 * cleaning up .... erase() the previous message OID and logout
84 */
85 protected void tearDown() {
86 if (con != null) con.disconnect(null);
87 }
88
89
90 /**
91 */
92 public void testDisconnect() {
93 log.info("*** Enter testDisconnect() ...");
94 if (con.disconnect(null) == false) {
95 log.severe("Expected successful disconnect");
96 fail("Expected successful disconnect");
97 }
98 if (con.disconnect(null) == true) {
99 log.severe("Expected disconnect to fail, we have disconnected already");
100 fail("Expected disconnect to fail, we have disconnected already");
101 }
102 con = null;
103 log.info("*** Leave testDisconnect() ...");
104 }
105
106 /**
107 */
108 public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
109 fail("Receiving update of a message " + updateKey.getOid());
110 return "";
111 }
112
113 /**
114 * Invoke: java org.xmlBlaster.test.authentication.TestLogout
115 * <p />
116 * <pre>java -Djava.compiler= junit.textui.TestRunner -noloading org.xmlBlaster.test.authentication.TestLogout</pre>
117 */
118 public static void main(String args[]) {
119 Global glob = new Global();
120 if (glob.init(args) != 0) {
121 System.exit(1);
122 }
123 TestLogout testSub = new TestLogout(glob);
124 testSub.setUp();
125 testSub.testDisconnect();
126 testSub.tearDown();
127 }
128 }
syntax highlighted by Code2HTML, v. 0.9.1