Package org.springframework.context.annotation

Examples of org.springframework.context.annotation.AnnotationConfigApplicationContext.refresh()


    assertHasStandardEnvironment(ctx);
    ctx.setEnvironment(prodEnv);

    ctx.register(DevConfig.class);
    ctx.refresh();

    assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
  }
View Full Code Here


    assertHasStandardEnvironment(ctx);
    ctx.setEnvironment(devEnv);

    ctx.register(DevConfig.class);
    ctx.refresh();

    assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
    assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
  }
View Full Code Here

    assertHasStandardEnvironment(ctx);
    ctx.setEnvironment(prodEnv);

    ctx.register(Config.class);
    ctx.refresh();

    assertEnvironmentAwareInvoked(ctx, prodEnv);
    assertThat("should have prod bean", ctx.containsBean(PROD_BEAN_NAME), is(true));
    assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
View Full Code Here

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    StandardEnvironment derivedDevEnv = new StandardEnvironment();
    derivedDevEnv.setActiveProfiles(DERIVED_DEV_ENV_NAME);
    ctx.setEnvironment(derivedDevEnv);
    ctx.register(DerivedDevConfig.class);
    ctx.refresh();

    assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
    assertThat("should have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(true));
    assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
  }
View Full Code Here

  @Test
  public void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.setEnvironment(devEnv);
    ctx.register(DerivedDevConfig.class);
    ctx.refresh();

    assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat("should not have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(false));
    assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
  }
View Full Code Here

  @Test
  public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.refresh();
    }

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo", "bar");
View Full Code Here

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo", "bar");
      try {
        ctx.refresh();
        fail("expected missing property exception");
      }
      catch (MissingRequiredPropertiesException ex) {
      }
    }
View Full Code Here

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo");
      ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue"));
      ctx.refresh(); // should succeed
    }
  }


  private DefaultListableBeanFactory newBeanFactoryWithEnvironmentAwareBean() {
View Full Code Here

  @Test
  public void singleCacheManagerBean() throws Throwable {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SingleCacheManagerConfig.class);
    ctx.refresh();
  }

  @Test(expected = IllegalStateException.class)
  public void multipleCacheManagerBeans() throws Throwable {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
View Full Code Here

  @Test(expected = IllegalStateException.class)
  public void multipleCacheManagerBeans() throws Throwable {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(MultiCacheManagerConfig.class);
    try {
      ctx.refresh();
    }
    catch (BeanCreationException ex) {
      Throwable root = ex.getRootCause();
      assertTrue(root.getMessage().contains("beans of type CacheManager"));
      throw root;
View Full Code Here

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.