使用H2数据库进行Thorntail Arquillian-Test for pactProvider测试

时间:2018-10-17 13:00:45

标签: java h2 jboss-arquillian thorntail

我正在尝试在我的项目中运行Arquillian测试,其中包含用于pact提供者测试的h2数据库。

但是我收到以下错误消息:

2018-10-17 14:43:15,826错误[org.jboss.as.controller.management-operation](ServerService线程池-28)[/]-WFLYCTL0013:操作(“添加”)失败-地址:([     (“子系统” =>“数据源”),     (“ jdbc-driver” =>“ h2”) ])-故障描述:“ WFLYJCA0041:无法加载驱动程序[com.h2database.h2]的模块”

我的project-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;
}

和我的test-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>

1 个答案:

答案 0 :(得分:0)

我必须将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>