package liquibase.integration.cdi;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Unit tests for CDILiquibaseTest
 *
 *  @author Aaron Walker (http://github.com/aaronwalker)
 */
public class CDILiquibaseTest {


    @Test
    public void shouldntRunWhenShouldRunIsFalse() {
        System.setProperty("liquibase.shouldRun", "false");
        WeldContainer weld = new Weld().initialize();
        CDILiquibase cdiLiquibase = weld.instance().select(CDILiquibase.class).get();
        assertNotNull(cdiLiquibase);
        assertFalse(cdiLiquibase.isInitialized());
        assertFalse(cdiLiquibase.isUpdateSuccessful());
    }

    @Test
    public void shouldRunWhenShouldRunIsTrue() {
        System.setProperty("liquibase.shouldRun", "true");
        WeldContainer weld = new Weld().initialize();
        CDILiquibase cdiLiquibase = weld.instance().select(CDILiquibase.class).get();
        assertNotNull(cdiLiquibase);
        assertTrue(cdiLiquibase.isInitialized());
        assertTrue(cdiLiquibase.isUpdateSuccessful());
    }
}

@@ -29,16 +29,71 @@
 n.cdi;%0A%0A
+import liquibase.configuration.LiquibaseConfiguration;%0A
 import o
@@ -127,16 +127,16 @@
 e.Weld;%0A
-
 import o
@@ -179,16 +179,65 @@
 tainer;%0A
+import org.junit.After;%0Aimport org.junit.Before;%0A
 import o
@@ -423,16 +423,186 @@
 Test %7B%0A%0A
+    @Before%0A    @After%0A    public void clearProperty() %7B%0A        System.clearProperty(%22liquibase.shouldRun%22);%0A        LiquibaseConfiguration.getInstance().reset();%0A    %7D%0A
 %0A    @Te

Clear test state in CDILiquibaseTest