Example usage for org.springframework.beans.factory.config BeanDefinition getConstructorArgumentValues

List of usage examples for org.springframework.beans.factory.config BeanDefinition getConstructorArgumentValues

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config BeanDefinition getConstructorArgumentValues.

Prototype

ConstructorArgumentValues getConstructorArgumentValues();

Source Link

Document

Return the constructor argument values for this bean.

Usage

From source file:org.bigtester.ate.xmlschema.RunTimeDataHolderBeanDefinitionParser.java

/**
 * {@inheritDoc}//from w  w  w . j a  va  2s. c om
 */
@Override
protected @Nullable AbstractBeanDefinition parseInternal(@Nullable Element element,
        @Nullable ParserContext parserContext) {

    // Here we parse the Spring elements such as < property>
    if (parserContext == null || element == null)
        throw GlobalUtils.createNotInitializedException("element and parserContext");
    // Here we parse the Spring elements such as < property>

    String dataHolderType = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATAHOLDERTYPE)
            .toUpperCase();
    if (null == dataHolderType || !StringUtils.hasText(dataHolderType)) {
        throw GlobalUtils.createNotInitializedException("dataHolderType attribute in xml test case");
    }
    RumtimeDataHolderType enumDataHolderType = RumtimeDataHolderType.valueOf(dataHolderType);
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);
    BeanDefinition bDef = holder.getBeanDefinition();
    switch (enumDataHolderType) {
    case PAGESOURCEPARSED:
        bDef.setBeanClassName(PageParsedDataHolder.class.getName());
        break;
    case MANUALASSIGNED:
        bDef.setBeanClassName(ManualAssignedValueDataHolder.class.getName());
        break;
    case CASESERVICEPARSED:
        bDef.setBeanClassName(CaseServiceParsedDataHolder.class.getName());
        break;
    case STEPSERVICEPARSED:
        bDef.setBeanClassName(StepServiceParsedDataHolder.class.getName());
        break;
    case RANDOMALPHATEXT:
        bDef.setBeanClassName(RandomAlphaTextValueDataHolder.class.getName());
        break;
    case RANDOMNUMBERS:
        bDef.setBeanClassName(RandomNumericValueDataHolder.class.getName());
        break;
    case RANDOMTEXTNUMBERS:
        bDef.setBeanClassName(RandomAlphaNumericValueDataHolder.class.getName());
        break;
    case RANDOMEMAIL:
        bDef.setBeanClassName(RandomEmailDataHolder.class.getName());
        break;
    default:
        break;

    }
    String dataType = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATATYPE).toUpperCase();
    if (null != dataType && StringUtils.hasText(dataType)) {
        EnumRunTimeDataType enumDataType = EnumRunTimeDataType.valueOf(dataType);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(enumDataType);
    }

    String dataValue = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATAVALUE);
    if (StringUtils.hasText(dataValue)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(dataValue);
    }

    String leftBoundry = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_LEFTBOUNDRY);
    if (StringUtils.hasText(leftBoundry)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(leftBoundry);
    }

    String rightBoundry = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_RIGHTBOUNDRY);
    if (StringUtils.hasText(rightBoundry)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(rightBoundry);
    }

    String page = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_PAGE);
    if (StringUtils.hasText(page)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(page));
    }

    String beanID = element.getAttribute("id");
    bDef.getConstructorArgumentValues().addGenericArgumentValue(beanID);

    String mappedBeanID = element
            .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_SUBCASEMAPPEDDATAHOLDERID);
    if (StringUtils.hasText(mappedBeanID)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(mappedBeanID);
    }

    String indexOfSameTypeDataOnPage = element
            .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_INDEXOFSAMETYPEDATAONPAGE);
    if (StringUtils.hasText(indexOfSameTypeDataOnPage)) {
        int index = Integer.parseInt(indexOfSameTypeDataOnPage);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(index);
    }

    String randomTextLength = element
            .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_RANDOMINPUTLENGTH);
    if (StringUtils.hasText(randomTextLength)) {
        int length = Integer.parseInt(randomTextLength);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(length);
    }

    parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef);
    return (AbstractBeanDefinition) bDef;

}

From source file:org.eclipse.gemini.blueprint.blueprint.container.support.internal.config.CycleOrderingProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    boolean trace = log.isTraceEnabled();

    String[] names = beanFactory.getBeanDefinitionNames();
    for (String name : names) {
        BeanDefinition definition = beanFactory.getBeanDefinition(name);
        if (definition.hasAttribute(ParsingUtils.BLUEPRINT_MARKER_NAME)) {
            ConstructorArgumentValues cArgs = definition.getConstructorArgumentValues();
            if (trace)
                log.trace("Inspecting cycles for (blueprint) bean " + name);

            tag(cArgs.getGenericArgumentValues(), name, definition);
            tag(cArgs.getIndexedArgumentValues().values(), name, definition);
        }//from w w w  . jav a 2 s.  c  o m
    }
}

