Package org.springframework.context.support

Examples of org.springframework.context.support.StaticApplicationContext


    assertEquals(null, tb1.getName());
    assertEquals("test", tb2.getName());
  }

  public void testPropertyOverrideConfigurerWithNestedProperty() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb.array[0].age=99\ntb.list[1].name=test");
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here


    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }

  public void testPropertyOverrideConfigurerWithNestedPropertyAndDotInBeanName() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("my.tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "my.tb_array[0].age=99\nmy.tb_list[1].name=test");
    pvs.addPropertyValue("beanNameSeparator", "_");
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("my.tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }

  public void testPropertyOverrideConfigurerWithNestedMapPropertyAndDotInMapKey() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb.map[key1]=99\ntb.map[key2.ext]=test");
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("tb");
    assertEquals("99", tb.getMap().get("key1"));
    assertEquals("test", tb.getMap().get("key2.ext"));
  }
View Full Code Here

    assertEquals("99", tb.getMap().get("key1"));
    assertEquals("test", tb.getMap().get("key2.ext"));
  }

  public void testPropertyOverrideConfigurerWithJavaMailProperties() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", JavaMailSenderImpl.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb.javaMailProperties[mail.smtp.auth]=true");
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    JavaMailSenderImpl tb = (JavaMailSenderImpl) ac.getBean("tb");
    assertEquals("true", tb.getJavaMailProperties().getProperty("mail.smtp.auth"));
  }
View Full Code Here

    JavaMailSenderImpl tb = (JavaMailSenderImpl) ac.getBean("tb");
    assertEquals("true", tb.getJavaMailProperties().getProperty("mail.smtp.auth"));
  }

  public void testPropertyOverrideConfigurerWithPropertiesFile() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("location", "classpath:org/springframework/beans/factory/config/test.properties");
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }

  public void testPropertyOverrideConfigurerWithInvalidPropertiesFile() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("locations",
        new String[] {"classpath:org/springframework/beans/factory/config/test.properties",
                      "classpath:org/springframework/beans/factory/config/xtest.properties"});
    pvs.addPropertyValue("ignoreResourceNotFound", Boolean.TRUE);
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    // ignore for JDK < 1.5
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
      return;
    }

    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("location", "classpath:org/springframework/beans/factory/config/test-properties.xml");
    ac.registerSingleton("configurer", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }

  public void testPropertyOverrideConfigurerWithConvertProperties() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb", IndexedTestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb.array[0].name=99\ntb.list[1].name=test");
    ac.registerSingleton("configurer", ConvertingOverrideConfigurer.class, pvs);
    ac.refresh();
    IndexedTestBean tb = (IndexedTestBean) ac.getBean("tb");
    assertEquals("X99", tb.getArray()[0].getName());
    assertEquals("Xtest", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    assertEquals("X99", tb.getArray()[0].getName());
    assertEquals("Xtest", ((TestBean) tb.getList().get(1)).getName());
  }

  public void testPropertyOverrideConfigurerWithInvalidKey() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb1", TestBean.class);
    ac.registerSingleton("tb2", TestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "argh=hgra\ntb1.age=99\ntb2.name=test");
    pvs.addPropertyValue("ignoreInvalidKeys", "true");
    ac.registerSingleton("configurer1", PropertyOverrideConfigurer.class, pvs);
    pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb2.age=99\ntb2.name=test2");
    pvs.addPropertyValue("order", "0");
    ac.registerSingleton("configurer2", PropertyOverrideConfigurer.class, pvs);
    try {
      ac.refresh();
    }
    catch (BeanInitializationException ex) {
      assertTrue(ex.getMessage().toLowerCase().indexOf("argh") != -1);
    }
  }
View Full Code Here

      assertTrue(ex.getMessage().toLowerCase().indexOf("argh") != -1);
    }
  }

  public void testPropertyOverrideConfigurerWithIgnoreInvalidKeys() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb1", TestBean.class);
    ac.registerSingleton("tb2", TestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "argh=hgra\ntb1.age=99\ntb2.name=test");
    pvs.addPropertyValue("ignoreInvalidKeys", "true");
    ac.registerSingleton("configurer1", PropertyOverrideConfigurer.class, pvs);
    pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb2.age=99\ntb2.name=test2");
    pvs.addPropertyValue("order", "0");
    ac.registerSingleton("configurer2", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    TestBean tb1 = (TestBean) ac.getBean("tb1");
    TestBean tb2 = (TestBean) ac.getBean("tb2");
    assertEquals(99, tb1.getAge());
    assertEquals(99, tb2.getAge());
    assertEquals(null, tb1.getName());
    assertEquals("test", tb2.getName());
  }
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.