次の Mule アプリケーションをテストするとします。
<sftp:config name="SFTP_Config">
<sftp:connection host="${ftp.host}" port="${ftp.port}" username="${ftp.user}" password="${ftp.password}"/>
</sftp:config>
<configuration-properties file="ftp.properties" />
<flow name="listFlow">
<sftp:list config-ref="SFTP_Config" directoryPath="."/>
<foreach>
<logger level="INFO" message="#[attributes.fileName]"/>
</foreach>
</flow>
src/main/resources にある ftp.properties には次のコンテンツが含まれています。
ftp.host=localhost
ftp.port=22
ftp.user=max
ftp.password=munittest
username 項目は空にできません。ユーザー名-パスワードのペアがない場合は、username を anonymous に設定し、パスワードは設定しないでください。デフォルトでは、anonymous 属性は true に設定されています。
FTP サーバーのインストール
-
Anypoint Studio から、[Mule Palette (Mule パレット)] ビューに移動し、[Search in Exchange… (Exchange 内を検索…)] を見つけます。
-
検索バーで「MUnit Utils FTP Server」 (MUnit ユーティリティ FTP サーバー) を検索し、そのモジュールをプロジェクトに追加します。
<!-- Ftp Server Dependency --> <dependency> <groupId>com.mulesoft.munit.utils</groupId> <artifactId>munit-ftpserver-module</artifactId> <version>2.0.1</version> <classifier>mule-plugin</classifier> <scope>test</scope> </dependency>POM ファイル内の MUnit FTP サーバーアーティファクトには
test スコープが必要です。
FTP サーバーの定義
-
Studio キャンバスで、[Global Elements (グローバル要素)] タブに移動し、[MUnit FTP Server Config (MUnit FTP サーバー設定)] 要素を選択します。
-
[Edit (編集)] をクリックし、次の項目に入力します。
属性 Value (値) 名前
MUnit_FTP_Server_ConfigPort (ポート)
${ftp.port}Username (ユーザー名)
${ftp.user}Password (パスワード)
${ftp.password}Secure (セキュア)
truehomeDir
${app.home}<ftpserver:config name="MUnit_FTP_Server_Config"> <ftpserver:connection port="${ftp.port}" username="${ftp.user}" password="${ftp.password}" secure="true" homeDir="${app.home}"/> </ftpserver:config>
テストの実行
FTP サーバーを設定したら、テストを実行できます。
<munit:test name="listFlowTest" description="Test listFlow" >
<munit:execution>
<flow-ref name="listFlow"/>
</munit:execution>
<munit:validation>
<munit-tools:assert-that expression="#[sizeOf(payload)]" is="#[MunitTools::greaterThan(0)]"/>
</munit:validation>
</munit:test>
この FTP はすべてのユーザーを受け入れるため、ユーザーのデータベースやリストをセットアップする必要はありません。