Package org.springframework.core.env

Examples of org.springframework.core.env.StandardEnvironment


  @Override
  public ApplicationContext loadContext(MergedContextConfiguration config)
      throws Exception {
    SpringApplication application = getSpringApplication();
    application.setSources(getSources(config));
    ConfigurableEnvironment environment = new StandardEnvironment();
    if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
      String profiles = StringUtils.arrayToCommaDelimitedString(config
          .getActiveProfiles());
      EnvironmentTestUtils.addEnvironment(environment, "spring.profiles.active="
          + profiles);
    }
    // Ensure @IntegrationTest properties go before external config and after system
    environment.getPropertySources()
        .addAfter(
            StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
            new MapPropertySource("integrationTest",
                getEnvironmentProperties(config)));
    application.setEnvironment(environment);
View Full Code Here


    if (this.environment != null
        && this.environment instanceof ConfigurableEnvironment) {
      sources = ((ConfigurableEnvironment) this.environment).getPropertySources();
    }
    else {
      sources = new StandardEnvironment().getPropertySources();
    }
    for (PropertySource<?> source : sources) {
      extract("", map, source);
    }
    return map;
View Full Code Here

    assertThat(AnsiOutputEnabledValue.get(), equalTo(Enabled.NEVER));
  }

  @Test
  public void disabledViaApplcationProperties() throws Exception {
    ConfigurableEnvironment environment = new StandardEnvironment();
    EnvironmentTestUtils.addEnvironment(environment, "spring.config.name:ansi");
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebEnvironment(false);
    application.setEnvironment(environment);
    application.run();
View Full Code Here

  }

  @Test
  public void overridePidFileWithSpring() throws Exception {
    File file = this.temporaryFolder.newFile();
    ConfigurableEnvironment environment = new StandardEnvironment();
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("spring.pidfile", file.getAbsolutePath());
    environment.getPropertySources().addLast(propertySource);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    ApplicationPreparedEvent event = new ApplicationPreparedEvent(
        new SpringApplication(), new String[] {}, context);
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
View Full Code Here

  }

  @Test
  public void differentEventTypes() throws Exception {
    File file = this.temporaryFolder.newFile();
    ConfigurableEnvironment environment = new StandardEnvironment();
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("spring.pidfile", file.getAbsolutePath());
    environment.getPropertySources().addLast(propertySource);
    ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(
        new SpringApplication(), new String[] {}, environment);
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
    listener.onApplicationEvent(event);
    assertThat(FileCopyUtils.copyToString(new FileReader(file)), isEmptyString());
View Full Code Here

     * method adds all the method names to map with annotation attribute value
     * as key
     */
    private static void findAnnotationMethods(final Class<? extends Annotation> annotationClass, final String attributeName)
            throws IOException {
        final String basePackagePath = ClassUtils.convertClassNameToResourcePath(new StandardEnvironment()
                .resolveRequiredPlaceholders(SEARCH_PACKAGE));
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + basePackagePath + "/" + RESOURCE_PATTERN;
        packageSearchPath = packageSearchPath.replace("//", "/"); // else it doesn't work if *.class are in WAR!!
        final Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (final Resource resource : resources) {
View Full Code Here

  @Test @Ignore
  public void testAdminFailsWithMismatchedQueue() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.setConfigLocation("org/springframework/amqp/rabbit/config/MismatchedQueueDeclarationTests-context.xml");
    StandardEnvironment env = new StandardEnvironment();
    env.addActiveProfile("basicAdmin");
    env.addActiveProfile("basic");
    context.setEnvironment(env);
    context.refresh();
    context.getBean(CachingConnectionFactory.class).createConnection();
    context.destroy();
    Channel channel = this.connectionFactory.createConnection().createChannel(false);
    channel.queueDeclarePassive("mismatch.bar");
    this.admin.deleteQueue("mismatch.bar");
    assertNotNull(this.admin.getQueueProperties("mismatch.foo"));
    assertNull(this.admin.getQueueProperties("mismatch.bar"));

    env = new StandardEnvironment();
    env.addActiveProfile("basicAdmin");
    env.addActiveProfile("ttl");
    context.setEnvironment(env);
    context.refresh();
    channel = this.connectionFactory.createConnection().createChannel(false);
    try {
      context.getBean(CachingConnectionFactory.class).createConnection();
View Full Code Here

  @Test
  public void testAdminSkipsMismatchedQueue() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.setConfigLocation("org/springframework/amqp/rabbit/config/MismatchedQueueDeclarationTests-context.xml");
    StandardEnvironment env = new StandardEnvironment();
    env.addActiveProfile("advancedAdmin");
    env.addActiveProfile("basic");
    context.setEnvironment(env);
    context.refresh();
    context.getBean(CachingConnectionFactory.class).createConnection();
    context.destroy();
    Channel channel = this.connectionFactory.createConnection().createChannel(false);
    channel.queueDeclarePassive("mismatch.bar");
    this.admin.deleteQueue("mismatch.bar");
    assertNotNull(this.admin.getQueueProperties("mismatch.foo"));
    assertNull(this.admin.getQueueProperties("mismatch.bar"));

    env = new StandardEnvironment();
    env.addActiveProfile("advancedAdmin");
    env.addActiveProfile("ttl");
    context.setEnvironment(env);
    context.refresh();
    channel = this.connectionFactory.createConnection().createChannel(false);
    context.getBean(CachingConnectionFactory.class).createConnection();
    assertNotNull(this.admin.getQueueProperties("mismatch.foo"));
View Full Code Here

TOP

Related Classes of org.springframework.core.env.StandardEnvironment

Copyright © 2018 www.massapicom. 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.