Examples of StaticApplicationContext


Examples of org.springframework.context.support.StaticApplicationContext

      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

Examples of org.springframework.context.support.StaticApplicationContext

  public void testPropertyPlaceholderConfigurerWithParentChildSeparation() {
    doTestPropertyPlaceholderConfigurer(true);
  }

  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");
    TestBean tb2 = (TestBean) ac.getBean("tb2");
    assertEquals(98, tb1.getAge());
    assertEquals(98, tb2.getAge());
    assertEquals("namemyvarmyvar${", tb1.getName());
    assertEquals("myvarname98", tb2.getName());
    assertEquals(tb2, tb1.getSpouse());
View Full Code Here

Examples of org.springframework.context.support.StaticApplicationContext

    assertEquals("namemyvarmyvar${", inner2.getName());
    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

Examples of org.springframework.context.support.StaticApplicationContext

    TestBean tb = (TestBean) ac.getBean("tb");
    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

Examples of org.springframework.context.support.StaticApplicationContext

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

  public void testPropertyPlaceholderConfigurerWithOverridingSystemProperty() {
    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);
    pvs.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_OVERRIDE");
    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

Examples of org.springframework.context.support.StaticApplicationContext

    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals(System.getProperty("os.name"), tb.getTouchy());
  }

  public void testPropertyPlaceholderConfigurerWithUnresolvableSystemProperty() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("touchy", "${user.dir}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    pvs.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_NEVER");
    ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
    try {
      ac.refresh();
      fail("Should have thrown BeanDefinitionStoreException");
    }
    catch (BeanDefinitionStoreException ex) {
      // expected
      assertTrue(ex.getMessage().indexOf("user.dir") != -1);
View Full Code Here

Examples of org.springframework.context.support.StaticApplicationContext

      assertTrue(ex.getMessage().indexOf("user.dir") != -1);
    }
  }

  public void testPropertyPlaceholderConfigurerWithUnresolvablePlaceholder() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("name", "${ref}");
    ac.registerSingleton("tb", TestBean.class, pvs);
    ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, null);
    try {
      ac.refresh();
      fail("Should have thrown BeanDefinitionStoreException");
    }
    catch (BeanDefinitionStoreException ex) {
      // expected
      assertTrue(ex.getMessage().indexOf("ref") != -1);
View Full Code Here

Examples of org.springframework.context.support.StaticApplicationContext

    assertEquals(1, messages.getAllMessages().length);
    assertEquals(1, messages.getMessagesBySource("validationcontext").length);
  }

  public void testValidateWithMessageContextForBeanValidator() {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("modelValidator", StubModelMessageContext.class);
    ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
    ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, null);
    helper.validate();
    MessageContext messages = requestContext.getMessageContext();
    assertEquals(1, messages.getAllMessages().length);
View Full Code Here

Examples of org.springframework.context.support.StaticApplicationContext

    assertEquals(1, messages.getAllMessages().length);
    assertEquals(1, messages.getMessagesBySource("messagecontext-external").length);
  }

  public void testValidateWithValidationContextForBeanValidator() {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("modelValidator", StubModelValidationContext.class);
    ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
    ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, null);
    helper.validate();
    MessageContext messages = requestContext.getMessageContext();
    assertEquals(1, messages.getAllMessages().length);
View Full Code Here

Examples of org.springframework.context.support.StaticApplicationContext

    assertEquals(1, messages.getAllMessages().length);
    assertEquals(1, messages.getMessagesBySource("validationcontext-external").length);
  }

  public void testValidateWithErrorsForBeanValidator() {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("modelValidator", StubModelErrors.class);
    ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
    ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, null);
    helper.validate();
    MessageContext messages = requestContext.getMessageContext();
    assertEquals(1, messages.getAllMessages().length);
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.