Flex Gateway新着情報
Governance新着情報
Monitoring API ManagerRun Custom イベントプロセッサーを使用すると、Mule イベントコンテンツをカスタムアサーションに対して確認できます。
Run Custom プロセッサーをプロジェクトに追加するには、次の連動関係を pom.xml ファイルに追加します。
<dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-assert</artifactId>
<version>${munit.version}</version>
<scope>test</scope>
</dependency>
また、エクスポートされたリソースとしてカスタムアサーションクラスを mule-artifact.json ファイルに追加する必要もあります。
たとえば、Java で次のアサーションを定義できます。
package org.mule.custom;
import org.mule.munit.assertion.api.MunitAssertion;
import org.mule.munit.assertion.api.TypedValue;
public class CustomAssertion implements MunitAssertion {
@Override
public void execute(TypedValue expression, Object params) throws AssertionError { (1)
if (!"Hello World".equals(expression.getValue())) { (2)
throw new AssertionError("Error the payload is incorrect");
}
}
}
| 1 | インターフェースに 1 つのメソッドのみを実装します: public void execute(TypedValue expression, Object params) throws AssertionError。 |
| 2 | カスタムロジックを実行します。この場合は、メッセージペイロードが Hello World であることを検証します。 |
CustomAssertion クラスは scr/test/java ディレクトリにある必要があります。
また、Run Custom イベントプロセッサーを使用してこれを実行します。
<munit-tools:run-custom
assertion="org.mule.custom.CustomAssertion" (1)
expression="#[payload]"/>
| 1 | アサーション項目にカスタムアサーションの正規クラス名が含まれていて、クラスがエクスポートされている必要があります。 |
アプリケーションをパッケージ化するときにクラスをエクスポートするには、org.mule.custom パッケージを mule-artifact.json に追加します。
{
"name": "mule-application",
"minMuleVersion": "4.2.0",
"classLoaderModelLoaderDescriptor": {
"id": "mule",
"attributes": {
"exportedPackages": [
"org.mule.custom"
]
}
}
}
パッケージ名は exportedPackages コレクションでのみ設定する必要があります。
|