From source file:org.opentestsystem.shared.test.listener.LifecycleResourceCombiner.java

private LifecycleResource[] getSortedResources() {
    // Build a doubly-linked tree of all Spring dependencies.
    final ApplicationContext context = getApplicationContext();
    final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) context;
    final Map<String, BeanHolder> beanHolderMap = new HashMap<String, BeanHolder>();

    for (String key_i : registry.getBeanDefinitionNames()) {
        final BeanDefinition definition_i = registry.getBeanDefinition(key_i);

        // Make sure that there is a holder for this bean in the map.
        // The holder may exist already if this bean's name has appeared as a
        // dependency for another bean.
        BeanHolder beanHolder = beanHolderMap.get(key_i);
        if (beanHolder == null) {
            beanHolder = new BeanHolder(key_i);
            beanHolderMap.put(key_i, beanHolder);
        }/*w  ww  .ja  v  a2  s . c om*/
        beanHolder.bean = context.getBean(key_i);

        // Add the constructor arguments as antecedents
        BeanHolder antecedentHolder = null;
        String antecedentBeanName = null;
        for (final ValueHolder value_j : definition_i.getConstructorArgumentValues()
                .getGenericArgumentValues()) {
            final Object antecedentValue = value_j.getValue();
            if (antecedentValue instanceof RuntimeBeanReference) {
                antecedentBeanName = ((RuntimeBeanReference) antecedentValue).getBeanName();
                antecedentHolder = beanHolderMap.get(antecedentBeanName);
                if (antecedentHolder == null) {
                    antecedentHolder = new BeanHolder(antecedentBeanName);
                    beanHolderMap.put(antecedentBeanName, antecedentHolder);
                }
                beanHolder.beansIDependOn.add(antecedentHolder);
                antecedentHolder.beansWhoDependOnMe.add(beanHolder);
            }
        }

        // Add any factory bean as antecedent
        antecedentBeanName = definition_i.getFactoryBeanName();
        if (!StringUtils.isBlank(antecedentBeanName)) {
            antecedentHolder = beanHolderMap.get(antecedentBeanName);
            if (antecedentHolder == null) {
                antecedentHolder = new BeanHolder(antecedentBeanName);
                beanHolderMap.put(antecedentBeanName, antecedentHolder);
            }
            beanHolder.beansIDependOn.add(antecedentHolder);
            antecedentHolder.beansWhoDependOnMe.add(beanHolder);
        }

        // Add the properties as antecedents
        if (definition_i.getPropertyValues() != null
                && definition_i.getPropertyValues().getPropertyValueList() != null) {
            for (final PropertyValue value_j : definition_i.getPropertyValues().getPropertyValueList()) {
                final Object antecedentValue = value_j.getValue();
                if (antecedentValue instanceof RuntimeBeanReference) {
                    antecedentBeanName = ((RuntimeBeanReference) antecedentValue).getBeanName();
                    antecedentHolder = beanHolderMap.get(antecedentBeanName);
                    if (antecedentHolder == null) {
                        antecedentHolder = new BeanHolder(antecedentBeanName);
                        beanHolderMap.put(antecedentBeanName, antecedentHolder);
                    }
                    beanHolder.beansIDependOn.add(antecedentHolder);
                    antecedentHolder.beansWhoDependOnMe.add(beanHolder);
                }
            }
        }

        // Add explicitly identified antecedents
        if (definition_i.getDependsOn() != null) {
            for (String name_j : definition_i.getDependsOn()) {
                antecedentBeanName = name_j;
                antecedentHolder = beanHolderMap.get(antecedentBeanName);
                if (antecedentHolder == null) {
                    antecedentHolder = new BeanHolder(antecedentBeanName);
                    beanHolderMap.put(antecedentBeanName, antecedentHolder);
                }
                beanHolder.beansIDependOn.add(antecedentHolder);
                antecedentHolder.beansWhoDependOnMe.add(beanHolder);
            }
        }
    }

    // Prune the tree of all items that aren't LifecycleResource
    // This step is easier with a stable ordering, so we copy things into a
    // list.
    List<BeanHolder> beanHolderList = new ArrayList<BeanHolder>(beanHolderMap.values());
    int i = 0;
    while (i < beanHolderList.size()) {
        final BeanHolder beanHolder_i = beanHolderList.get(i);
        if (beanHolder_i.bean instanceof LifecycleResource) {
            i++;
        } else {
            for (final BeanHolder antecedent_j : beanHolder_i.beansIDependOn) {
                for (final BeanHolder dependent_k : beanHolder_i.beansWhoDependOnMe) {
                    dependent_k.beansIDependOn.add(antecedent_j);
                    antecedent_j.beansWhoDependOnMe.add(dependent_k);
                }
                antecedent_j.beansWhoDependOnMe.remove(beanHolder_i);
            }
            for (final BeanHolder dependent_j : beanHolder_i.beansWhoDependOnMe) {
                dependent_j.beansIDependOn.remove(beanHolder_i);
            }
            beanHolderList.remove(i);
        }
    }

    // Now do the topo sort.
    //
    // We cycle through the list repeatedly. Each time, we can pull out anyone
    // who doesn't have a dependency on anyone else who is still in the list.
    // This leads to everyone being pulled out before their dependencies.
    //
    // If at the end we still have people in the list who depend on each
    // other, we have a dependency cycle.

    i = 0;
    boolean found = true;
    int n = beanHolderList.size();
    LifecycleResource[] ans = new LifecycleResource[n];
    StringBuilder message = new StringBuilder(
            "Resolved sequence of LifecycleResource elements in Spring context:\r\n  ");
    while (i < n) {
        if (!found) {
            // We got all the way through the list without finding any with no
            // antecedents. There is a cycle
            StringBuilder beanNames = new StringBuilder();
            for (BeanHolder beanHolder_k : beanHolderList) {
                beanNames.append(beanHolder_k.beanName).append(" depends on ( ");
                for (BeanHolder beanHolder_l : beanHolder_k.beansIDependOn) {
                    beanNames.append(beanHolder_l.beanName).append(" ");
                }
                beanNames.append(")\r\n");
            }
            throw new RuntimeException(String.format(
                    "LifecycleResource beans have one or more reference cycles involving:\r\n   %s",
                    beanNames));
        }
        found = false;
        int j = 0;
        while (j < beanHolderList.size()) {
            final BeanHolder beanHolder_j = beanHolderList.get(j);
            if (beanHolder_j.beansIDependOn.size() == 0) {
                ans[i] = (LifecycleResource) beanHolder_j.bean;
                i++;
                found = true;
                beanHolderList.remove(j);
                for (final BeanHolder beanHolder_k : beanHolder_j.beansWhoDependOnMe) {
                    beanHolder_k.beansIDependOn.remove(beanHolder_j);
                }
                message.append(beanHolder_j.beanName).append(" ");
            } else {
                j++;
            }
        }
    }
    _logger.info(message.toString());
    return ans;
}

