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]);
}
}
}
Aggregations