01: package liquibase.parser.visitor;
02:
03: import liquibase.ChangeSet;
04: import liquibase.RanChangeSet;
05: import liquibase.change.CreateTableChange;
06: import liquibase.exception.SetupException;
07: import static org.junit.Assert.*;
08: import org.junit.Before;
09: import org.junit.Test;
10:
11: import java.util.ArrayList;
12:
13: public class ValidatingVisitorTest {
14:
15: private ChangeSet changeSet1;
16: private ChangeSet changeSet2;
17:
18: @Before
19: public void setup() {
20: changeSet1 = new ChangeSet("1", "testAuthor", false, false,
21: "path/changelog", null, null, null);
22: changeSet2 = new ChangeSet("2", "testAuthor", false, false,
23: "path/changelog", null, null, null);
24: }
25:
26: @Test
27: public void visit_successful() {
28: changeSet1.addChange(new CreateTableChange());
29: changeSet2.addChange(new CreateTableChange());
30:
31: ValidatingVisitor handler = new ValidatingVisitor(
32: new ArrayList<RanChangeSet>());
33: handler.visit(changeSet1);
34: handler.visit(changeSet2);
35:
36: assertTrue(handler.validationPassed());
37:
38: }
39:
40: @Test
41: public void visit_setupException() {
42: changeSet1.addChange(new CreateTableChange() {
43: public void setUp() throws SetupException {
44: throw new SetupException("Test message");
45: }
46: });
47:
48: ValidatingVisitor handler = new ValidatingVisitor(
49: new ArrayList<RanChangeSet>());
50: handler.visit(changeSet1);
51:
52: assertEquals(1, handler.getSetupExceptions().size());
53: assertEquals("Test message", handler.getSetupExceptions()
54: .get(0).getMessage());
55:
56: assertFalse(handler.validationPassed());
57: }
58:
59: @Test
60: public void visit_duplicate() {
61:
62: ValidatingVisitor handler = new ValidatingVisitor(
63: new ArrayList<RanChangeSet>());
64: handler.visit(changeSet1);
65: handler.visit(changeSet1);
66:
67: assertEquals(1, handler.getDuplicateChangeSets().size());
68:
69: assertFalse(handler.validationPassed());
70: }
71: }
|