01: package liquibase.parser.filter;
02:
03: import liquibase.ChangeSet;
04: import liquibase.RanChangeSet;
05: import liquibase.database.Database;
06: import liquibase.database.sql.UpdateStatement;
07: import liquibase.database.template.JdbcTemplate;
08: import liquibase.exception.JDBCException;
09: import static org.easymock.classextension.EasyMock.*;
10: import static org.junit.Assert.*;
11: import org.junit.Test;
12:
13: import java.util.ArrayList;
14: import java.util.Date;
15:
16: public class ShouldRunChangeSetFilterTest {
17:
18: @Test
19: public void accepts_noneRun() throws JDBCException {
20: Database database = createMock(Database.class);
21: expect(database.getRanChangeSetList()).andReturn(
22: new ArrayList<RanChangeSet>());
23: replay(database);
24:
25: ShouldRunChangeSetFilter filter = new ShouldRunChangeSetFilter(
26: database);
27:
28: assertTrue(filter.accepts(new ChangeSet("1", "testAuthor",
29: false, false, "path/changelog", null, null, null)));
30: }
31:
32: @Test
33: public void accepts() throws JDBCException {
34: ArrayList<RanChangeSet> ranChanges = new ArrayList<RanChangeSet>();
35: ranChanges.add(new RanChangeSet("path/changelog", "1",
36: "testAuthor", "12345", new Date(), null));
37: ranChanges.add(new RanChangeSet("path/changelog", "2",
38: "testAuthor", "12345", new Date(), null));
39:
40: Database database = createMock(Database.class);
41: expect(database.getRanChangeSetList()).andReturn(ranChanges);
42: expect(database.getDatabaseChangeLogTableName()).andReturn(
43: "DATABASECHANGELOG").anyTimes();
44: expect(database.getDefaultSchemaName()).andReturn(null)
45: .anyTimes();
46:
47: JdbcTemplate template = createMock(JdbcTemplate.class);
48: expect(database.getJdbcTemplate()).andReturn(template)
49: .anyTimes();
50: expect(template.update(isA(UpdateStatement.class)))
51: .andReturn(1).anyTimes();
52: // template.comment("Lock Database");
53: // expectLastCall();
54:
55: replay(database);
56: replay(template);
57:
58: ShouldRunChangeSetFilter filter = new ShouldRunChangeSetFilter(
59: database);
60:
61: //everything same
62: assertFalse(filter.accepts(new ChangeSet("1", "testAuthor",
63: false, false, "path/changelog", null, null, null)));
64:
65: //alwaysRun
66: assertTrue(filter.accepts(new ChangeSet("1", "testAuthor",
67: true, false, "path/changelog", null, null, null)));
68:
69: //run on change
70: assertTrue(filter.accepts(new ChangeSet("1", "testAuthor",
71: false, true, "path/changelog", null, null, null)));
72:
73: //different id
74: assertTrue(filter.accepts(new ChangeSet("3", "testAuthor",
75: false, false, "path/changelog", null, null, null)));
76:
77: //different author
78: assertTrue(filter.accepts(new ChangeSet("1", "otherAuthor",
79: false, false, "path/changelog", null, null, null)));
80:
81: //different path
82: assertTrue(filter.accepts(new ChangeSet("1", "testAuthor",
83: false, false, "other/changelog", null, null, null)));
84: }
85: }
|