Search in sources :

Example 1 with ProjectStageProducer

use of org.apache.deltaspike.core.util.ProjectStageProducer in project deltaspike by apache.

the class ProjectStageProducerTest method testProjectStageSetByEnvironment.

/**
     * Test a ProjectStage which got set by the <i>javax.faces.ProjectStage</i>
     */
@Test
public void testProjectStageSetByEnvironment() {
    String[] oldEnvVals = new String[ProjectStageProducer.CONFIG_SETTING_KEYS.length];
    for (int i = 0; i < ProjectStageProducer.CONFIG_SETTING_KEYS.length; i++) {
        String envName = ProjectStageProducer.CONFIG_SETTING_KEYS[i];
        oldEnvVals[i] = "" + System.getProperty(envName);
        // and also clean them now
        System.setProperty(ProjectStageProducer.CONFIG_SETTING_KEYS[i], "");
    }
    try {
        for (int i = 0; i < ProjectStageProducer.CONFIG_SETTING_KEYS.length; i++) {
            String envName = ProjectStageProducer.CONFIG_SETTING_KEYS[i];
            System.setProperty(envName, "SystemTest");
            ProjectStageProducer psp = ProjectStageProducer.getInstance();
            Assert.assertNotNull(psp);
            ProjectStageProducer.setProjectStage(null);
            ProjectStage ps = psp.getProjectStage();
            Assert.assertNotNull(ps);
            Assert.assertEquals(ps, ProjectStage.SystemTest);
            Assert.assertTrue(ps == ProjectStage.SystemTest);
            ProjectStageProducer.setProjectStage(null);
            System.setProperty(envName, "IntegrationTest");
            ps = psp.getProjectStage();
            Assert.assertNotNull(ps);
            Assert.assertEquals(ps, ProjectStage.IntegrationTest);
            Assert.assertTrue(ps == ProjectStage.IntegrationTest);
            System.setProperty(envName, "");
        }
    } finally {
        // restore the old env values
        for (int i = 0; i < ProjectStageProducer.CONFIG_SETTING_KEYS.length; i++) {
            System.setProperty(ProjectStageProducer.CONFIG_SETTING_KEYS[i], oldEnvVals[i]);
        }
    }
}
Also used : ProjectStageProducer(org.apache.deltaspike.core.util.ProjectStageProducer) ProjectStage(org.apache.deltaspike.core.api.projectstage.ProjectStage) Test(org.junit.Test)

Aggregations

ProjectStage (org.apache.deltaspike.core.api.projectstage.ProjectStage)1 ProjectStageProducer (org.apache.deltaspike.core.util.ProjectStageProducer)1 Test (org.junit.Test)1