ReactiveTrigger { String getCreateSql() { String triggerSql = format(CREATE_TRIGGER_TEMPLATE, triggerName, triggerTime, triggerEvent, triggerTable); String mainBody = MAIN_BODY_TEMPLATE .replace("{oldJson}", oldJson()) .replace("{newJson}", newJson()) .replace("{tableName}", triggerTable) .replace("{eventType}", triggerEvent.toString()); return triggerSql.replace("{mainBody}", mainBody); } ReactiveTrigger(String triggerName, String triggerTable, TriggerEvent triggerEvent, TriggerTime triggerTime,
                    List<String> tableColumns); String getDropSql();  }
@Test(groups = SMALL) public void testGetCreateSqlContainsTheTriggerAttributes() { String triggerSql = reactiveTrigger.getCreateSql(); assertTrue(triggerSql.contains(TRIGGER_NAME)); assertTrue(triggerSql.contains("'" + TRIGGER_TABLE + "'")); assertTrue(triggerSql.contains(TRIGGER_TABLE)); assertTrue(triggerSql.contains(INSERT.toString())); assertTrue(triggerSql.contains("'" + INSERT.toString() + "'")); assertTrue(triggerSql.contains(AFTER.toString())); }
@Test(groups = SMALL) public void testGetCreateSqlContainsOnlyNewColumnValuesForInsert() { ReactiveTrigger trigger = new ReactiveTrigger(TRIGGER_NAME, TRIGGER_TABLE, INSERT, AFTER, TABLE_COLS); String triggerSql = trigger.getCreateSql(); assertTrue(triggerSql.contains("NEW.ID")); assertTrue(triggerSql.contains("NEW.TXT")); assertFalse(triggerSql.contains("OLD.ID")); assertFalse(triggerSql.contains("OLD.TXT")); }
@Test(groups = SMALL) public void testGetCreateSqlContainsOnlyOldColumnValuesForDelete() { ReactiveTrigger trigger = new ReactiveTrigger(TRIGGER_NAME, TRIGGER_TABLE, DELETE, AFTER, TABLE_COLS); String triggerSql = trigger.getCreateSql(); assertFalse(triggerSql.contains("NEW.ID")); assertFalse(triggerSql.contains("NEW.TXT")); assertTrue(triggerSql.contains("OLD.ID")); assertTrue(triggerSql.contains("OLD.TXT")); }
@Test(groups = SMALL) public void testGetCreateSqlContainsBothOldAndNewColumnValuesForUpdate() { ReactiveTrigger trigger = new ReactiveTrigger(TRIGGER_NAME, TRIGGER_TABLE, UPDATE, AFTER, TABLE_COLS); String triggerSql = trigger.getCreateSql(); assertTrue(triggerSql.contains("NEW.ID")); assertTrue(triggerSql.contains("NEW.TXT")); assertTrue(triggerSql.contains("OLD.ID")); assertTrue(triggerSql.contains("OLD.TXT")); }