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

📄 runleveltest.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.xmlBlaster.test.classtest;import java.util.Properties;import java.util.logging.Logger;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import junit.framework.*;import org.xmlBlaster.engine.runlevel.RunLevelActionSaxFactory;import org.xmlBlaster.engine.runlevel.RunLevelAction;import org.xmlBlaster.engine.runlevel.PluginConfig;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.qos.MsgQosData;import org.xmlBlaster.util.qos.MsgQosSaxFactory;import org.xmlBlaster.engine.runlevel.PluginConfigSaxFactory;import org.xmlBlaster.engine.runlevel.PluginHolderSaxFactory;import org.xmlBlaster.engine.runlevel.PluginHolder;import org.xmlBlaster.engine.runlevel.PluginConfigComparator;/** * Test ConnectQos.  * <p /> * All methods starting with 'test' and without arguments are invoked automatically * <p /> * TODO: http://xmlunit.sourceforge.net/ * <p /> * Invoke: java -Djava.compiler= junit.textui.TestRunner -noloading org.xmlBlaster.test.classtest.RunLevelTest * @see org.xmlBlaster.util.qos.ConnectQosData * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.connect.html" target="others">the interface.connect requirement</a> */public class RunLevelTest extends TestCase {   final static String ME = "RunLevelTest";   protected Global glob;   private static Logger log = Logger.getLogger(RunLevelTest.class.getName());   int counter = 0;   public RunLevelTest(String name, String[] args) {      super(name);      this.glob = Global.instance();      this.glob.init(args);   }   public RunLevelTest(String name) {      super(name);      this.glob = Global.instance();   }   protected void setUp() {   }   protected void tearDown() {   }   public void testAction() {      String me = ME + "-testAction";      log.info("start");      try {         String xml = "<action do='LOAD'\n" +                      "        onStartupRunlevel='3'\n" +                      "        sequence='5'\n" +                      "        onFail='resource.configuration.pluginFailed'/>";            RunLevelActionSaxFactory factory = new RunLevelActionSaxFactory(this.glob);         RunLevelAction action = factory.readObject(xml);         for (int i=0; i < 2; i++) {            assertEquals(me + " checking do attribute", "LOAD", action.getDo());            assertEquals(me + " checking onFail attribute", "resource.configuration.pluginFailed", action.getOnFail().getErrorCode());            assertEquals(me + " checking onShutdownLevel attribute", -1, action.getOnShutdownRunlevel());            assertEquals(me + " checking onStartupLevel attribute", 3, action.getOnStartupRunlevel());            assertEquals(me + " checking sequence attribute", 5, action.getSequence());            assertEquals(me + " checking hasOnFail", true, action.hasOnFail());            assertEquals(me + " checking isOnShutdownLevel", false, action.isOnShutdownRunlevel());            assertEquals(me + " checking isOnStartupLevel", true, action.isOnStartupRunlevel());            xml = action.toXml();            action = factory.readObject(xml);            log.info("going to test the second time ...");         }         // now test a null string         try {            xml = null;            action = factory.readObject(xml);            assertTrue(me + " a null string is not allowed here. Should have thrown an exception", true);         }         catch (XmlBlasterException ex) {            log.info("the exception is allowed here since a null string is not allowed here." + ex.getMessage());         }         try {            xml = "";            action = factory.readObject(xml);            assertTrue(me + " an empty string is not allowed here. Should have thrown an exception", true);         }         catch (XmlBlasterException ex) {            log.info("the exception is allowed here since an empty string is not allowed here." + ex.getMessage());         }         try {            xml = "xyz";            action = factory.readObject(xml);            assertTrue(me + " a non-xml string is not allowed here. Should have thrown an exception", true);         }         catch (XmlBlasterException ex) {            log.info("the exception is allowed here since a non-xml string is not allowed here." + ex.getMessage());         }         try {            xml = "<xmlBlaster></xmlBlaster>";            action = factory.readObject(xml);            assertTrue(me + " a wrong tag name is not allowed here. Should have thrown an exception", true);         }         catch (XmlBlasterException ex) {            log.info("the exception is allowed here since  a wrong tag name is not allowed here." + ex.getMessage());         }         // this is allowed ...         xml = "<action/>";         action = factory.readObject(xml);      }      catch (XmlBlasterException e) {         fail(ME+ " failed: " + e.toString());      }      log.info("successfully ended");   }   public void testPluginConfig() {      String me = ME + "-testPluginConfig";      try {         log.info("start");         PluginConfig config = new PluginConfig(this.glob, "queueJDBC", true, "org.xmlBlaster.util.queue.jdbc.JDBCQueueCommonTablePlugin");         config.addAttribute("url", "jdbc:oracle:thin:@localhost:1521:noty");         config.addAttribute("user", "joe");         config.addAttribute("password", "secret");         config.addAttribute("connectionBusyTimeout", "90000");         config.addAttribute("maxWaitingThreads", "300");         RunLevelAction action = new RunLevelAction(this.glob, "LOAD", 3, -1, ErrorCode.toErrorCode("internal.unknown"), 5);         config.addAction(action);         action = new RunLevelAction(this.glob, "STOP", -1, 2, null, 4);         config.addAction(action);              String xml = config.toXml();         log.info(xml);              PluginConfigSaxFactory factory = new PluginConfigSaxFactory(this.glob);         config = factory.readObject(xml);         RunLevelAction[] actions = config.getActions();         assertEquals(me + " number of actions", 2, actions.length);      }      catch (XmlBlasterException e) {         fail(ME + " failed: " + e.toString());      }      log.info("successfully ended");   }   private MsgQosData getQosData(String attrVal) throws XmlBlasterException {      PluginConfigSaxFactory factory = new PluginConfigSaxFactory(this.glob);      String xml = "<plugin id='FilePollerPlugin' className='org.xmlBlaster.client.filepoller.FilePollerPlugin'>\n" +                   "  <attribute id='qosTest'>" + attrVal + "</attribute>\n" +                    "  <action do='LOAD' onStartupRunlevel='9' sequence='6' onFail='resource.configuration.pluginFailed'/>\n" +                   "  <action do='STOP' onShutdownRunlevel='6' sequence='5'/>\n" +                    "</plugin>\n";      PluginConfig config = factory.readObject(xml);      Properties prop = config.getPluginInfo().getParameters();      String txt = prop.getProperty("qosTest", null);      if (txt == null) {         prop.list(System.err);         assertTrue("the qosTest is null when it should not", false);      }      MsgQosSaxFactory msgFactory = new MsgQosSaxFactory(this.glob);      return msgFactory.readObject(txt);   }   public void testPluginConfigParser() {      log.info("start");      String xml = "<![CDATA[<qos><expiration lifeTime='4000'/></qos>]]>";      try {         MsgQosData data = getQosData(xml);         assertEquals("Wrong lifetime", 4000L, data.getLifeTime());       }      catch (XmlBlasterException e) {         assertTrue(ME + " parsing failed for '" + xml + "'", false);      }      /*      xml = "&lt;![CDATA[<qos><expiration lifeTime='4000'/></qos>]]&gt;";      try {         MsgQosData data = getQosData(xml);         assertEquals("Wrong lifetime", 4000L, data.getLifeTime());       }      catch (XmlBlasterException e) {         assertTrue(ME + " parsing failed for '" + xml + "'", false);      }      */      xml = "<qos><expiration lifeTime='4000'/></qos>";      try {         MsgQosData data = getQosData(xml);         assertEquals("Wrong lifetime", 4000L, data.getLifeTime());       }      catch (XmlBlasterException e) {         assertTrue(ME + " parsing failed for '" + xml + "'", false);      }      xml = "<qos><![CDATA[<expiration lifeTime='4000'/>]]></qos>";      try {         MsgQosData data = getQosData(xml);         // unless you change the parsing in MsgQosData         assertEquals("Wrong lifetime", -1L, data.getLifeTime());       }      catch (XmlBlasterException e) {         assertTrue(ME + " parsing failed for '" + xml + "'", false);      }         }   public void testPluginHolder() {      String me = ME + "-testPluginHolder";      try {         log.info("start");         PluginHolder holder = new PluginHolder(this.glob);                  PluginConfig tmp = new PluginConfig(this.glob, "queueJDBC", true, "org.xmlBlaster.util.queue.jdbc.JDBCQueueCommonTablePlugin");         holder.addDefaultPluginConfig(tmp);         tmp = new PluginConfig(this.glob, "queueRAM", true, "org.xmlBlaster.util.queue.ram.RAMQueuePlugin");         holder.addPluginConfig("avalon", tmp);         tmp = holder.getPluginConfig("avalon", "queueRAM");         if (tmp == null) assertTrue(me + " getting 'avalon queueRAM'", false);         log.info(tmp.toXml());         tmp = holder.getPluginConfig("avalon", "queueJDBC");         if (tmp == null) assertTrue(me + " getting 'avalon queueJDBC'", false);

⌨️ 快捷键说明

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