⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlscriptinterpretertest.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      XmlScriptInterpreterTest.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.test.classtest;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.InputStreamReader;import java.util.HashMap;import org.custommonkey.xmlunit.XMLTestCase;import org.custommonkey.xmlunit.XMLUnit;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.client.I_Callback;import org.xmlBlaster.client.XmlBlasterAccess;import org.xmlBlaster.client.qos.*;import org.xmlBlaster.client.script.XmlScriptClient;import org.xmlBlaster.client.script.XmlScriptInterpreter;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.MsgUnit;import org.xmlBlaster.util.XmlBlasterException;/** * Test ClientProperty.  * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a> * <p /> * All methods starting with 'test' and without arguments are invoked automatically * <p /> * Invoke: java -Djava.compiler= junit.textui.TestRunner -noloading org.xmlBlaster.test.classtest.XmlScriptInterpreterTest * @see org.xmlBlaster.client.script.XmlScriptInterpreter * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/engine.qos.xmlScript.html">The client.xmlScript requirement</a> */public class XmlScriptInterpreterTest extends XMLTestCase {   protected final static String ME = "XmlScriptInterpreterTest";   protected Global glob;   private static Logger log = Logger.getLogger(XmlScriptInterpreterTest.class.getName());   protected XmlScriptInterpreter interpreter;   private TestAccessor accessor;   private ByteArrayOutputStream out;   private HashMap attachments;      public class TestAccessor extends XmlBlasterAccess {            private boolean doRemoteCalls;      private String key, qos;      private byte[] content;            public TestAccessor(Global global, boolean doRemoteCalls) {         super(global);         this.doRemoteCalls = doRemoteCalls;      }            public String getQos() {         return this.qos;      }            public String getKey() {         return this.key;      }      public byte[] getContent() {         return this.content;      }            public ConnectReturnQos connect(ConnectQos qos, I_Callback callback)          throws XmlBlasterException {         this.qos = qos.toXml();         if (this.doRemoteCalls) return super.connect(qos, callback);         return null;               }            public SubscribeReturnQos subscribe(String key, String qos)          throws XmlBlasterException {         this.qos = qos;         this.key = key;         log.fine("subscribe: " + key + " " + qos);         if (this.doRemoteCalls) return super.subscribe(key, qos);         return null;      }      public UnSubscribeReturnQos[] unSubscribe(String key, String qos)          throws XmlBlasterException {         this.qos = qos;         this.key = key;         log.fine("unSubscribe: " + key + " " + qos);         if (this.doRemoteCalls) return super.unSubscribe(key, qos);         return null;      }      public PublishReturnQos publish(MsgUnit msgUnit)          throws XmlBlasterException {         this.qos = msgUnit.getQos();         this.key = msgUnit.getKey();         this.content = msgUnit.getContent();         log.fine("publish: " + key + " " + qos);         if (this.doRemoteCalls) return super.publish(msgUnit);         return null;      }         public PublishReturnQos[] publishArr(MsgUnit[] msgUnits) throws XmlBlasterException {         // currently only store the first ones ...         this.qos = msgUnits[0].getQos();         this.key = msgUnits[0].getKey();         this.content = msgUnits[0].getContent();         log.fine("publishArr: " + key + " " + qos);         if (this.doRemoteCalls) return super.publishArr(msgUnits);         return null;      }            public MsgUnit[] get(String key, String qos) throws XmlBlasterException {         this.qos = qos;         this.key = key;         log.fine("get: " + key + " " + qos);         if (this.doRemoteCalls) return super.get(key, qos);         return null;      }      public EraseReturnQos[] erase(String key, String qos) throws XmlBlasterException {         this.qos = qos;         this.key = key;         log.fine("erase: " + key + " " + qos);         if (this.doRemoteCalls) return super.erase(key, qos);         return null;      }      public boolean disconnect(DisconnectQos qos) {         this.qos = qos.toXml();         log.fine("disconnect: " + key + " " + qos);         if (this.doRemoteCalls) return super.disconnect(qos);         return false;      }   }   public XmlScriptInterpreterTest(String name) {      this(new Global(), name);   }   public XmlScriptInterpreterTest(Global global, String name) {      super(name);      boolean doRemoteCalls = false;      this.accessor = new TestAccessor(global, doRemoteCalls);      this.out = new ByteArrayOutputStream();      this.attachments = new HashMap();      String contentRef = "QmxhQmxhQmxh"; // this is used in testPublishArr      this.attachments.put("attachment1", contentRef);      this.interpreter = new XmlScriptClient(global, this.accessor, out, out, this.attachments);       XMLUnit.setIgnoreWhitespace(true);   }   protected void setUp() {      this.glob = Global.instance();   }   protected void testConnect() throws Exception {      String tmp = "<xmlBlaster>\n" +                   "  <connect>\n" +                    "      <qos>\n" +                   "         <securityService type='htpasswd' version='1.0'>\n" +                   "           <![CDATA[" +                   "           <user>michele</user>" +                   "           <passwd>secret</passwd>" +                   "           ]]>" +                   "         </securityService>\n" +                   "         <session name='client/joe/3' timeout='3600000' maxSessions='10'" +                   "                     clearSessions='false' reconnectSameClientOnly='false'/>\n" +                   "         <ptp>true</ptp>\n" +                   "         <duplicateUpdates>false</duplicateUpdates>\n" +                   "         <queue relating='callback' maxEntries='1000' maxBytes='4000000'>\n" +                   "            <callback type='IOR' sessionId='4e56890ghdFzj0' pingInterval='10000'\n" +                   "                retries='-1' delay='10000' oneway='false' dispatchPlugin='undef'>\n" +                   "               IOR:10000010033200000099000010....\n" +                   "               <burstMode collectTime='400' />\n" +                   "               <compress type='gzip' minSize='3000'/>\n" +                   "               <ptp>true</ptp>\n" +                   "            </callback>\n" +                   "         </queue>\n" +                    "         <!-- a client specific property: here it could be the bean to invoke on updates -->\n" +                   "         <clientProperty name='onMessageDefault'>beanName</clientProperty>\n" +                   "      </qos>\n" +                   "   </connect>\n" +                    "</xmlBlaster>\n";      ByteArrayInputStream in = new ByteArrayInputStream(tmp.getBytes());      this.interpreter.parse(new InputStreamReader(in));      String qos = this.accessor.getQos();      assertXpathExists("/qos/securityService[@type='htpasswd']", qos);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -