Package org.springframework.beans

Examples of org.springframework.beans.MutablePropertyValues


  }

  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


  }

  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

  }

  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

      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

  }

  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

  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) {
View Full Code Here

  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());
View Full Code Here

  private void doTestPropertyPlaceholderConfigurer(boolean parentChildSeparation) {
    StaticApplicationContext ac = new StaticApplicationContext();

    if (parentChildSeparation) {
      MutablePropertyValues pvs1 = new MutablePropertyValues();
      pvs1.addPropertyValue("age", "${age}");
      MutablePropertyValues pvs2 = new MutablePropertyValues();
      pvs2.addPropertyValue("name", "name${var}${var}${");
      pvs2.addPropertyValue("spouse", new RuntimeBeanReference("${ref}"));

      RootBeanDefinition parent = new RootBeanDefinition(TestBean.class, pvs1);
      ChildBeanDefinition bd = new ChildBeanDefinition("${parent}", pvs2);
      ac.getDefaultListableBeanFactory().registerBeanDefinition("parent1", parent);
      ac.getDefaultListableBeanFactory().registerBeanDefinition("tb1", bd);
    }
    else {
      MutablePropertyValues pvs = new MutablePropertyValues();
      pvs.addPropertyValue("age", "${age}");
      pvs.addPropertyValue("name", "name${var}${var}${");
      pvs.addPropertyValue("spouse", new RuntimeBeanReference("${ref}"));
      RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
      ac.getDefaultListableBeanFactory().registerBeanDefinition("tb1", bd);
    }

    ConstructorArgumentValues cas = new ConstructorArgumentValues();
    cas.addIndexedArgumentValue(1, "${age}");
    cas.addGenericArgumentValue("${var}name${age}");

    MutablePropertyValues pvs = new MutablePropertyValues();
    List friends = new ManagedList();
    friends.add("na${age}me");
    friends.add(new RuntimeBeanReference("${ref}"));
    pvs.addPropertyValue("friends", friends);

    Set someSet = new ManagedSet();
    someSet.add("na${age}me");
    someSet.add(new RuntimeBeanReference("${ref}"));
    someSet.add(new TypedStringValue("${age}", Integer.class));
    pvs.addPropertyValue("someSet", someSet);

    Map someMap = new ManagedMap();
    someMap.put(new TypedStringValue("key${age}"), new TypedStringValue("${age}"));
    someMap.put(new TypedStringValue("key${age}ref"), new RuntimeBeanReference("${ref}"));
    someMap.put("key1", new RuntimeBeanReference("${ref}"));
    someMap.put("key2", "${age}name");
    MutablePropertyValues innerPvs = new MutablePropertyValues();
    innerPvs.addPropertyValue("touchy", "${os.name}");
    someMap.put("key3", new RootBeanDefinition(TestBean.class, innerPvs));
    MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs);
    someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child"));
    pvs.addPropertyValue("someMap", someMap);

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, cas, pvs);
    ac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);

    pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "age=98\nvar=${m}var\nref=tb2\nm=my\nkey4=mykey4\nparent=parent1");
    ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
    ac.refresh();

    TestBean tb1 = (TestBean) ac.getBean("tb1");
View Full Code Here

    assertEquals(System.getProperty("os.name"), inner2.getTouchy());
  }

  public void testPropertyPlaceholderConfigurerWithSystemPropertyFallback() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("touchy", "${os.name}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals(System.getProperty("os.name"), tb.getTouchy());
  }
View Full Code Here

    assertEquals(System.getProperty("os.name"), tb.getTouchy());
  }

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

TOP

Related Classes of org.springframework.beans.MutablePropertyValues

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.