Package org.springframework.context.support

Examples of org.springframework.context.support.StaticApplicationContext


      // expected
    }
  }

  public void testPropertyPlaceholderConfigurerWithDefaultProperties() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("touchy", "${test}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    Properties props = new Properties();
    props.put("test", "mytest");
    pvs.addPropertyValue("properties", new Properties(props));
    ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("mytest", tb.getTouchy());
  }
View Full Code Here


    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("mytest", tb.getTouchy());
  }

  public void testPropertyPlaceholderConfigurerWithAutowireByType() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("touchy", "${test}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    pvs.addPropertyValue("target", new RuntimeBeanReference("tb"));
    ac.registerSingleton("tbProxy", ProxyFactoryBean.class, pvs);
    pvs = new MutablePropertyValues();
    Properties props = new Properties();
    props.put("test", "mytest");
    pvs.addPropertyValue("properties", new Properties(props));
    RootBeanDefinition ppcDef = new RootBeanDefinition(PropertyPlaceholderConfigurer.class, pvs);
    ppcDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
    ac.registerBeanDefinition("configurer", ppcDef);
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("mytest", tb.getTouchy());
  }
View Full Code Here

    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("mytest", tb.getTouchy());
  }

  public void testPropertyPlaceholderConfigurerWithAliases() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("touchy", "${test}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    ac.registerAlias("tb", "${myAlias}");
    ac.registerAlias("${myTarget}", "alias2");
    pvs = new MutablePropertyValues();
    Properties props = new Properties();
    props.put("test", "mytest");
    props.put("myAlias", "alias");
    props.put("myTarget", "tb");
    pvs.addPropertyValue("properties", new Properties(props));
    ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("mytest", tb.getTouchy());
    tb = (TestBean) ac.getBean("alias");
    assertEquals("mytest", tb.getTouchy());
    tb = (TestBean) ac.getBean("alias2");
    assertEquals("mytest", tb.getTouchy());
  }
