📄 testdbspecific.java
字号:
* @param dbSpecificName the name of the class to instantiate. If null, a default is taken. * @return The created I_DbSpecific object. */ private I_DbSpecific setUpDbSpecific(I_Info info, String dbSpecificName) { try { if (dbSpecificName == null) dbSpecificName = "org.xmlBlaster.contrib.replication.impl.SpecificDefault"; ClassLoader cl = DbWatcher.class.getClassLoader(); I_DbSpecific dbSpecific = (I_DbSpecific)cl.loadClass(dbSpecificName).newInstance(); assertNotNull("dbSpecific must not be null, check the classname", dbSpecific); info.put("mom.class", "org.xmlBlaster.test.contrib.replication.TestDbSpecific"); dbSpecific.init(info); return dbSpecific; } catch (Exception ex) { ex.printStackTrace(); assertTrue("exception when setting up publisher should not occur: " + ex.getMessage(), false); return null; } } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); try { dbPool.update("DELETE from " + dbHelper.getIdentifier(this.replPrefix + "TABLES")); } catch (Exception ex) { ex.printStackTrace(); } if (dbSpecific != null) { dbSpecific.shutdown(); dbSpecific = null; } if (dbPool != null) { dbPool.shutdown(); dbPool = null; } } /** * This method tests all the sql statements. It checks the creation statements * for the different sql data types. * * @throws Exception Any type is possible */ public final void testCreateTablesWithDifferentTypes() throws Exception { currentMethod = new String("testCreateTablesWithDifferentTypes"); log.info("Start " + currentMethod); I_DbPool pool = (I_DbPool)info.getObject("db.pool"); assertNotNull("pool must be instantiated", pool); doCheck = true; String[] sqls = specificHelper.getSql(this.tableName); try { for (int i=0; i < sqls.length; i++) { try { try { pool.update("DROP TABLE " + this.tableName + specificHelper.getCascade()); } catch (Exception e) { } pool.update(sqls[i]); // don't do this since oracle 10.1.0 returns zero (don't know why) // assertEquals("the number of created tables must be one", 1, ret); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not occur when testing nr." + i + " which is '" + sqls[i] + "' : " + ex.getMessage(), false); } try { log.info("processing now '" + specificHelper.getSql(this.tableName)[i] + "'"); checked = false; dbSpecific.readNewTable(null, specificHelper.getOwnSchema(pool), this.tableName, null, true); assertTrue("The 'publish' method has not been invoked or has been invoked with check false ('check='" + doCheck + "'", checked); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not occur when invoking readNewTable when testing nr." + i + " which is '" + sqls[i] + "' : " + ex.getMessage(), false); } } } finally { doCheck = false; } log.info("testCreateTablesWithDifferentTypes: SUCCESS"); } /** * * @throws Exception Any type is possible */ public final void testGetObjectName() throws Exception { currentMethod = new String("testGetObjectName"); log.info("Start " + currentMethod); SpecificDefault specificDefault = (SpecificDefault)dbSpecific; { String op = "CREATE TABLE"; String sql = "CREATE TABLE someName(aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = "CREATE TABLE someName (aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = "CREATE TABLE someName\n\n (aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = "CREATE TABLE someName aaa"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = "CREATE TABLE someName() "; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = " CREATE TABLE someName(aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = "\n\nCREATE TABLE someName(aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = " CREATE TABLE\n someName (aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { String op = "CREATE TABLE"; String sql = " CREATE TABLE\n someName (aaa)"; String tableName = specificDefault.getObjectName(op, sql); assertNotNull("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall not be null"); assertEquals("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "')", "someName", tableName); } { // this shall be null String op = "CREATE TABLE"; String sql = " CREATE SEQUENCE someName(aaa)"; String tableName = specificDefault.getObjectName(op, sql); if (tableName != null) assertTrue("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall be null", false); } { // this shall be null String op = "CREATE TABLE"; String sql = null; String tableName = specificDefault.getObjectName(op, sql); if (tableName != null) assertTrue("the operation of SpecificDefault.getObjectName('" + op + "',null) shall be null", false); } { // this shall be null String op = "CREATE TABLE"; String sql = ""; String tableName = specificDefault.getObjectName(op, sql); if (tableName != null) assertTrue("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall be null", false); } { // this shall be null String op = "CREATE TABLE"; String sql = " "; String tableName = specificDefault.getObjectName(op, sql); if (tableName != null) assertTrue("the operation of SpecificDefault.getObjectName('" + op + "','" + sql + "') shall be null", false); } log.info("SUCCESS"); } /** * This method tests all the sql statements. It checks the creation statements * for the different sql data types. * * @throws Exception Any type is possible */ public final void testCheckTableForCreation() throws Exception { currentMethod = new String("testCheckTableForCreation"); log.info("Start " + currentMethod); SpecificDefault specificDefault = (SpecificDefault)dbSpecific; { String sql = "CREATE TABLE repl_items values(sss)"; int ret = specificDefault.checkTableForCreation(sql); assertEquals("check the operation of SpecificDefault.checkTableForCreation('" + sql + "')", 0, ret); } { String sql = "CREATE TABLE repl_tables()"; int ret = specificDefault.checkTableForCreation(sql); assertEquals("check the operation of SpecificDefault.checkTableForCreation('" + sql + "')", 0, ret); } { String sql = "CREATE SEQUENCE repl_items values(sss) "; int ret = specificDefault.checkTableForCreation(sql); assertEquals("check the operation of SpecificDefault.checkTableForCreation('" + sql + "')", -1, ret); } { String sql = "CREATE TABLE aaaxmsjd values(sss) "; int ret = specificDefault.checkTableForCreation(sql); assertEquals("check the operation of SpecificDefault.checkTableForCreation('" + sql + "')", 1, ret); } } /** * This method tests all the sql statements. It checks the creation statements * for the different sql data types. * * @throws Exception Any type is possible */ public final void testCheckSequenceForCreation() throws Exception { currentMethod = new String("testCheckSequenceForCreation"); log.info("Start " + currentMethod); SpecificDefault specificDefault = (SpecificDefault)dbSpecific; I_DbPool pool = (I_DbPool)info.getObject("db.pool"); assertNotNull("pool must be instantiated", pool); { String sql = "CREATE SEQUENCE repl_seq values(sss)"; int ret = specificDefault.checkSequenceForCreation(sql); assertEquals("check the operation of SpecificDefault.checkSequenceForCreation('" + sql + "')", 0, ret); } { String sql = "CREATE SEQUENCE blabla values(sss)"; int ret = specificDefault.checkSequenceForCreation(sql); assertEquals("check the operation of SpecificDefault.checkTableForCreation('" + sql + "') shall be one since the sequence shall not exist", 1, ret); } { String sql = "CREATE TABLE repl_seq values(sss)"; int ret = specificDefault.checkSequenceForCreation(sql); assertEquals("check the operation of SpecificDefault.checkSequenceForCreation('" + sql + "')", -1, ret); } log.info("SUCCESS"); } public final void testSchemaWipeout() throws Exception { currentMethod = new String("testSchemaCleanup"); log.info("Start " + currentMethod); try { final String catalog = null; dbSpecific.wipeoutSchema(catalog, specificHelper.getOwnSchema(dbPool), null); } catch (Exception ex) { ex.printStackTrace(); assertTrue("An exception should not occur when testing complete schema clanup", false); } } /** * @see org.xmlBlaster.contrib.I_ChangePublisher#getJmsSession() */ public XBSession getJmsSession() { return null; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -