jakarta-ee - Arquillian - ClassNotFound on org.jboss.arquillian.core.api.threading.ExecutorService

标签 jakarta-ee classnotfoundexception executorservice jboss-arquillian

我目前正在尝试使 arquillian 工作,但我的单元测试之一有问题。它在类 org.jboss.arquillian.core.api.threading.ExecutorService 上的 CLassNotFoundException 上失败.也许我忘记了我的 pom.xml 中的依赖项,或者我误解了一些东西但我无法解决这个问题。

这是堆栈跟踪:

java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:160)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
    at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
    at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:95)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
    ... 37 more
Caused by: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.core.impl.ManagerImpl
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:160)
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:111)
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:97)
    at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77)
    at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:55)
    ... 42 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:156)
    ... 46 more
Caused by: java.lang.NoClassDefFoundError: org/jboss/arquillian/core/api/threading/ExecutorService
    at org.jboss.arquillian.core.impl.ManagerImpl$3.call(ManagerImpl.java:470)
    at org.jboss.arquillian.core.impl.ManagerImpl.executeInApplicationContext(ManagerImpl.java:242)
    at org.jboss.arquillian.core.impl.ManagerImpl.createBuiltInServices(ManagerImpl.java:465)
    at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:94)
    ... 51 more
Caused by: java.lang.ClassNotFoundException: org.jboss.arquillian.core.api.threading.ExecutorService
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 55 more

以下是文件:
pom.xml
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>be.normegil</groupId>
    <artifactId>librarium</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>librarium</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.7</version>
        </dependency>
        <!-- Apache Commons -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.1</version>
        </dependency>
        <!-- JEE 7 - API -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
        <!-- JEE 7 - JPA -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.4.Final</version>
        </dependency>
        <!-- TEST DEPENDANCIES -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <version>1.1.4.Final</version>
            <scope>test</scope>
        </dependency>
        <!-- REST Testing framework -->
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-arquillian-container-embedded</artifactId>
            <version>8.1.0.CR1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <!-- Used by persistence.xml in test resources -->
    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>

</project>
GameREST.java
package be.normegil.librarium.rest;

import be.normegil.librarium.model.dao.GameDAO;
import be.normegil.librarium.model.data.Game;
import org.apache.commons.lang3.Validate;

import javax.inject.Inject;
import javax.ws.rs.*;
import java.util.Collection;

@Path("/games")
public class GameREST {

    private GameDAO gameDAO;

    @GET
    @Path("/all")
    @Produces("application/json")
    public Collection<Game> getGamesList() {
        return gameDAO.getAll();
    }

    @GET
    @Path("{ID}")
    @Produces("application/json")
    public Game getGame(@PathParam("ID") Long id) {
        Validate.notNull(id);

        return gameDAO.get(id);
    }

    @PUT
    @Path("{Name}")
    @Produces("application/json")
    public void createGame(@PathParam("Name") String name) {
        Validate.notNull(name);

        Game game = new Game(name);
        gameDAO.save(game);
    }

    @POST
    @Path("{ID}/{Name}")
    public void updateGame(@PathParam("ID") Long id,
                           @PathParam("Name") String name) {
        Validate.notNull(id);
        Validate.notNull(name);
        Game game = gameDAO.get(id);
        if(game == null){
            throw new IllegalArgumentException("No game found for ID : " + id);
        }

        game.setName(name);
        gameDAO.save(game);
    }

    @DELETE
    @Path("{ID}")
    public void deleteGame(@PathParam("ID") Long id) {
        Validate.notNull(id);
        Game game = gameDAO.get(id);
        if(game == null){
            throw new IllegalArgumentException("No game found for ID : " + id);
        }

        gameDAO.remove(game);
    }

    @Inject
    public void setGameDAO(final GameDAO gameDAO) {
        this.gameDAO = gameDAO;
    }
}
GameRESTTestREST.java
package be.normegil.librarium.rest;

import be.normegil.librarium.LibrariumApplication;
import org.apache.http.HttpStatus;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.jayway.restassured.RestAssured.expect;

@RunWith(Arquillian.class)
public class GameRESTTestREST {

    @Deployment
    public static WebArchive createTestArchive() {
        return ShrinkWrap.create(WebArchive.class)
                .addClass(GameREST.class)
                .addClass(LibrariumApplication.class);
    }

    @Test
    @RunAsClient
    public void testGetAll() throws Exception {
        expect()
                .statusCode(HttpStatus.SC_OK)
                .log().ifError()
                .when()
                .get("/games/all");
    }
}

为什么我有一个 ClassNotFoundExceptionorg.jboss.arquillian.core.api.threading.ExecutorService ?知道问题出在哪里吗?

最佳答案

尝试添加

<dependency>
        <groupId>org.jboss.arquillian.core</groupId>
        <artifactId>arquillian-core-api</artifactId>
        <version>1.1.4.Final</version>
        <scope>test</scope>
</dependency>

关于jakarta-ee - Arquillian - ClassNotFound on org.jboss.arquillian.core.api.threading.ExecutorService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23474223/

相关文章:

android - 尝试访问库项目中的 View 时出现 ClassNotFoundException

java - 从线程创建附加线程的最有效方法是什么?

javarabbitmq带有Executor线程,创建的线程保持运行。如何确保线程被杀死?

html - CSS 文件中的部分类不起作用 (J2EE)

java - 使用 JNA 和 Windows sendMessage API 从基于 java 的 Web 应用程序更改 Windows XP 中的焦点窗口

java - 什么是 CDI bean?

maven - 错误:无法找到或加载主类org.apache.mahout.driver.MahoutDriver

java - Eclipse 项目布局类路径问题

java - hibernate jpa java.lang.ClassCastException : model. Dog 无法转换为 model.Dog

java - ExecutorService 固定线程拒绝