1 package org.xmlBlaster.test.client;
  2 
  3 import java.util.logging.Logger;
  4 
  5 import org.xmlBlaster.client.I_XmlBlasterAccess;
  6 import org.xmlBlaster.client.key.UpdateKey;
  7 import org.xmlBlaster.client.qos.ConnectQos;
  8 import org.xmlBlaster.client.qos.DisconnectQos;
  9 import org.xmlBlaster.client.qos.UpdateQos;
 10 import org.xmlBlaster.test.MsgInterceptor;
 11 import org.xmlBlaster.util.Global;
 12 import org.xmlBlaster.util.XmlBlasterException;
 13 
 14 import junit.framework.TestCase;
 15 
 16 /**
 17  * Testing administrative commands. 
 18  * @author xmlblast@marcelruff.info
 19  */
 20 public class TestCommand extends TestCase {
 21    private final Global global;
 22    private static Logger log = Logger.getLogger(TestCommand.class.getName());
 23    private Global connGlobal;
 24    private MsgInterceptor updateInterceptor;
 25 
 26    public static void main(String[] args) {
 27       junit.swingui.TestRunner.run(TestCommand.class);
 28    }
 29 
 30    /**
 31     * Constructor for TestCommand.
 32     * @param arg0
 33     */
 34    public TestCommand(String name) {
 35       super(name);
 36       this.global = Global.instance();
 37    }
 38 
 39    /*
 40     * @see TestCase#setUp()
 41     */
 42    protected void setUp() throws Exception {
 43       super.setUp();
 44       log.info("Trying to connect to xmlBlaster with Java client lib " + global.getVersion());
 45       try {
 46          this.connGlobal = this.global.getClone(null);
 47          this.updateInterceptor = new MsgInterceptor(this.connGlobal, log, null);
 48          this.connGlobal.getXmlBlasterAccess().connect(new ConnectQos(this.connGlobal), this.updateInterceptor);
 49       }
 50       catch (XmlBlasterException ex) {
 51          ex.printStackTrace();
 52          fail("aborting since exception ex: " + ex.getMessage());
 53       }
 54    }
 55 
 56    /*
 57     * @see TestCase#tearDown()
 58     */
 59    protected void tearDown() throws Exception {
 60       super.tearDown();
 61       log.info("Entering tearDown(), test is finished");
 62       this.connGlobal.getXmlBlasterAccess().disconnect(new DisconnectQos(this.connGlobal));
 63       this.connGlobal.shutdown();
 64       this.connGlobal = null;
 65    }
 66 
 67    public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) throws XmlBlasterException {
 68       log.severe("update: should never be invoked (msgInterceptors take care of it since they are passed on subscriptions)");
 69       return "OK";
 70    }
 71    
 72    public void testSetCallbackDispatcherActive() {
 73       log.fine("setCallbackDispatcherActive() ...");
 74       try {
 75          this.connGlobal.getXmlBlasterAccess().setCallbackDispatcherActive(false);
 76          log.info("Success: setCallbackDispatcherActive(false)");
 77 
 78          //Global.waitOnKeyboardHit("Hit a key to activate again ...");
 79 
 80          this.connGlobal.getXmlBlasterAccess().setCallbackDispatcherActive(true);
 81          log.info("Success: setCallbackDispatcherActive(true)");
 82 
 83          //Global.waitOnKeyboardHit("Hit a key to finish test ...");
 84       }
 85       catch(XmlBlasterException e) {
 86          log.warning("XmlBlasterException: " + e.toXml());
 87          fail(e.getMessage());
 88       }
 89    }
 90 
 91    public void testSendAdministrativeCommand() {
 92       log.fine("sendAdministrativeCommand() ...");
 93       I_XmlBlasterAccess con = this.connGlobal.getXmlBlasterAccess();
 94       String sessionName = con.getSessionName().getAbsoluteName();
 95       {
 96          String command = sessionName+"/?dispatcherActive";
 97          log.info("Trying command '" + command + "'");
 98          try {
 99             String ret = con.sendAdministrativeCommand(command);
100             log.info("Success: " + command + " returned '" + ret + "'");
101             assertEquals("true", ret);
102          }
103          catch(XmlBlasterException e) {
104             fail(e.getMessage());
105          }
106       }
107       {
108          String command = sessionName+"/?dispatcherActive=false";
109          log.info("Trying command '" + command + "'");
110          try {
111             String ret = con.sendAdministrativeCommand(command);
112             log.info("Success: " + command + " returned '" + ret + "'");
113             assertEquals("OK", ret);
114          }
115          catch(XmlBlasterException e) {
116             fail(e.getMessage());
117          }
118       }
119       {
120          String command = sessionName+"/?dispatcherActive";
121          log.info("Trying command '" + command + "'");
122          try {
123             String ret = con.sendAdministrativeCommand(command);
124             log.info("Success: " + command + " returned '" + ret + "'");
125             assertEquals("false", ret);
126          }
127          catch(XmlBlasterException e) {
128             fail(e.getMessage());
129          }
130       }
131       {
132          String command = "set " + sessionName+"/?dispatcherActive=true";
133          log.info("Trying command '" + command + "'");
134          try {
135             String ret = con.sendAdministrativeCommand(command);
136             log.info("Success: " + command + " returned '" + ret + "'");
137             assertEquals("OK", ret);
138          }
139          catch(XmlBlasterException e) {
140             fail(e.getMessage());
141          }
142       }
143       {
144          String command = "get " + sessionName+"/?dispatcherActive";
145          log.info("Trying command '" + command + "'");
146          try {
147             String ret = con.sendAdministrativeCommand(command);
148             log.info("Success: " + command + " returned '" + ret + "'");
149             assertEquals("true", ret);
150          }
151          catch(XmlBlasterException e) {
152             fail(e.getMessage());
153          }
154       }
155    }
156 }


syntax highlighted by Code2HTML, v. 0.9.1