View Javadoc

1   package liquibase.maven;
2   
3   import java.io.IOException;
4   import java.io.File;
5   import org.apache.maven.it.VerificationException;
6   
7   import org.apache.maven.it.Verifier;
8   import org.apache.maven.it.util.ResourceExtractor;
9   import org.junit.Test;
10  import liquibase.database.Database;
11  import liquibase.database.DatabaseConnection;
12  import liquibase.database.DatabaseFactory;
13  import liquibase.test.DatabaseTestContext;
14  import org.junit.Before;
15  import static org.junit.Assert.*;
16  
17  /**
18   * Maven integration test. Run an update executing maven as if it was ran by the user
19   * @author lujop
20   */
21  public class MavenIntegrationTest {
22      private static final String URL="jdbc:hsqldb:file:target/test-classes/maven/liquibase;shutdown=true";
23  
24      @Before
25      public void cleanDatabase() throws Exception {
26           DatabaseConnection connection = DatabaseTestContext.getInstance().getConnection(URL);
27           assertNotNull(connection);
28           Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
29           database.dropDatabaseObjects(null);
30           database.close();
31           DatabaseFactory.reset();
32      }
33  
34      @Test
35      public void testUpdate() throws Exception{        
36          Verifier verifier=createVerifier();
37  
38          verifier.executeGoal( "clean" );
39          verifier.executeGoal( "install" );
40  
41          //Verify everithing has gone well.
42          verifier.verifyErrorFreeLog();
43  
44          //Reset the streams before executing the verifier
45          verifier.resetStreams();
46      }
47      
48      @Test
49      public void testRollbackTag() throws Exception {
50          Verifier verifier= createVerifier();
51  
52  
53          verifier.executeGoal("clean");
54          verifier.executeGoal("liquibase:tag");
55          verifier.executeGoal("package"); //runs update that is bound to test phase
56          verifier.executeGoal("liquibase:rollback");
57          //If we can reupdate rollback has succeded
58          verifier.executeGoal("liquibase:update");
59  
60          //Verify everithing has gone well.
61          verifier.verifyErrorFreeLog();
62  
63          //Reset the streams before executing the verifier
64          verifier.resetStreams();
65      }
66  
67     private Verifier createVerifier() throws IOException, VerificationException {
68          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/maven" );
69  
70          //Clear any artifact created by the test project to avoid unstable test results
71          Verifier verifier = new Verifier(testDir.getAbsolutePath());
72          verifier.setAutoclean(false); //Don't do clean automatically in each executeGoal
73          verifier.deleteArtifact("org.liquibase", "liquibase-maven-integration-tests", "1.0-SNAPSHOT", "jar");
74          return verifier;
75      }
76      
77  }