View Javadoc

1   package liquibase.changelog;
2   
3   import liquibase.change.CheckSum;
4   import liquibase.change.core.AddDefaultValueChange;
5   import liquibase.change.core.CreateTableChange;
6   import liquibase.change.core.InsertDataChange;
7   import static org.junit.Assert.*;
8   import org.junit.Test;
9   
10  /**
11   * Tests for {@link liquibase.changelog.ChangeSet}
12   */
13  public class ChangeSetTest {
14  
15      @Test
16      public void getDescriptions() {
17          ChangeSet changeSet = new ChangeSet("testId", "testAuthor", false, false,null, null, null);
18  
19          assertEquals("Empty", changeSet.getDescription());
20  
21          changeSet.addChange(new InsertDataChange());
22          assertEquals("Insert Row", changeSet.getDescription());
23  
24          changeSet.addChange(new InsertDataChange());
25          assertEquals("Insert Row (x2)", changeSet.getDescription());
26  
27          changeSet.addChange(new CreateTableChange());
28          assertEquals("Insert Row (x2), Create Table", changeSet.getDescription());
29      }
30      
31      @Test
32      public void generateCheckSum() {
33          ChangeSet changeSet1 = new ChangeSet("testId", "testAuthor", false, false,null, null, null);
34          ChangeSet changeSet2 = new ChangeSet("testId", "testAuthor", false, false,null, null, null);
35  
36          AddDefaultValueChange change = new AddDefaultValueChange();
37          change.setSchemaName("SCHEMA_NAME");
38          change.setTableName("TABLE_NAME");
39          change.setColumnName("COLUMN_NAME");
40          change.setDefaultValue("DEF STRING");
41          change.setDefaultValueNumeric("42");
42          change.setDefaultValueBoolean(true);
43          change.setDefaultValueDate("2007-01-02");
44  
45          changeSet1.addChange(change);
46          changeSet2.addChange(change);
47  
48          CheckSum md5Sum1 = changeSet1.generateCheckSum();
49  
50          change.setSchemaName("SCHEMA_NAME2");
51          CheckSum md5Sum2 = changeSet2.generateCheckSum();
52          assertFalse(md5Sum1.equals(md5Sum2));
53      }
54  
55      @Test
56      public void isCheckSumValid_validCheckSum() {
57          ChangeSet changeSet = new ChangeSet("1", "2",false, false, "/test.xml",null, null);
58          CheckSum checkSum = changeSet.generateCheckSum();
59  
60          assertTrue(changeSet.isCheckSumValid(checkSum));
61      }
62  
63      @Test
64      public void isCheckSumValid_invalidCheckSum() {
65          CheckSum checkSum = CheckSum.parse("2:asdf");
66  
67          ChangeSet changeSet = new ChangeSet("1", "2",false, false, "/test.xml",null, null);
68          assertFalse(changeSet.isCheckSumValid(checkSum));
69      }
70  
71      @Test
72      public void isCheckSumValid_differentButValidCheckSum() {
73          CheckSum checkSum = CheckSum.parse("2:asdf");
74  
75          ChangeSet changeSet = new ChangeSet("1", "2",false, false, "/test.xml",null, null);
76          changeSet.addValidCheckSum(changeSet.generateCheckSum().toString());
77  
78          assertTrue(changeSet.isCheckSumValid(checkSum));
79      }
80  }