From source file:org.springframework.batch.core.jsr.configuration.xml.JsrBeanDefinitionDocumentReader.java

private Properties initJobParameters() {
    Properties jobParameters = new Properties();

    if (getBeanDefinitionRegistry().containsBeanDefinition(JOB_PARAMETERS_BEAN_DEFINITION_NAME)) {
        BeanDefinition beanDefintion = getBeanDefinitionRegistry()
                .getBeanDefinition(JOB_PARAMETERS_BEAN_DEFINITION_NAME);

        Properties properties = (Properties) beanDefintion.getConstructorArgumentValues()
                .getGenericArgumentValue(Properties.class).getValue();

        if (properties == null) {
            return new Properties();
        }//from w  ww  . ja v  a 2  s . c o  m

        Enumeration<?> propertyNames = properties.propertyNames();

        while (propertyNames.hasMoreElements()) {
            String curName = (String) propertyNames.nextElement();
            jobParameters.put(curName, properties.getProperty(curName));
        }
    }

    return jobParameters;
}

From source file:org.springframework.batch.core.jsr.configuration.xml.JsrBeanDefinitionDocumentReaderTests.java

@Test
@SuppressWarnings("resource")
public void testGetJobParameters() {
    Properties jobParameters = new Properties();
    jobParameters.setProperty("jobParameter1", "jobParameter1Value");
    jobParameters.setProperty("jobParameter2", "jobParameter2Value");

    JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(jobParameters);
    applicationContext.setValidating(false);
    applicationContext.load(new ClassPathResource("jsrBaseContext.xml"),
            new ClassPathResource("/META-INF/batch.xml"),
            new ClassPathResource("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml"));
    applicationContext.refresh();/*from   w w  w.ja v a 2 s.  c om*/

    BeanDefinition beanDefinition = applicationContext.getBeanDefinition(JOB_PARAMETERS_BEAN_DEFINITION_NAME);

    Properties processedJobParameters = (Properties) beanDefinition.getConstructorArgumentValues()
            .getGenericArgumentValue(Properties.class).getValue();
    assertNotNull(processedJobParameters);
    assertTrue("Wrong number of job parameters", processedJobParameters.size() == 2);
    assertEquals("jobParameter1Value", processedJobParameters.getProperty("jobParameter1"));
    assertEquals("jobParameter2Value", processedJobParameters.getProperty("jobParameter2"));
}

