Example usage for org.springframework.integration.expression ExpressionUtils createStandardEvaluationContext

List of usage examples for org.springframework.integration.expression ExpressionUtils createStandardEvaluationContext

Introduction

In this page you can find the example usage for org.springframework.integration.expression ExpressionUtils createStandardEvaluationContext.

Prototype

public static StandardEvaluationContext createStandardEvaluationContext() 

Source Link

Document

Used to create a context with no BeanFactory, usually in tests.

Usage

From source file:org.springframework.integration.ftp.inbound.FtpInboundRemoteFileSystemSynchronizerTests.java

@Test
public void testCopyFileToLocalDir() throws Exception {
    File localDirectoy = new File("test");
    assertFalse(localDirectoy.exists());

    TestFtpSessionFactory ftpSessionFactory = new TestFtpSessionFactory();
    ftpSessionFactory.setUsername("kermit");
    ftpSessionFactory.setPassword("frog");
    ftpSessionFactory.setHost("foo.com");
    FtpInboundFileSynchronizer synchronizer = spy(new FtpInboundFileSynchronizer(ftpSessionFactory));
    synchronizer.setDeleteRemoteFiles(true);
    synchronizer.setRemoteDirectory("remote-test-dir");
    synchronizer.setFilter(new FtpRegexPatternFileListFilter(".*\\.test$"));
    synchronizer.setIntegrationEvaluationContext(ExpressionUtils.createStandardEvaluationContext());

    ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Expression expression = expressionParser.parseExpression("#this.toUpperCase() + '.a'");
    synchronizer.setLocalFilenameGeneratorExpression(expression);

    FtpInboundFileSynchronizingMessageSource ms = new FtpInboundFileSynchronizingMessageSource(synchronizer);

    ms.setAutoCreateLocalDirectory(true);

    ms.setLocalDirectory(localDirectoy);
    ms.afterPropertiesSet();//from www  . j a  v a 2 s .c  o m
    Message<File> atestFile = ms.receive();
    assertNotNull(atestFile);
    assertEquals("A.TEST.a", atestFile.getPayload().getName());
    Message<File> btestFile = ms.receive();
    assertNotNull(btestFile);
    assertEquals("B.TEST.a", btestFile.getPayload().getName());
    Message<File> nothing = ms.receive();
    assertNull(nothing);

    // two times because on the third receive (above) the internal queue will be empty, so it will attempt
    verify(synchronizer, times(2)).synchronizeToLocalDirectory(localDirectoy);

    assertTrue(new File("test/A.TEST.a").exists());
    assertTrue(new File("test/B.TEST.a").exists());
}

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

/**
 * Create a LoggingHandler with the given log level (case-insensitive).
 * <p>/*from   www. jav  a 2s. c o m*/
 * The valid levels are: FATAL, ERROR, WARN, INFO, DEBUG, or TRACE
 */
public LoggingHandler(String level) {
    Assert.notNull(level, "'level' cannot be null");
    try {
        this.level = Level.valueOf(level.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                "Invalid log level '" + level + "'. The (case-insensitive) supported values are: "
                        + StringUtils.arrayToCommaDelimitedString(Level.values()));
    }
    this.evaluationContext = ExpressionUtils.createStandardEvaluationContext();
    this.expression = EXPRESSION_PARSER.parseExpression("payload");
}

From source file:org.springframework.integration.util.AbstractExpressionEvaluator.java

/**
 * Emits a WARN log if the beanFactory field is null, unless the argument is false.
 * @param beanFactoryRequired set to false to suppress the warning.
 * @return The evaluation context./*  ww  w . j av  a2 s  .  c o  m*/
 */
protected final StandardEvaluationContext getEvaluationContext(boolean beanFactoryRequired) {
    if (this.evaluationContext == null) {
        if (this.beanFactory == null && !beanFactoryRequired) {
            this.evaluationContext = ExpressionUtils.createStandardEvaluationContext();
        } else {
            this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory);
        }
        if (this.typeConverter != null) {
            this.evaluationContext.setTypeConverter(this.typeConverter);
        }
    }
    return this.evaluationContext;
}