Package sagan

Source Code of sagan.Dummy

package sagan;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import static org.springframework.util.StringUtils.arrayToCommaDelimitedString;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.springframework.core.env.AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME;
import static sagan.SaganProfiles.*;

public class SaganApplicationTests {

    @BeforeClass
    public static void assertClear() {
        assertThat(System.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), nullValue());
    }

    @Test(expected = IllegalStateException.class)
    public void unknownProfileSpecified() {
        activateProfiles("bogus");
        runApp();
    }

    @Test(expected = IllegalStateException.class)
    public void bothStagingAndProductionSpecified() {
        activateProfiles(STAGING, PRODUCTION);
        runApp();
    }

    @Test
    public void stagingSpecified() {
        activateProfiles(STAGING);
        assertThat(runApp().getEnvironment().acceptsProfiles(CLOUDFOUNDRY), is(true));
    }

    @Test
    public void productionSpecified() {
        activateProfiles(PRODUCTION);
        assertThat(runApp().getEnvironment().acceptsProfiles(CLOUDFOUNDRY), is(true));
    }

    @Test
    public void noProfileSpecified() {
        // activateProfiles(...);
        Environment env = runApp().getEnvironment();
        assertThat(env.acceptsProfiles(env.getDefaultProfiles()), is(true));
        assertThat(env.acceptsProfiles(CLOUDFOUNDRY), is(false));
        assertThat(env.acceptsProfiles(STANDALONE), is(true));
    }

    @After
    public void clearProperty() {
        System.clearProperty(ACTIVE_PROFILES_PROPERTY_NAME);
    }

    private ConfigurableApplicationContext runApp() {
        return new SaganApplication(Dummy.class).run();
    }

    private void activateProfiles(String... profiles) {
        System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, arrayToCommaDelimitedString(profiles));
    }

}

class Dummy {
}
TOP

Related Classes of sagan.Dummy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.