From source file:org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java

/**
 * Parse a constructor-arg element.//from   w  ww  . j a  va  2 s  .c o  m
 */
public void parseConstructorArgElement(Element ele, BeanDefinition bd) {
    String indexAttr = ele.getAttribute(INDEX_ATTRIBUTE);
    String typeAttr = ele.getAttribute(TYPE_ATTRIBUTE);
    String nameAttr = ele.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasLength(indexAttr)) {
        try {
            int index = Integer.parseInt(indexAttr);
            if (index < 0) {
                error("'index' cannot be lower than 0", ele);
            } else {
                try {
                    this.parseState.push(new ConstructorArgumentEntry(index));
                    Object value = parsePropertyValue(ele, bd, null);
                    ConstructorArgumentValues.ValueHolder valueHolder = new ConstructorArgumentValues.ValueHolder(
                            value);
                    if (StringUtils.hasLength(typeAttr)) {
                        valueHolder.setType(typeAttr);
                    }
                    if (StringUtils.hasLength(nameAttr)) {
                        valueHolder.setName(nameAttr);
                    }
                    valueHolder.setSource(extractSource(ele));
                    if (bd.getConstructorArgumentValues().hasIndexedArgumentValue(index)) {
                        error("Ambiguous constructor-arg entries for index " + index, ele);
                    } else {
                        bd.getConstructorArgumentValues().addIndexedArgumentValue(index, valueHolder);
                    }
                } finally {
                    this.parseState.pop();
                }
            }
        } catch (NumberFormatException ex) {
            error("Attribute 'index' of tag 'constructor-arg' must be an integer", ele);
        }
    } else {
        try {
            this.parseState.push(new ConstructorArgumentEntry());
            Object value = parsePropertyValue(ele, bd, null);
            ConstructorArgumentValues.ValueHolder valueHolder = new ConstructorArgumentValues.ValueHolder(
                    value);
            if (StringUtils.hasLength(typeAttr)) {
                valueHolder.setType(typeAttr);
            }
            if (StringUtils.hasLength(nameAttr)) {
                valueHolder.setName(nameAttr);
            }
            valueHolder.setSource(extractSource(ele));
            bd.getConstructorArgumentValues().addGenericArgumentValue(valueHolder);
        } finally {
            this.parseState.pop();
        }
    }
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationPackages.java

/**
 * Programmatically registers the auto-configuration package names. Subsequent
 * invocations will add the given package names to those that have already been
 * registered. You can use this method to manually define the base packages that will
 * be used for a given {@link BeanDefinitionRegistry}. Generally it's recommended that
 * you don't call this method directly, but instead rely on the default convention
 * where the package name is set from your {@code @EnableAutoConfiguration}
 * configuration class or classes.// www  .j a  va 2 s.  com
 * @param registry the bean definition registry
 * @param packageNames the package names to set
 */
public static void register(BeanDefinitionRegistry registry, String... packageNames) {
    if (registry.containsBeanDefinition(BEAN)) {
        BeanDefinition beanDefinition = registry.getBeanDefinition(BEAN);
        ConstructorArgumentValues constructorArguments = beanDefinition.getConstructorArgumentValues();
        constructorArguments.addIndexedArgumentValue(0, addBasePackages(constructorArguments, packageNames));
    } else {
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(BasePackages.class);
        beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, packageNames);
        beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        registry.registerBeanDefinition(BEAN, beanDefinition);
    }
}

From source file:org.springframework.integration.config.MessagingGatewayRegistrar.java

