Search in sources :

Example 21 with PropertyValue

use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.

the class GenericFilterBean method getFilterConfigPropertyValues.

/**
 * @param config the FilterConfig we'll use to take PropertyValues from
 * @param requiredProperties set of property names we need, where
 * we can't accept default values
 * @return PropertyValues
 * @throws ServletException if any required properties are missing
 */
private PropertyValues getFilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties) throws ServletException {
    PropertyValues propertyValues = new PropertyValues();
    Set<String> missingProps = CollectionUtils.isNotEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null;
    Enumeration<String> paramNames = config.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String property = paramNames.nextElement();
        Object value = config.getInitParameter(property);
        propertyValues.add(new PropertyValue(property, value));
        if (missingProps != null) {
            missingProps.remove(property);
        }
    }
    // Fail if we are still missing properties.
    if (CollectionUtils.isNotEmpty(missingProps)) {
        throw new ServletException("Initialization from FilterConfig for filter '" + config.getFilterName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", "));
    }
    return propertyValues;
}
Also used : ServletException(jakarta.servlet.ServletException) NestedServletException(cn.taketoday.web.servlet.NestedServletException) PropertyValues(cn.taketoday.beans.PropertyValues) PropertyValue(cn.taketoday.beans.PropertyValue)

Example 22 with PropertyValue

use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.

the class MixinProxyTargetClassTrueConfig method testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory.

@Test
public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() {
    ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
    GenericApplicationContext childAc = new GenericApplicationContext(ac);
    // Create a child factory with a bean that should be woven
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    bd.getPropertyValues().add(new PropertyValue("name", "Adrian")).add(new PropertyValue("age", 34));
    childAc.registerBeanDefinition("adrian2", bd);
    // Register the advisor auto proxy creator with subclass
    childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class));
    childAc.refresh();
    ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2");
    // testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian"));
    doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) GenericApplicationContext(cn.taketoday.context.support.GenericApplicationContext) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) AnnotationAwareAspectJAutoProxyCreator(cn.taketoday.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) PropertyValue(cn.taketoday.beans.PropertyValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with PropertyValue

use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.

the class CustomEditorTests method testComplexObjectWithOldValueAccess.

@Test
void testComplexObjectWithOldValueAccess() {
    TestBean tb = new TestBean();
    String newName = "Rod";
    String tbString = "Kerry_34";
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.setExtractOldValueForEditor(true);
    bw.registerCustomEditor(ITestBean.class, new OldValueAccessingTestBeanEditor());
    PropertyValues pvs = new PropertyValues();
    pvs.add(new PropertyValue("age", 55));
    pvs.add(new PropertyValue("name", newName));
    pvs.add(new PropertyValue("touchy", "valid"));
    pvs.add(new PropertyValue("spouse", tbString));
    bw.setPropertyValues(pvs);
    assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
    assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
    ITestBean spouse = tb.getSpouse();
    bw.setPropertyValues(pvs);
    assertThat(tb.getSpouse()).as("Should have remained same object").isSameAs(spouse);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) BeanWrapper(cn.taketoday.beans.BeanWrapper) PropertyValues(cn.taketoday.beans.PropertyValues) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) BooleanTestBean(cn.taketoday.beans.BooleanTestBean) NumberTestBean(cn.taketoday.beans.NumberTestBean) PropertyValue(cn.taketoday.beans.PropertyValue) Test(org.junit.jupiter.api.Test)

Example 24 with PropertyValue

use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.

the class CustomEditorTests method testComplexObject.

@Test
void testComplexObject() {
    TestBean tb = new TestBean();
    String newName = "Rod";
    String tbString = "Kerry_34";
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(ITestBean.class, new TestBeanEditor());
    PropertyValues pvs = new PropertyValues();
    pvs.add(new PropertyValue("age", 55));
    pvs.add(new PropertyValue("name", newName));
    pvs.add(new PropertyValue("touchy", "valid"));
    pvs.add(new PropertyValue("spouse", tbString));
    bw.setPropertyValues(pvs);
    assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
    assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
}
Also used : BeanWrapper(cn.taketoday.beans.BeanWrapper) PropertyValues(cn.taketoday.beans.PropertyValues) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) BooleanTestBean(cn.taketoday.beans.BooleanTestBean) NumberTestBean(cn.taketoday.beans.NumberTestBean) PropertyValue(cn.taketoday.beans.PropertyValue) Test(org.junit.jupiter.api.Test)

Example 25 with PropertyValue

use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.

the class JdbcNamespaceIntegrationTests method assertBeanPropertyValueOf.

private void assertBeanPropertyValueOf(String propertyName, String expected, StandardBeanFactory factory) {
    BeanDefinition bean = factory.getBeanDefinition(expected);
    PropertyValue value = bean.getPropertyValues().get(propertyName);
    assertThat(value).isNotNull();
    assertThat(value.getValue().toString()).isEqualTo(expected);
}
Also used : PropertyValue(cn.taketoday.beans.PropertyValue) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition)

Aggregations

PropertyValue (cn.taketoday.beans.PropertyValue)46 PropertyValues (cn.taketoday.beans.PropertyValues)28 Test (org.junit.jupiter.api.Test)22 ConfigurablePropertyAccessor (cn.taketoday.beans.ConfigurablePropertyAccessor)6 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)6 MultiValueMap (cn.taketoday.core.MultiValueMap)6 List (java.util.List)6 Map (java.util.Map)6 BeanMetadata (cn.taketoday.beans.BeanMetadata)4 BeanWrapper (cn.taketoday.beans.BeanWrapper)4 BeanWrapperImpl (cn.taketoday.beans.BeanWrapperImpl)4 BooleanTestBean (cn.taketoday.beans.BooleanTestBean)4 NumberTestBean (cn.taketoday.beans.NumberTestBean)4 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)4 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)4 Nullable (cn.taketoday.lang.Nullable)4 RequestContextDataBinder (cn.taketoday.web.bind.RequestContextDataBinder)4 ArrayList (java.util.ArrayList)4 AnnotationAwareAspectJAutoProxyCreator (cn.taketoday.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator)2