📄 xmlscriptinterpretertest.java
字号:
assertXpathExists("/qos/session", qos); assertXpathExists("/qos/ptp", qos); assertXpathExists("/qos/duplicateUpdates", qos); assertXpathExists("/qos/queue/callback", qos); assertXpathExists("/qos/clientProperty[@name='onMessageDefault']", qos); assertXpathExists("/qos/duplicateUpdates", qos); assertXpathExists("/qos/duplicateUpdates", qos); } protected void testSubscribe() throws Exception { String qosRef = "" + " <qos>\n" + " <subscribe id='_subId:1'/>\n" + " <erase forceDestroy='true'/>\n" + " <meta>false</meta>\n" + " <content>false</content>\n" + " <multiSubscribe>false</multiSubscribe>\n" + " <local>false</local>\n" + " <initialUpdate>false</initialUpdate>\n" + " <notify>false</notify>\n" + " <filter type='GnuRegexFilter' version='1.0'>^H.*$</filter>\n" + " <history numEntries='20'/>\n" + " </qos>\n"; String keyRef = " <key oid='' queryType='XPATH'> /xmlBlaster/key[starts-with(@oid,'radar.')] </key>\n"; String cmd = "<xmlBlaster>\n <subscribe>\n" + qosRef + keyRef + " </subscribe>\n" + "</xmlBlaster>\n"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); String key = this.accessor.getKey(); log.info("testSubscribe: qos: '" + qos + "'"); log.info("testSubscribe: key: '" + key + "'"); assertXMLEqual(qosRef, qos); assertXMLEqual(keyRef, key); } protected void testPublish() throws Exception { String keyRef = "<key oid='MyMessageOid' contentMime='text/xml'><some><qos type='xxx'><content /></qos><key>xxx</key></some></key>"; // String keyRef = "<key oid='MyMessageOid' contentMime='text/xml'><some><qos type='xxx'><content /></qos>xxx</some></key>"; String qosRef = "<qos><priority>HIGH</priority></qos>"; String contentRef = "<some><content>Hello World</content><qos></qos><key><key><qos><qos></qos></qos></key></key></some>"; String cmd = "<xmlBlaster id='xxyyzz'><publish>" + keyRef + "<content>" + contentRef + "</content>" + qosRef + "</publish></xmlBlaster>\n"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.out.reset(); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); String key = this.accessor.getKey(); String content = new String(this.accessor.getContent()).trim(); log.info("testPublish: qos: '" + qos + "' '" + qosRef + "'"); log.info("testPublish: key: '" + key + "' '" + keyRef + "'"); log.info("testPublish: content: '" + content + "' and should be '" + contentRef); assertXMLEqual(keyRef, key); assertXMLEqual(qosRef, qos); assertEquals(contentRef, content); String response = new String(this.out.toByteArray()); log.info("testPublish: response: '" + response + "'"); assertXpathExists("/xmlBlasterResponse[@id='xxyyzz']", response); } protected void testPublishArr() throws Exception { String keyRef = "<key oid='MyMessageOid' contentMime='text/xml'/>"; String qosRef = "<qos><priority>HIGH</priority></qos>"; String contentRef = "QmxhQmxhQmxh"; // this is in the attachment String contentShould = "BlaBlaBla"; String cmd = "<xmlBlaster><publishArr><message>" + keyRef + "<content link='attachment1' encoding='base64'>" + "</content>" + qosRef + "</message></publishArr></xmlBlaster>\n"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); String key = this.accessor.getKey(); String content = new String(this.accessor.getContent()).trim(); log.info("testPublishArr: qos: '" + qos + "' '" + qosRef + "'"); log.info("testPublishArr: key: '" + key + "' '" + keyRef + "'"); log.info("testPublishArr: content: '" + content + "'"); assertXMLEqual(keyRef, key); assertXMLEqual(qosRef, qos); assertEquals(contentShould, content); } protected void testDisconnect() throws Exception { String qosRef = "<qos><deleteSubjectQueue/><clearSessions>false</clearSessions></qos>"; String cmd = "<xmlBlaster><disconnect>" + qosRef + "</disconnect></xmlBlaster>"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); log.info("testDisconnect: qos: '" + qos + "' '" + qosRef + "'"); assertXMLEqual(qosRef, qos); } protected void testUnSubscribe() throws Exception { String qosRef = "<qos/>"; String keyRef = "<key queryType='XPATH'>//key</key>"; String cmd = "<xmlBlaster>\n <unSubscribe>\n" + qosRef + keyRef + " </unSubscribe>\n" + "</xmlBlaster>\n"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); String key = this.accessor.getKey(); log.info("testUnSubscribe: qos: '" + qos + "'"); log.info("testUnSubscribe: key: '" + key + "'"); assertXMLEqual(qosRef, qos); assertXMLEqual(keyRef, key); } protected void testErase() throws Exception { String qosRef = "<qos><erase forceDestroy='false'/></qos>"; String keyRef = "<key oid='MyTopic'/>"; String cmd = "<xmlBlaster>\n <erase>\n" + qosRef + keyRef + " </erase>\n" + "</xmlBlaster>\n"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); String key = this.accessor.getKey(); log.info("testErase: qos: '" + qos + "'"); log.info("testErase: key: '" + key + "'"); assertXMLEqual(qosRef, qos); assertXMLEqual(keyRef, key); } protected void testGet() throws Exception { String qosRef = "<qos><content>false</content>" +
"<filter type='GnuRegexFilter' version='1.0'>^H.*$</filter>" + "<history numEntries='20'/></qos>"; String keyRef = "<key oid='MyMessage' />"; String cmd = "<xmlBlaster>\n <get>\n" + qosRef + keyRef + " </get>\n" + "</xmlBlaster>\n"; ByteArrayInputStream in = new ByteArrayInputStream(cmd.getBytes()); this.interpreter.parse(new InputStreamReader(in)); String qos = this.accessor.getQos(); String key = this.accessor.getKey(); log.info("testGet: qos: '" + qos + "'"); log.info("testGet: key: '" + key + "'"); assertXMLEqual(qosRef, qos); assertXMLEqual(keyRef, key); } /** * <pre> * java org.xmlBlaster.test.classtest.XmlScriptInterpreterTest * </pre> */ public static void main(String args[]) { try { Global global = new Global(args); XmlScriptInterpreterTest test = new XmlScriptInterpreterTest(global, "XmlScriptInterpreterTest"); test.setUp(); test.testConnect(); test.testSubscribe(); test.testPublishArr(); test.testDisconnect(); test.testGet(); test.testErase(); test.testUnSubscribe(); test.testPublish(); // test.testWait(); //testSub.tearDown(); } catch(Throwable e) { e.printStackTrace(); //fail(e.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -