带有 h2 数据库的 Thorntail Arquillian-Test 用于 pactProvider 测试

Thorntail Arquillian-Test with h2 database for pactProvider test

我正在尝试对我的项目进行 运行 Arquillian 测试,其中包含用于协议提供程序测试的 h2 数据库。

但我收到以下错误消息:

2018-10-17 14:43:15,826 错误 [org.jboss.as.controller.management-操作] (ServerService 线程池 -- 28) [/] - WFLYCTL0013: 操作 ("add") 失败- 地址: ([ ("subsystem" => "datasources"), ("jdbc-driver" => "h2") ]) - 故障描述:"WFLYJCA0041: Failed to load module for driver [com.h2database.h2]"

我的项目-defaults.yaml 包含以下内容:

datasources:
  jdbc-drivers:
    h2:
      driver-class-name: org.h2.Driver
      xa-datasource-class-name: org.h2.jdbcx.JdbcDataSource
      driver-module-name: com.h2database.h2
  data-sources:
    ExmapleDS:
      driver-name: h2
      connection-url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
      user-name: sa
      password: sa

我的 Arquillian 部署

@Deployment(testable = false)
public static WebArchive createDeployment() {
    PomEquippedResolveStage pomFile = Maven.resolver().loadPomFromFile("pom.xml");

    File[] libs = Maven.configureResolver().loadPomFromFile("pom.xml")
    .importRuntimeAndTestDependencies().resolve()
    .withTransitivity().asFile();

    WebArchive archive = ShrinkWrap.create(WebArchive.class)
    .addAsLibraries(pomFile.resolve("org.apache.commons:commons-lang3").withTransitivity().asFile())
    .addAsLibraries(pomFile.resolve("io.thorntail:datasources:2.2.0.Final").withTransitivity().asFile())
    .addAsLibraries(pomFile.resolve("com.h2database:h2:1.4.197").withTransitivity().asFile())
    .addAsLibraries(pomFile.resolve("org.assertj:assertj-core").withTransitivity().asFile())
    .addAsLibraries(libs)
    .addPackage(ShoppingCart.class.getPackage())
    .addClass(Product.class)
    .addClass(TracerResolver.class)
    .addClass(ShoppingCartOpenApiFilter.class)
    .addPackage(Persistence.class.getPackage())
    .addPackage(ShoppingCartResource.class.getPackage())
    .addAsResource("import.sql")
    .addAsWebInfResource("test-persistence.xml", "META-INF/persistence.xml")
    .addAsResource("project-defaults.yml")
    .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("META-INF/beans.xml"));

    LOG.debug(archive.toString(true));
    return archive;
}

和我的测试-persistence.xml

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
         http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
         version="2.1">
  <persistence-unit name="ExampleDS" transaction-type="JTA">
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
      <property name="javax.persistence.schema-generation.create-source" value="metadata"/>
      <property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
      <property name="javax.persistence.sql-load-script-source" value="import.sql"/>
    </properties>
  </persistence-unit>
</persistence>

我不得不为 h2 添加一个 module.xml 到 scr/main/resources/modules/com/h2database/h2/main

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2015 Red Hat, Inc. and/or its affiliates.
  ~
  ~ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
  -->
<module xmlns="urn:jboss:module:1.3" name="com.h2database.h2">

  <resources>
    <artifact name="com.h2database:${h2.version}"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
  </dependencies>
</module>