Mule Maven 插件 MUnit 失败:NoSuchElementException
Mule Maven Plugin MUnit Failure: NoSuchElementException
我正在尝试使用 mule maven 插件创建构建,它必须执行 MUnit 测试用例。我使用了一个配置 属性 并且它被配置为 app-{mule.env}.yaml
虽然 运行 该应用程序在我传递参数 mule.env=dev 时工作正常,但在使用下面的 mule maven 插件创建 maven 构建时导致失败是 POM 结构
MUnit 特定配置:
<configuration>
<environmentVariables>
<mule.env>dev</mule.env>
<mule.key>23454646576575675</mule.key>
</environmentVariables>
<coverage>
<runCoverage>true</runCoverage>
<failBuild>true</failBuild>
<requiredApplicationCoverage>${app.coverage}</requiredApplicationCoverage>
<requiredResourceCoverage>0</requiredResourceCoverage>
<requiredFlowCoverage>0</requiredFlowCoverage>
<formats>
<format>console</format>
<format>html</format>
</formats>
</coverage>
</configuration>
完成 POM
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>app</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mule.version>4.2.1</mule.version>
<munit.version>2.2.1</munit.version>
<app.runtime>4.2.1</app.runtime>
<mule.maven.plugin.version>3.2.7</mule.maven.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<server>anypoint-platform</server>
<environment>${environment}</environment>
<applicationName>${application.name}</applicationName>
<muleVersion>${mule.version}</muleVersion>
<businessGroup>${business.group}</businessGroup>
<properties>
<mule.env>${mule.env}</mule.env>
<mule.key>${mule.key}</mule.key>
<anypoint.platform.analytics_base_uri>https://analytics-ingest.anypoint.mulesoft.com</anypoint.platform.analytics_base_uri>
<anypoint.platform.client_id>${client-id}</anypoint.platform.client_id>
<anypoint.platform.client_secret>${client-secret}</anypoint.platform.client_secret>
<anypoint.platform.base_uri>https://anypoint.mulesoft.com</anypoint.platform.base_uri>
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
<plugin>
<groupId>com.mulesoft.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
<version>${munit.version}</version>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<environmentVariables>
<mule.env>dev</mule.env>
<mule.key>23454646576575675</mule.key>
</environmentVariables>
<coverage>
<runCoverage>true</runCoverage>
<failBuild>true</failBuild>
<requiredApplicationCoverage>${app.coverage}</requiredApplicationCoverage>
<requiredResourceCoverage>0</requiredResourceCoverage>
<requiredFlowCoverage>0</requiredFlowCoverage>
<formats>
<format>console</format>
<format>html</format>
</formats>
</coverage>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>1.4.1</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>1.1.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.modules</groupId>
<artifactId>mule-secure-configuration-property-module</artifactId>
<version>1.0.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-runner</artifactId>
<version>2.1.5</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-tools</artifactId>
<version>2.1.5</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-jms-connector</artifactId>
<version>1.3.6</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>anypoint-mq-connector</artifactId>
<version>3.1.0</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-apikit-module</artifactId>
<version>1.1.9</version>
<classifier>mule-plugin</classifier>
</dependency>
</dependencies>
<repositories>
<repository>
<id>anypoint-exchange</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
当我尝试 maven 构建时出现以下错误
INFO 2020-01-02 13:43:20,651 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.munit.runner.remote.api.server.RunnerServer: Waiting for client connection
INFO 2020-01-02 13:43:21,155 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.munit.runner.remote.api.server.RunnerServer: Client connection received from 127.0.0.1 - true
INFO 2020-01-02 13:43:21,564 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.runtime.api.message.AbstractMuleMessageBuilderFactory: Loaded MuleMessageBuilderFactory implementation 'org.mule.runtime.core.internal.message.DefaultMessageBuilderFactory' from classloader 'java.net.URLClassLoader@5177e388'
org.mule.runtime.api.exception.MuleRuntimeException: java.util.NoSuchElementException: No value present
Caused by: java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.lambda$null(LazyMuleArtifactContext.java:278)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.lambda$createComponents(LazyMuleArtifactContext.java:278)
at org.mule.runtime.core.api.util.ClassUtils.lambda$withContextClassLoader(ClassUtils.java:794)
at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:227)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:849)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:813)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:793)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.createComponents(LazyMuleArtifactContext.java:225)
应用-dev.yaml
anypoint:
mq:
name: "in-queue"
url: https://mq-us-west-1.anypoint.mulesoft.com/api/v1
clientId: "![0iop3V64o9uyhffvvn605a9wLr/kuoqX2B6tcMrt2A6MSIPg3f0zR0+W/Cv]"
clientSecret: "![l0vHmQFIgKjoii8998&*07dsdsfdd4LaMdsfdsEHcxS0]"
该应用程序及其测试用例在 Anypoint studio 中正常运行,但仅在 maven 构建中失败。
我终于明白了这个错误背后的原因,这里的错误信息含糊不清。问题在于在测试套件中定义一个全局元素
<global-property name="https.port" value="8097"/>
如上所示,我尝试使用全局 属性 覆盖应用程序配置的 https 端口,这导致 maven 构建失败。
当我们简单地 运行 在工作室中进行 Munit 测试并将 https 端口覆盖到 8097 时,这工作正常,但在 maven 构建期间失败。
删除全局 属性 解决了问题。
我正在尝试使用 mule maven 插件创建构建,它必须执行 MUnit 测试用例。我使用了一个配置 属性 并且它被配置为 app-{mule.env}.yaml 虽然 运行 该应用程序在我传递参数 mule.env=dev 时工作正常,但在使用下面的 mule maven 插件创建 maven 构建时导致失败是 POM 结构
MUnit 特定配置:
<configuration>
<environmentVariables>
<mule.env>dev</mule.env>
<mule.key>23454646576575675</mule.key>
</environmentVariables>
<coverage>
<runCoverage>true</runCoverage>
<failBuild>true</failBuild>
<requiredApplicationCoverage>${app.coverage}</requiredApplicationCoverage>
<requiredResourceCoverage>0</requiredResourceCoverage>
<requiredFlowCoverage>0</requiredFlowCoverage>
<formats>
<format>console</format>
<format>html</format>
</formats>
</coverage>
</configuration>
完成 POM
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>app</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mule.version>4.2.1</mule.version>
<munit.version>2.2.1</munit.version>
<app.runtime>4.2.1</app.runtime>
<mule.maven.plugin.version>3.2.7</mule.maven.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<server>anypoint-platform</server>
<environment>${environment}</environment>
<applicationName>${application.name}</applicationName>
<muleVersion>${mule.version}</muleVersion>
<businessGroup>${business.group}</businessGroup>
<properties>
<mule.env>${mule.env}</mule.env>
<mule.key>${mule.key}</mule.key>
<anypoint.platform.analytics_base_uri>https://analytics-ingest.anypoint.mulesoft.com</anypoint.platform.analytics_base_uri>
<anypoint.platform.client_id>${client-id}</anypoint.platform.client_id>
<anypoint.platform.client_secret>${client-secret}</anypoint.platform.client_secret>
<anypoint.platform.base_uri>https://anypoint.mulesoft.com</anypoint.platform.base_uri>
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
<plugin>
<groupId>com.mulesoft.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
<version>${munit.version}</version>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<environmentVariables>
<mule.env>dev</mule.env>
<mule.key>23454646576575675</mule.key>
</environmentVariables>
<coverage>
<runCoverage>true</runCoverage>
<failBuild>true</failBuild>
<requiredApplicationCoverage>${app.coverage}</requiredApplicationCoverage>
<requiredResourceCoverage>0</requiredResourceCoverage>
<requiredFlowCoverage>0</requiredFlowCoverage>
<formats>
<format>console</format>
<format>html</format>
</formats>
</coverage>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>1.4.1</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>1.1.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.modules</groupId>
<artifactId>mule-secure-configuration-property-module</artifactId>
<version>1.0.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-runner</artifactId>
<version>2.1.5</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-tools</artifactId>
<version>2.1.5</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-jms-connector</artifactId>
<version>1.3.6</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>anypoint-mq-connector</artifactId>
<version>3.1.0</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-apikit-module</artifactId>
<version>1.1.9</version>
<classifier>mule-plugin</classifier>
</dependency>
</dependencies>
<repositories>
<repository>
<id>anypoint-exchange</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
当我尝试 maven 构建时出现以下错误
INFO 2020-01-02 13:43:20,651 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.munit.runner.remote.api.server.RunnerServer: Waiting for client connection
INFO 2020-01-02 13:43:21,155 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.munit.runner.remote.api.server.RunnerServer: Client connection received from 127.0.0.1 - true
INFO 2020-01-02 13:43:21,564 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.runtime.api.message.AbstractMuleMessageBuilderFactory: Loaded MuleMessageBuilderFactory implementation 'org.mule.runtime.core.internal.message.DefaultMessageBuilderFactory' from classloader 'java.net.URLClassLoader@5177e388'
org.mule.runtime.api.exception.MuleRuntimeException: java.util.NoSuchElementException: No value present
Caused by: java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.lambda$null(LazyMuleArtifactContext.java:278)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.lambda$createComponents(LazyMuleArtifactContext.java:278)
at org.mule.runtime.core.api.util.ClassUtils.lambda$withContextClassLoader(ClassUtils.java:794)
at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:227)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:849)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:813)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:793)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.createComponents(LazyMuleArtifactContext.java:225)
应用-dev.yaml
anypoint:
mq:
name: "in-queue"
url: https://mq-us-west-1.anypoint.mulesoft.com/api/v1
clientId: "![0iop3V64o9uyhffvvn605a9wLr/kuoqX2B6tcMrt2A6MSIPg3f0zR0+W/Cv]"
clientSecret: "![l0vHmQFIgKjoii8998&*07dsdsfdd4LaMdsfdsEHcxS0]"
该应用程序及其测试用例在 Anypoint studio 中正常运行,但仅在 maven 构建中失败。
我终于明白了这个错误背后的原因,这里的错误信息含糊不清。问题在于在测试套件中定义一个全局元素
<global-property name="https.port" value="8097"/>
如上所示,我尝试使用全局 属性 覆盖应用程序配置的 https 端口,这导致 maven 构建失败。
当我们简单地 运行 在工作室中进行 Munit 测试并将 https 端口覆盖到 8097 时,这工作正常,但在 maven 构建期间失败。
删除全局 属性 解决了问题。