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

📄 testhelperclasses.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*------------------------------------------------------------------------------ Name:      TestHelperClasses.java Project:   org.xmlBlasterProject:   xmlBlaster.org Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file ------------------------------------------------------------------------------*/package org.xmlBlaster.test.contrib.replication;import java.io.ByteArrayInputStream;import java.io.File;import java.io.FileInputStream;import java.net.URL;import java.net.URLClassLoader;import java.sql.Connection;import java.sql.ResultSet;import java.sql.Statement;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;import java.util.logging.Logger;import org.custommonkey.xmlunit.XMLTestCase;import org.custommonkey.xmlunit.XMLUnit;import org.xmlBlaster.contrib.I_Info;import org.xmlBlaster.contrib.InfoHelper;import org.xmlBlaster.contrib.PropertiesInfo;import org.xmlBlaster.contrib.VersionTransformerCache;import org.xmlBlaster.contrib.db.DbPool;import org.xmlBlaster.contrib.db.I_DbPool;import org.xmlBlaster.contrib.dbwriter.DbWriter;import org.xmlBlaster.contrib.dbwriter.SqlInfoParser;import org.xmlBlaster.contrib.dbwriter.info.SqlDescription;import org.xmlBlaster.contrib.dbwriter.info.SqlInfo;import org.xmlBlaster.contrib.dbwriter.info.SqlRow;import org.xmlBlaster.contrib.filewriter.FileWriterCallback;import org.xmlBlaster.contrib.replication.ReplicationConstants;import org.xmlBlaster.contrib.replication.ReplicationWriter;import org.xmlBlaster.contrib.replication.TableToWatchInfo;import org.xmlBlaster.contrib.replication.impl.DefaultMapper;import org.xmlBlaster.contrib.replication.impl.SearchableConfig;import org.xmlBlaster.jms.XBConnectionMetaData;import org.xmlBlaster.jms.XBMessage;import org.xmlBlaster.util.qos.ClientProperty;/** * Test helper classes as for example beans used for the configuration. * Does not need a DB nor xmlBlaster running. *  * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a> */public class TestHelperClasses extends XMLTestCase {   private static Logger log = Logger.getLogger(TestHelperClasses.class.getName());      /**    * Start the test.    * <pre>    *  java -Ddb=oracle junit.swingui.TestRunner -noloading org.xmlBlaster.test.contrib.replication.TestHelperClasses    * </pre>    * @param args  Command line settings    */   public static void main(String[] args) {      // junit.swingui.TestRunner.run(TestHelperClasses.class);            TestHelperClasses test = new TestHelperClasses();      try {                  test.setUp();         test.testTableToWatchInfoForAllToken();         test.tearDown();         test.setUp();         test.testSearchableConfig();         test.tearDown();         test.setUp();         test.testFileWriterCallback();         test.tearDown();         test.setUp();         test.testVersionTransformerCache();         test.tearDown();         test.setUp();         test.testInfoHelper();         test.tearDown();         test.setUp();         test.testTableMapper();         test.tearDown();         test.setUp();         test.testTableToWatchInfoKeys();         test.tearDown();         test.setUp();         test.testTableToWatchInfoValues();         test.tearDown();         test.setUp();         test.testTableToWatchInfoStatic();         test.tearDown();         test.setUp();         test.testInfo();         test.tearDown();      }       catch (Exception ex) {         ex.printStackTrace();         fail();      }   }   /**    * Default ctor.    */   public TestHelperClasses() {      super();      XMLUnit.setIgnoreWhitespace(true);   }   /**    * Constructor for TestHelperClasses.    *     * @param arg0    */   public TestHelperClasses(String arg0) {      super(arg0);      XMLUnit.setIgnoreWhitespace(true);   }   /**    * Configure database access.    * @see TestCase#setUp()    */   protected void setUp() throws Exception {      super.setUp();   }   /*    * @see TestCase#tearDown()    */   protected void tearDown() throws Exception {      super.tearDown();   }   public void testVersionTransformerCacheInternal() {            String srcData = "<?xml version='1.0' encoding='iso-8859-1' ?>\n" +                        "<check><test/></check>\n";      String replPrefix = "test";      String srcVersion = "01";      String destVersion = "02";      String destination = "client/subject/1";            VersionTransformerCache cache = new VersionTransformerCache();            try {         byte[] ret = cache.transform(replPrefix, srcVersion, destVersion, destination, srcData.getBytes(), null);         log.info(new String(ret));      }      catch (Exception ex) {         ex.printStackTrace();      }            System.out.println("TEST");   }            public void testFileWriterCallback() {      String importLocation = "/tmp";      String tmpImportLocation = "/tmp/tmpFiles";      String lockExtention = ".lock";      boolean overwriteDumpFiles = true;      boolean keepDumpFiles = false;      try {         FileWriterCallback callback = new FileWriterCallback(importLocation, tmpImportLocation, lockExtention, overwriteDumpFiles, keepDumpFiles);         byte[] content = new byte[100000];         File checkFile = new File("/tmp/dummy");         checkFile.delete();         callback.update("dummy", new ByteArrayInputStream(content), null);         assertTrue("The file 'dummy' must exist", checkFile.exists());      }      catch (Exception ex) {         ex.printStackTrace();         assertTrue("An exception should not occur. " + ex.getMessage(), false);      }            try {         FileWriterCallback callback = new FileWriterCallback(importLocation, tmpImportLocation, lockExtention, overwriteDumpFiles, keepDumpFiles);         String filename = "second.dat";         File checkFile = new File("/tmp/" + filename);         checkFile.delete();         HashMap map = new HashMap();         map.put("_filename", new ClientProperty("_filename", null, null, filename));         String key = XBMessage.addToKeyAndCheck(XBConnectionMetaData.JMSX_GROUP_SEQ);         map.put(key, new ClientProperty(key, null, null, "" + 0L));         callback.update("dummy", new ByteArrayInputStream("first".getBytes()), map);         map.clear();         map.put("_filename", new ClientProperty("_filename", null, null, filename));         key = XBMessage.addToKeyAndCheck(XBConnectionMetaData.JMSX_GROUP_SEQ);         map.put(key, new ClientProperty(key, null, null, "" + 1L));         callback.update("dummy", new ByteArrayInputStream("second".getBytes()), map);                  map.clear();         map.put("_filename", new ClientProperty("_filename", null, null, filename));         key = XBMessage.addToKeyAndCheck(XBConnectionMetaData.JMSX_GROUP_SEQ);         map.put(key, new ClientProperty(key, null, null, "" + 2L));         key = XBMessage.addToKeyAndCheck(XBConnectionMetaData.JMSX_GROUP_EOF);         map.put(key, new ClientProperty(key, null, null, "true"));         callback.update("dummy", new ByteArrayInputStream("third".getBytes()), map);                  assertTrue("The file 'dummy' must exist", checkFile.exists());         FileInputStream fis = new FileInputStream(checkFile);         byte[] buf = new byte[100];         fis.read(buf);         String ret = new String(buf).trim();         assertEquals("The length of the string of combined files must match", "firstsecondthird".length(), ret.length());         assertEquals("The string of the combined files is ", "firstsecondthird", ret);         log.info("content of message is '" + ret + "'");      }      catch (Exception ex) {         ex.printStackTrace();         assertTrue("An exception should not occur. " + ex.getMessage(), false);      }   }         public void testVersionTransformerCache() {      try {         URLClassLoader cl = (URLClassLoader)getClass().getClassLoader();         URL[] urls = cl.getURLs();         String url = null;         for (int i=0; i < urls.length; i++) {            int pos = urls[i].getFile().indexOf(File.separator + "xmlBlaster" + File.separator + "lib" + File.separator);             if (pos > -1) {               url = urls[i].getFile().substring(0, pos);               break;            }         }         if (url == null)            url = "";         log.info("The found xmlBlaster url is '" + url + "'");         StringBuffer buf = new StringBuffer();         buf.append(File.separator).append("xmlBlaster");         buf.append(File.separator).append("testsuite");         buf.append(File.separator).append("data");         buf.append(File.separator).append("xsl").append(File.separator);         String name = "file:" + url + buf.toString();         URL[] tmpUrls = new URL[] { new URL(name) };         URLClassLoader subLoader = URLClassLoader.newInstance(tmpUrls, cl);                  // Object obj = subLoader.loadClass(TestHelperClasses.class.getName()).newInstance();         // Method method = obj.getClass().getMethod("testVersionTransformerCacheInternal", null);         // method.invoke(obj, null);                           String srcData = "<?xml version='1.0' encoding='iso-8859-1' ?>\n" +          "<check><test/></check>\n";         String replPrefix = "test";         String srcVersion = "01";         String destVersion = "02";         String destination = "client/subject/1";         VersionTransformerCache cache = new VersionTransformerCache();         try {            byte[] ret = cache.transform(replPrefix, srcVersion, destVersion, destination, srcData.getBytes(), subLoader);            log.info(new String(ret));            ret = cache.transform(replPrefix, srcVersion, destVersion, destination, srcData.getBytes(), subLoader);            log.info(new String(ret));            destVersion = "03";            ret = cache.transform(replPrefix, srcVersion, destVersion, destination, srcData.getBytes(), subLoader);            log.info(new String(ret));                        {               String in = "repl_Ver_0.5.dump";               String prefix = VersionTransformerCache.stripReplicationPrefix(in);               String version = VersionTransformerCache.stripReplicationVersion(in);               assertEquals("Wrong prefix", "repl", prefix);               assertEquals("Wrong version", "0.5", version);            }            {               String in = "repl_Ver_0.5";               String prefix = VersionTransformerCache.stripReplicationPrefix(in);               String version = VersionTransformerCache.stripReplicationVersion(in);               assertEquals("Wrong prefix", "repl", prefix);               assertEquals("Wrong version", "0.5", version);            }                                             }         catch (Exception ex) {            ex.printStackTrace();         }         log.info("END");      }      catch (Exception ex) {         ex.printStackTrace();      }   }      /**    *     */   public final void testTableToWatchInfoKeys() {      log.info("Start testTableToWatchInfoKeys");            TableToWatchInfo tableToWatchInfo = new TableToWatchInfo();      String key1 = "table.catalog1.schema1.table1";      String key2 = "table.schema2.table2";

⌨️ 快捷键说明

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