View Javadoc

1   package liquibase.dbtest.oracle;
2   
3   import liquibase.database.jvm.JdbcConnection;
4   import liquibase.dbtest.AbstractIntegrationTest;
5   import liquibase.Liquibase;
6   import liquibase.exception.ValidationFailedException;
7   import org.junit.Test;
8   import static org.junit.Assert.assertEquals;
9   import static org.junit.Assert.assertTrue;
10  
11  import java.sql.Statement;
12  import java.sql.ResultSet;
13  import java.util.Date;
14  
15  /**
16   * create tablespace liquibase2 datafile 'C:\ORACLEXE\ORADATA\XE\LIQUIBASE2.DBF' SIZE 5M autoextend on next 5M
17   */
18  public class OracleIntegrationTest extends AbstractIntegrationTest {
19  
20      private String indexOnSchemaChangeLog;
21      private String viewOnSchemaChangeLog;
22  
23      public OracleIntegrationTest() throws Exception {
24          super("oracle", "jdbc:oracle:thin:@" + getDatabaseServerHostname("Oracle") + "/XE");
25          this.indexOnSchemaChangeLog = "changelogs/oracle/complete/indexOnSchema.xml";
26          this.viewOnSchemaChangeLog = "changelogs/oracle/complete/viewOnSchema.xml";
27      }
28  
29      @Test
30      public void indexCreatedOnCorrectSchema() throws Exception {
31           if (this.getDatabase() == null) {
32              return;
33          }
34  
35          Liquibase liquibase = createLiquibase(this.indexOnSchemaChangeLog);
36          clearDatabase(liquibase);
37  
38          try {
39              liquibase.update(this.contexts);
40          } catch (ValidationFailedException e) {
41              e.printDescriptiveError(System.out);
42              throw e;
43          }
44  
45          Statement queryIndex = ((JdbcConnection) this.getDatabase().getConnection()).getUnderlyingConnection().createStatement();
46  
47          ResultSet indexOwner = queryIndex.executeQuery("SELECT owner FROM ALL_INDEXES WHERE index_name = 'IDX_BOOK_ID'");
48  
49          assertTrue(indexOwner.next());
50  
51          String owner = indexOwner.getString("owner");
52  
53          assertEquals("LIQUIBASEB",owner);
54  
55          // check that the automatically rollback now works too
56          try {
57              liquibase.rollback( new Date(0),this.contexts);
58          } catch (ValidationFailedException e) {
59              e.printDescriptiveError(System.out);
60              throw e;
61          }
62  
63  
64  
65  
66      }
67  
68      @Test
69      public void viewCreatedOnCorrectSchema() throws Exception {
70           if (this.getDatabase() == null) {
71              return;
72          }
73  
74          Liquibase liquibase = createLiquibase(this.viewOnSchemaChangeLog);
75          clearDatabase(liquibase);
76  
77          try {
78              liquibase.update(this.contexts);
79          } catch (ValidationFailedException e) {
80              e.printDescriptiveError(System.out);
81              throw e;
82          }
83  
84          Statement queryIndex = ((JdbcConnection) this.getDatabase().getConnection()).getUnderlyingConnection().createStatement();
85  
86          ResultSet indexOwner = queryIndex.executeQuery("SELECT owner FROM ALL_VIEWS WHERE view_name = 'V_BOOK2'");
87  
88          assertTrue(indexOwner.next());
89  
90          String owner = indexOwner.getString("owner");
91  
92          assertEquals("LIQUIBASEB",owner);
93  
94          // check that the automatically rollback now works too
95          try {
96              liquibase.rollback( new Date(0),this.contexts);
97          } catch (ValidationFailedException e) {
98              e.printDescriptiveError(System.out);
99              throw e;
100         }
101     }
102 
103     @Test
104     public void smartDataLoad() throws Exception {
105         if (this.getDatabase() == null) {
106             return;
107         }
108 
109         Liquibase liquibase = createLiquibase("changelogs/common/smartDataLoad.changelog.xml");
110         clearDatabase(liquibase);
111 
112         try {
113             liquibase.update(this.contexts);
114         } catch (ValidationFailedException e) {
115             e.printDescriptiveError(System.out);
116             throw e;
117         }
118 
119         // check that the automatically rollback now works too
120         try {
121             liquibase.rollback( new Date(0),this.contexts);
122         } catch (ValidationFailedException e) {
123             e.printDescriptiveError(System.out);
124             throw e;
125         }
126     }
127 }