Search in sources :

Example 1 with S3InboundFileSynchronizingMessageSource

use of org.springframework.integration.aws.inbound.S3InboundFileSynchronizingMessageSource in project spring-integration-aws by spring-projects.

the class S3InboundChannelAdapterParserTests method testS3InboundChannelAdapterComplete.

@Test
@SuppressWarnings("unchecked")
public void testS3InboundChannelAdapterComplete() throws Exception {
    assertThat(TestUtils.getPropertyValue(this.s3Inbound, "autoStartup", Boolean.class)).isFalse();
    PriorityBlockingQueue<?> blockingQueue = TestUtils.getPropertyValue(this.s3Inbound, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);
    Comparator<?> comparator = blockingQueue.comparator();
    assertThat(comparator).isSameAs(this.comparator);
    assertThat(this.s3Inbound.getComponentName()).isEqualTo("s3Inbound");
    assertThat(this.s3Inbound.getComponentType()).isEqualTo("aws:s3-inbound-channel-adapter");
    assertThat(TestUtils.getPropertyValue(this.s3Inbound, "outputChannel")).isSameAs(this.s3Channel);
    S3InboundFileSynchronizingMessageSource inbound = TestUtils.getPropertyValue(this.s3Inbound, "source", S3InboundFileSynchronizingMessageSource.class);
    S3InboundFileSynchronizer fisync = TestUtils.getPropertyValue(inbound, "synchronizer", S3InboundFileSynchronizer.class);
    assertThat(TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class).getExpressionString()).isEqualTo("'foo/bar'");
    assertThat(TestUtils.getPropertyValue(fisync, "localFilenameGeneratorExpression")).isNotNull();
    assertThat(TestUtils.getPropertyValue(fisync, "preserveTimestamp", Boolean.class)).isTrue();
    assertThat(TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class)).isEqualTo(".foo");
    String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
    assertThat(remoteFileSeparator).isEqualTo("\\");
    CompositeFileListFilter<?> filter = TestUtils.getPropertyValue(fisync, "filter", CompositeFileListFilter.class);
    assertThat(filter).isNotNull();
    Set<FileListFilter<?>> fileFilters = TestUtils.getPropertyValue(filter, "fileFilters", Set.class);
    assertThat(fileFilters).size().isEqualTo(2);
    List<FileListFilter<?>> filters = new ArrayList<>(fileFilters);
    assertThat(filters.get(0)).isInstanceOf(S3SimplePatternFileListFilter.class);
    assertThat(filters.get(1)).isInstanceOf(S3PersistentAcceptOnceFileListFilter.class);
    assertThat(TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory")).isSameAs(this.s3SessionFactory);
    assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class).contains(this.acceptAllFilter)).isTrue();
    final AtomicReference<Method> genMethod = new AtomicReference<Method>();
    ReflectionUtils.doWithMethods(AbstractInboundFileSynchronizer.class, new ReflectionUtils.MethodCallback() {

        @Override
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            if ("generateLocalFileName".equals(method.getName())) {
                method.setAccessible(true);
                genMethod.set(method);
            }
        }
    });
    assertThat(genMethod.get().invoke(fisync, "foo")).isEqualTo("FOO.afoo");
}
Also used : S3PersistentAcceptOnceFileListFilter(org.springframework.integration.aws.support.filters.S3PersistentAcceptOnceFileListFilter) AcceptAllFileListFilter(org.springframework.integration.file.filters.AcceptAllFileListFilter) FileListFilter(org.springframework.integration.file.filters.FileListFilter) CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) S3SimplePatternFileListFilter(org.springframework.integration.aws.support.filters.S3SimplePatternFileListFilter) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Method(java.lang.reflect.Method) S3InboundFileSynchronizer(org.springframework.integration.aws.inbound.S3InboundFileSynchronizer) Expression(org.springframework.expression.Expression) Collection(java.util.Collection) S3InboundFileSynchronizingMessageSource(org.springframework.integration.aws.inbound.S3InboundFileSynchronizingMessageSource) ReflectionUtils(org.springframework.util.ReflectionUtils) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 Expression (org.springframework.expression.Expression)1 S3InboundFileSynchronizer (org.springframework.integration.aws.inbound.S3InboundFileSynchronizer)1 S3InboundFileSynchronizingMessageSource (org.springframework.integration.aws.inbound.S3InboundFileSynchronizingMessageSource)1 S3PersistentAcceptOnceFileListFilter (org.springframework.integration.aws.support.filters.S3PersistentAcceptOnceFileListFilter)1 S3SimplePatternFileListFilter (org.springframework.integration.aws.support.filters.S3SimplePatternFileListFilter)1 AcceptAllFileListFilter (org.springframework.integration.file.filters.AcceptAllFileListFilter)1 CompositeFileListFilter (org.springframework.integration.file.filters.CompositeFileListFilter)1 FileListFilter (org.springframework.integration.file.filters.FileListFilter)1 ReflectionUtils (org.springframework.util.ReflectionUtils)1