View Full Code Here

    tb = (TestBean) ac.getBean("alias2");
    assertEquals("mytest", tb.getTouchy());
  }

  public void testPreferencesPlaceholderConfigurer() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("name", "${myName}");
    pvs.addPropertyValue("age", "${myAge}");
    pvs.addPropertyValue("touchy", "${myTouchy}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    Properties props = new Properties();
    props.put("myAge", "99");
    pvs.addPropertyValue("properties", props);
    ac.registerSingleton("configurer", PreferencesPlaceholderConfigurer.class, pvs);
    Preferences.systemRoot().put("myName", "myNameValue");
    Preferences.systemRoot().put("myTouchy", "myTouchyValue");
    Preferences.userRoot().put("myTouchy", "myOtherTouchyValue");
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("myNameValue", tb.getName());
    assertEquals(99, tb.getAge());
    assertEquals("myOtherTouchyValue", tb.getTouchy());
    Preferences.userRoot().remove("myTouchy");
    Preferences.systemRoot().remove("myTouchy");
View Full Code Here

    Preferences.systemRoot().remove("myTouchy");
    Preferences.systemRoot().remove("myName");
  }

  public void testPreferencesPlaceholderConfigurerWithCustomTreePaths() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("name", "${myName}");
    pvs.addPropertyValue("age", "${myAge}");
    pvs.addPropertyValue("touchy", "${myTouchy}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    Properties props = new Properties();
    props.put("myAge", "99");
    pvs.addPropertyValue("properties", props);
    pvs.addPropertyValue("systemTreePath", "mySystemPath");
    pvs.addPropertyValue("userTreePath", "myUserPath");
    ac.registerSingleton("configurer", PreferencesPlaceholderConfigurer.class, pvs);
    Preferences.systemRoot().node("mySystemPath").put("myName", "myNameValue");
    Preferences.systemRoot().node("mySystemPath").put("myTouchy", "myTouchyValue");
    Preferences.userRoot().node("myUserPath").put("myTouchy", "myOtherTouchyValue");
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("myNameValue", tb.getName());
    assertEquals(99, tb.getAge());
    assertEquals("myOtherTouchyValue", tb.getTouchy());
    Preferences.userRoot().node("myUserPath").remove("myTouchy");
    Preferences.systemRoot().node("mySystemPath").remove("myTouchy");
View Full Code Here

    Preferences.systemRoot().node("mySystemPath").remove("myTouchy");
    Preferences.systemRoot().node("mySystemPath").remove("myName");
  }

  public void testPreferencesPlaceholderConfigurerWithPathInPlaceholder() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("name", "${mypath/myName}");
    pvs.addPropertyValue("age", "${myAge}");
    pvs.addPropertyValue("touchy", "${myotherpath/myTouchy}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    Properties props = new Properties();
    props.put("myAge", "99");
    pvs.addPropertyValue("properties", props);
    pvs.addPropertyValue("systemTreePath", "mySystemPath");
    pvs.addPropertyValue("userTreePath", "myUserPath");
    ac.registerSingleton("configurer", PreferencesPlaceholderConfigurer.class, pvs);
    Preferences.systemRoot().node("mySystemPath").node("mypath").put("myName", "myNameValue");
    Preferences.systemRoot().node("mySystemPath/myotherpath").put("myTouchy", "myTouchyValue");
    Preferences.userRoot().node("myUserPath/myotherpath").put("myTouchy", "myOtherTouchyValue");
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("myNameValue", tb.getName());
    assertEquals(99, tb.getAge());
    assertEquals("myOtherTouchyValue", tb.getTouchy());
    Preferences.userRoot().node("myUserPath/myotherpath").remove("myTouchy");
    Preferences.systemRoot().node("mySystemPath/myotherpath").remove("myTouchy");
View Full Code Here

    assertEquals("baz", exp.getValue(context));
  }

  public void testResolveSpringBean() {
    MockRequestContext context = new MockRequestContext();
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.getBeanFactory().registerSingleton("testBean", new TestBean());
    ac.getBeanFactory().registerSingleton("action", new TestAction());
    ac.getBeanFactory().registerSingleton("multiAction", new FormAction(TestBean.class));
    context.getRootFlow().setApplicationContext(ac);
    context.getConversationScope().put("foo", "bar");
    Expression exp = parser.parseExpression("foo", new FluentParserContext().evaluate(RequestContext.class));
    assertEquals("bar", exp.getValue(context));
  }
View Full Code Here

    assertEquals("bar", exp.getValue(context));
  }

  public void testResolveAction() {
    MockRequestContext context = new MockRequestContext();
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.getBeanFactory().registerSingleton("testBean", new TestBean());
    ac.getBeanFactory().registerSingleton("action", new TestAction());
    context.getRootFlow().setApplicationContext(ac);
    Expression exp = parser.parseExpression("action", new FluentParserContext().evaluate(RequestContext.class));
    assertSame(ac.getBean("action"), exp.getValue(context));
  }
View Full Code Here

    assertSame(ac.getBean("action"), exp.getValue(context));
  }

  public void testResolveMultiAction() {
    MockRequestContext context = new MockRequestContext();
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.getBeanFactory().registerSingleton("multiAction", new FormAction());
    context.getRootFlow().setApplicationContext(ac);
    Expression exp = parser.parseExpression("multiAction.setupForm", new FluentParserContext()
        .evaluate(RequestContext.class));
    AnnotatedAction action = (AnnotatedAction) exp.getValue(context);
    assertSame(ac.getBean("multiAction"), action.getTargetAction());
    assertEquals("setupForm", action.getMethod());
  }
View Full Code Here

    assertEquals("bar", exp.getValue(context));
  }

  public void testResolveMessage() {
    MockRequestContext context = new MockRequestContext();
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.getStaticMessageSource().addMessage("foo", Locale.FRANCE, "bar");
    ac.refresh();
    context.getRootFlow().setApplicationContext(ac);
    context.getMockExternalContext().setLocale(Locale.FRANCE);
    Expression exp = parser.parseExpression("resourceBundle.foo", new FluentParserContext()
        .evaluate(RequestContext.class));
    assertEquals("bar", exp.getValue(context));
View Full Code Here

TOP

Related Classes of org.springframework.context.support.StaticApplicationContext

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.