public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes) {

    String defaultPayloadExpression = (String) gatewayAttributes.get("defaultPayloadExpression");

    @SuppressWarnings("unchecked")
    Map<String, Object>[] defaultHeaders = (Map<String, Object>[]) gatewayAttributes.get("defaultHeaders");

    String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel");
    String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel");
    String errorChannel = (String) gatewayAttributes.get("errorChannel");
    String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor");
    String mapper = (String) gatewayAttributes.get("mapper");

    boolean hasMapper = StringUtils.hasText(mapper);
    boolean hasDefaultPayloadExpression = StringUtils.hasText(defaultPayloadExpression);
    Assert.state(!hasMapper || !hasDefaultPayloadExpression,
            "'defaultPayloadExpression' is not allowed when a 'mapper' is provided");

    boolean hasDefaultHeaders = !ObjectUtils.isEmpty(defaultHeaders);
    Assert.state(!hasMapper || !hasDefaultHeaders,
            "'defaultHeaders' are not allowed when a 'mapper' is provided");

    BeanDefinitionBuilder gatewayProxyBuilder = BeanDefinitionBuilder
            .genericBeanDefinition(GatewayProxyFactoryBean.class);

    if (hasDefaultHeaders || hasDefaultPayloadExpression) {
        BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(GatewayMethodMetadata.class);
        if (hasDefaultPayloadExpression) {
            methodMetadataBuilder.addPropertyValue("payloadExpression", defaultPayloadExpression);
        }//from  ww  w .  j  a  v  a2 s. c  o  m
        Map<String, Object> headerExpressions = new ManagedMap<String, Object>();
        for (Map<String, Object> header : defaultHeaders) {
            String headerValue = (String) header.get("value");
            String headerExpression = (String) header.get("expression");
            boolean hasValue = StringUtils.hasText(headerValue);

            if (!(hasValue ^ StringUtils.hasText(headerExpression))) {
                throw new BeanDefinitionStoreException(
                        "exactly one of 'value' or 'expression' " + "is required on a gateway's header.");
            }

            BeanDefinition expressionDef = new RootBeanDefinition(
                    hasValue ? LiteralExpression.class : ExpressionFactoryBean.class);
            expressionDef.getConstructorArgumentValues()
                    .addGenericArgumentValue(hasValue ? headerValue : headerExpression);

            headerExpressions.put((String) header.get("name"), expressionDef);
        }
        methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
        gatewayProxyBuilder.addPropertyValue("globalMethodMetadata", methodMetadataBuilder.getBeanDefinition());
    }

    if (StringUtils.hasText(defaultRequestChannel)) {
        gatewayProxyBuilder.addPropertyReference("defaultRequestChannel", defaultRequestChannel);
    }
    if (StringUtils.hasText(defaultReplyChannel)) {
        gatewayProxyBuilder.addPropertyReference("defaultReplyChannel", defaultReplyChannel);
    }
    if (StringUtils.hasText(errorChannel)) {
        gatewayProxyBuilder.addPropertyReference("errorChannel", errorChannel);
    }
    if (StringUtils.hasText(asyncExecutor)) {
        gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor);
    }
    if (StringUtils.hasText(mapper)) {
        gatewayProxyBuilder.addPropertyReference("mapper", mapper);
    }

    gatewayProxyBuilder.addPropertyValue("defaultRequestTimeout",
            gatewayAttributes.get("defaultRequestTimeout"));
    gatewayProxyBuilder.addPropertyValue("defaultReplyTimeout", gatewayAttributes.get("defaultReplyTimeout"));
    gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods"));

    String serviceInterface = (String) gatewayAttributes.get("serviceInterface");
    if (!StringUtils.hasText(serviceInterface)) {
        serviceInterface = "org.springframework.integration.gateway.RequestReplyExchanger";
    }
    String id = (String) gatewayAttributes.get("name");
    if (!StringUtils.hasText(id)) {
        id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf(".") + 1));
    }

    gatewayProxyBuilder.addConstructorArgValue(serviceInterface);

    return new BeanDefinitionHolder(gatewayProxyBuilder.getBeanDefinition(), id);
}

From source file:org.springframework.integration.handler.ExpressionEvaluatingMessageProcessorTests.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test//w  w  w .j av a  2 s  .c  o  m
public void testProcessMessageWithBeanAsMethodArgument() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
    beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("bar");
    context.registerBeanDefinition("testString", beanDefinition);
    context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME,
            new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class));
    Expression expression = expressionParser.parseExpression("payload.concat(@testString)");
    ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
    processor.setBeanFactory(context);
    processor.afterPropertiesSet();
    GenericMessage<String> message = new GenericMessage<String>("foo");
    assertEquals("foobar", processor.processMessage(message));
}

From source file:org.springframework.integration.handler.ExpressionEvaluatingMessageProcessorTests.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test//from w  ww.j  a  v  a2s . c  om
public void testProcessMessageWithMethodCallOnBean() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
    beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("bar");
    context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME,
            new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class));
    context.registerBeanDefinition("testString", beanDefinition);
    Expression expression = expressionParser.parseExpression("@testString.concat(payload)");
    ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
    processor.setBeanFactory(context);
    processor.afterPropertiesSet();
    GenericMessage<String> message = new GenericMessage<String>("foo");
    assertEquals("barfoo", processor.processMessage(message));
}