// Path: vault-upgrade-hook/src/main/java/biz/netcentric/vlt/upgrade/UpgradeInfo.java
// public enum InstallationMode {
//     /**
//      * Run all new or changed actions.
//      */
//     ON_CHANGE,
// 
//     /**
//      * Completely disregarding previous executions.
//      */
//     ALWAYS
// }
// 
// Path: vault-upgrade-hook/src/main/java/biz/netcentric/vlt/upgrade/handler/UpgradeHandler.java
// public interface UpgradeHandler {
// 
//     /**
//      * Is called to check if all requirements are met to create and run
//      * {@link UpgradeAction}s provided by this handler.
//      * 
//      * @return
//      */
//     boolean isAvailable(InstallContext ctx);
// 
//     /**
//      * Called by {@link UpgradeInfo} to get the {@link UpgradeAction}s which are
//      * configured in the content package.
//      * 
//      * @param ctx
//      * @param info
//      * @return
//      * @throws RepositoryException
//      */
//     Iterable<UpgradeAction> create(InstallContext ctx, UpgradeInfo info) throws RepositoryException;
// 
// }


import java.util.Arrays;
import javax.jcr.Node;
import javax.jcr.Session;
import org.apache.jackrabbit.vault.packaging.InstallContext;
import org.apache.jackrabbit.vault.packaging.InstallContext.Phase;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.internal.util.MockUtil;
import org.mockito.runners.MockitoJUnitRunner;
import biz.netcentric.vlt.upgrade.UpgradeInfo.InstallationMode;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;
        );
        Node node = session.getNode("/test");
        UpgradeInfo info = new UpgradeInfo(ctx, status, node);
        info.loadActions(ctx);

        Assert.assertEquals(InstallationMode.ALWAYS, info.getInstallationMode());
        Assert.assertEquals(Phase.PREPARE, info.getDefaultPhase());
        Assert.assertTrue(info.getHandler() instanceof TestHandler);
        Assert.assertTrue(info.getRunModes().contains("publish"));
    }

    @Test
    public void testConstructorWithRunModes() throws Exception {
        sling.build().resource("/test", //
                UpgradeInfo.PN_INSTALLATION_MODE, "always", //
                UpgradeInfo.PN_DEFAULT_PHASE, "prepare", //
                UpgradeInfo.PN_HANDLER, TEST_HANDLER, //
                UpgradeInfo.PN_RUNMODES, new String[] { "publish", "author" } //
        );
        Node node = session.getNode("/test");
        UpgradeInfo info = new UpgradeInfo(ctx, status, node);
        info.loadActions(ctx);

        Assert.assertEquals(InstallationMode.ALWAYS, info.getInstallationMode());
        Assert.assertEquals(Phase.PREPARE, info.getDefaultPhase());
        Assert.assertTrue(info.getHandler() instanceof TestHandler);
        Assert.assertTrue(info.getRunModes().contains("publish"));
        Assert.assertTrue(info.getRunModes().contains("author"));
    }

// Path: vault-upgrade-hook/src/main/java/biz/netcentric/vlt/upgrade/UpgradeInfo.java
// public enum InstallationMode {
//     /**
//      * Run all new or changed actions.
//      */
//     ON_CHANGE,
// 
//     /**
//      * Completely disregarding previous executions.
//      */
//     ALWAYS
// }
// 
// Path: vault-upgrade-hook/src/main/java/biz/netcentric/vlt/upgrade/handler/UpgradeHandler.java
// public interface UpgradeHandler {
// 
//     /**
//      * Is called to check if all requirements are met to create and run
//      * {@link UpgradeAction}s provided by this handler.
//      * 
//      * @return
//      */
//     boolean isAvailable(InstallContext ctx);
// 
//     /**
//      * Called by {@link UpgradeInfo} to get the {@link UpgradeAction}s which are
//      * configured in the content package.
//      * 
//      * @param ctx
//      * @param info
//      * @return
//      * @throws RepositoryException
//      */
//     Iterable<UpgradeAction> create(InstallContext ctx, UpgradeInfo info) throws RepositoryException;
// 
// }


// Path: vault-upgrade-hook/src/test/java/biz/netcentric/vlt/upgrade/UpgradeInfoTest.java
import java.util.Arrays;
import javax.jcr.Node;
import javax.jcr.Session;
import org.apache.jackrabbit.vault.packaging.InstallContext;
import org.apache.jackrabbit.vault.packaging.InstallContext.Phase;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.internal.util.MockUtil;
import org.mockito.runners.MockitoJUnitRunner;
import biz.netcentric.vlt.upgrade.UpgradeInfo.InstallationMode;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;

        );
        Node node = session.getNode("/test");
        UpgradeInfo info = new UpgradeInfo(ctx, status, node);
        info.loadActions(ctx);

        Assert.assertEquals(InstallationMode.ALWAYS, info.getInstallationMode());
        Assert.assertEquals(Phase.PREPARE, info.getDefaultPhase());
        Assert.assertTrue(info.getHandler() instanceof TestHandler);
        Assert.assertTrue(info.getRunModes().contains("publish"));
    }

    @Test
    public void testConstructorWithRunModes() throws Exception {
        sling.build().resource("/test", //
                UpgradeInfo.PN_INSTALLATION_MODE, "always", //
                UpgradeInfo.PN_DEFAULT_PHASE, "prepare", //
                UpgradeInfo.PN_HANDLER, TEST_HANDLER, //
                UpgradeInfo.PN_RUNMODES, new String[] { "publish", "author" } //
        );
        Node node = session.getNode("/test");
        UpgradeInfo info = new UpgradeInfo(ctx, status, node);
        info.loadActions(ctx);

        Assert.assertEquals(InstallationMode.ALWAYS, info.getInstallationMode());
        Assert.assertEquals(Phase.PREPARE, info.getDefaultPhase());
        Assert.assertTrue(info.getHandler() instanceof TestHandler);
        Assert.assertTrue(info.getRunModes().contains("publish"));
        Assert.assertTrue(info.getRunModes().contains("author"));
    }

    public static class TestHandler implements UpgradeHandler {