当我从新的单元测试中到达这个非测试代码时
Response.status(responseStatus).entity(response).build();
我从新编写的单元测试中得到以下异常:
java.lang.AbstractMethodError: Receiver class org.apache.wink.common.internal.ResponseImpl$ResponseBuilderImpl does not define or inherit an implementation of the resolved method 'abstract javax.ws.rs.core.Response$ResponseBuilder status(int, java.lang.String)' of abstract class javax.ws.rs.core.Response$ResponseBuilder.
at javax.ws.rs.core.Response$ResponseBuilder.status(Response.java:921)
at javax.ws.rs.core.Response.status(Response.java:592)
at javax.ws.rs.core.Response.status(Response.java:603)
at c.i.c.riker.services.v3.resource.VendorWorkOrderV3Resource.rtsWorkOrderCreateMultipart(VendorWorkOrderV3Resource.java:947)
at c.i.c.riker.services.v3.resource.VendorWorkOrderV3ResourceUnitTest.testRtsWorkOrderCreateMultipart(VendorWorkOrderV3UnitTest.java:134)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:100)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
在创建单元测试之前,我还没有看到这个异常发生。
不是说
Response
是javax.ws.rs.core.Response
,ResponseBuilder
是javax.ws.rs.core.Response.ResponseBuilder
,response
是String
,responseStatus
是javax.ws.rs.core.Response.Status
我正在使用 Maven、Mockito、JUnit 5 和 Open Liberty 服务器。
我不知道如何继续或尝试什么。 我希望当我调用此函数时不会发生异常。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>https://raw.github.com/WASdev/ci.maven.tools/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<parent>
<groupId>com.ibm.cio.riker</groupId>
<artifactId>riker</artifactId>
<version>1.0.0</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>riker-services</artifactId>
<packaging>war</packaging>
<name>rikerServices</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>net.wasdev.maven.tools.targets</groupId>
<artifactId>liberty-target</artifactId>
<version>RELEASE</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.cio.riker</groupId>
<artifactId>riker-timer</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.openapi</groupId>
<artifactId>microprofile-openapi-api</artifactId>
<version>2.0</version>
</dependency>
<!-- newly added dependency -->
<dependency>
<groupId>com.ibm.cio.riker</groupId>
<artifactId>riker-common</artifactId>
<version>1.0.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
<build>
<finalName>riker-services</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-package-config</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../src/main/liberty/config</outputDirectory>
<resources>
<resource>
<directory>src/main/liberty/config</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-package-war</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../target</outputDirectory>
<resources>
<resource>
<directory>./target</directory>
<includes>
<include>riker-services.war</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<systemPropertyVariables>
<http.port>${liberty.var.default.http.port}</http.port>
<context.root>${liberty.var.default.contextroot}</context.root>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
</executions>
<configuration>
<target>2.2</target>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlLocation>/wsdl/wfoutbound.wsdl</wsdlLocation>
<executable>${env.WAS_HOME}/bin/jaxws/wsimport</executable>
<packageName>com.ibm.cio.riker.dao.wsdl</packageName>
<keep>true</keep>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.2.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
ResponseBuilder.status(int, String) 已在 JAX-RS 2.1 中添加。在 Liberty 中,Apache Wink 用于 JAX-RS 1.1 实现。因此,您正在测试的 API 级别 (2.1) 和所使用的实现 (1.1) 之间似乎不匹配。如果您想使用 JAX-RS 2.1 进行测试,则需要切换到 server.xml 中的
jaxrs-2.1
功能,否则您将需要使用 1.1 API 进行 JUnit / Mockito 测试。
要提供更多详细信息,您可以查看
src/main/liberty/config
目录来了解 Liberty 服务器的配置方式。否则,最好知道您的应用程序(我相信它是 riker-services.war)正在使用什么 Java EE 级别。您可能希望将它们同步以使两者之间的 EE 水平匹配。
希望有帮助。
贾里德·安德森