Repository: camel Updated Branches: refs/heads/master 02ace89eb -> eb7e8244c
CAMEL-10103: Camel FTP - Unittest on OSGI Parsers Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/eb7e8244 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/eb7e8244 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/eb7e8244 Branch: refs/heads/master Commit: eb7e8244c22f7cb81ec191a218ca3d6a856ea329 Parents: 02ace89 Author: Arno Noordover <anoordo...@users.noreply.github.com> Authored: Thu Jun 30 22:40:55 2016 +0200 Committer: Arno Noordover <anoordo...@users.noreply.github.com> Committed: Thu Jun 30 22:40:55 2016 +0200 ---------------------------------------------------------------------- components/camel-ftp/pom.xml | 5 + .../file/remote/OsgiParserFactoryTest.java | 96 ++++++++++++++++++++ 2 files changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/eb7e8244/components/camel-ftp/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-ftp/pom.xml b/components/camel-ftp/pom.xml index 6e4691e..1b36540 100644 --- a/components/camel-ftp/pom.xml +++ b/components/camel-ftp/pom.xml @@ -128,6 +128,11 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/camel/blob/eb7e8244/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/OsgiParserFactoryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/OsgiParserFactoryTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/OsgiParserFactoryTest.java new file mode 100644 index 0000000..e5702be --- /dev/null +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/OsgiParserFactoryTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.file.remote; + +import org.apache.commons.net.ftp.FTPClientConfig; +import org.apache.commons.net.ftp.FTPFileEntryParser; +import org.apache.commons.net.ftp.parser.CompositeFileEntryParser; +import org.apache.commons.net.ftp.parser.NTFTPEntryParser; +import org.apache.commons.net.ftp.parser.UnixFTPEntryParser; +import org.apache.commons.net.ftp.parser.VMSVersioningFTPEntryParser; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class OsgiParserFactoryTest { + + private static final OsgiParserFactory OSGI_PARSER_FACTORY = new OsgiParserFactory(null); + @Mock + private FTPClientConfig ftpClientConfig; + + @Before + public void setup() { + when(ftpClientConfig.getDefaultDateFormatStr()).thenReturn("yyyy-MM-dd"); + } + + @Test + public void createFileEntryParserUnix() + throws Exception { + when(ftpClientConfig.getServerSystemKey()).thenReturn("bla unix bla"); + FTPFileEntryParser result = OSGI_PARSER_FACTORY.createFileEntryParser(ftpClientConfig); + assertThat(result, instanceOf(UnixFTPEntryParser.class)); + } + + @Test + public void createFileEntryParserLinux() + throws Exception { + when(ftpClientConfig.getServerSystemKey()).thenReturn("bla linux bla"); + FTPFileEntryParser result = OSGI_PARSER_FACTORY.createFileEntryParser(ftpClientConfig); + assertThat(result, instanceOf(UnixFTPEntryParser.class)); + } + + @Test + public void createFileEntryParserTypeL8() + throws Exception { + when(ftpClientConfig.getServerSystemKey()).thenReturn("bla type: l8 bla"); + FTPFileEntryParser result = OSGI_PARSER_FACTORY.createFileEntryParser(ftpClientConfig); + assertThat(result, instanceOf(UnixFTPEntryParser.class)); + } + + @Test + public void createFileEntryParserVms() + throws Exception { + when(ftpClientConfig.getServerSystemKey()).thenReturn("bla vms bla"); + FTPFileEntryParser result = OSGI_PARSER_FACTORY.createFileEntryParser(ftpClientConfig); + assertThat(result, instanceOf(VMSVersioningFTPEntryParser.class)); + } + + @Test + public void createFileEntryParserPlainWindows() + throws Exception { + when(ftpClientConfig.getServerSystemKey()).thenReturn("WINDOWS"); + FTPFileEntryParser result = OSGI_PARSER_FACTORY.createFileEntryParser(ftpClientConfig); + assertThat(result, instanceOf(NTFTPEntryParser.class)); + } + + @Test + public void createFileEntryParserNotPlainWindows() + throws Exception { + when(ftpClientConfig.getServerSystemKey()).thenReturn("WINDOWS XP"); + FTPFileEntryParser result = OSGI_PARSER_FACTORY.createFileEntryParser(ftpClientConfig); + assertThat(result, instanceOf(CompositeFileEntryParser.class)); + } + +} \ No newline at end of file