我在我的应用程序中使用Arquillian,但是任何测试都无法部署,因为所有测试我都有同样的错误:
org.jboss.arquillian.persistence.core.exception.DataSourceNotFoundException:无法找到给定名称的数据源:java:/ analyticsTestDS
我有standalone.xml数据源,xa-datasource和驱动程序配置。此配置适用于使用相同服务器连接数据库的其他项目。
这是Junit日志:
org.jboss.arquillian.persistence.core.exception.DataSourceNotFoundException: Unable to find data source for given name: java:/analyticsTestDS
at org.jboss.arquillian.persistence.core.datasource.JndiDataSourceProvider.lookupDataSource(JndiDataSourceProvider.java:62)
...
Caused by: javax.naming.NameNotFoundException; remaining name 'java:/analyticsTestDS'
at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:490)
at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:536)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.jboss.arquillian.persistence.core.datasource.JndiDataSourceProvider.lookupDataSource(JndiDataSourceProvider.java:58)
... 86 more
这是Jboss日志:
...
[0m[0m11:50:43,832 INFO [org.jboss.resteasy.plugins.validation.AbstractValidatorContextResolver] (MSC service thread 1-7) Unable to find CDI supporting ValidatorFactory. Using default ValidatorFactory
[0m[0m11:50:43,973 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017534: Registered web context: /test
[0m[0m11:50:44,117 INFO [org.jboss.as.server] (management-handler-thread - 2) JBAS018559: Deployed "test.war" (runtime-name : "test.war")
[0m[0m11:50:46,039 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017535: Unregistered web context: /test
[0m[0m11:50:46,074 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 65) JBAS011410: Stopping Persistence Unit (phase 2 of 2) Service 'test.war#analytics-datasource'
[0m[0m11:50:46,079 INFO [org.infinispan.factories.GlobalComponentRegistry] (ServerService Thread Pool -- 65) ISPN000128: Infinispan version: Infinispan 'Infinium' 6.0.2.Final
[0m[0m11:50:46,322 INFO [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 65) ISPN000031: MBeans were successfully registered to the platform MBean server.
[0m[0m11:50:46,325 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 65) JBAS010281: Started local-query cache from hibernate container
[0m[0m11:50:46,331 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016009: Stopping weld service for deployment test.war
[0m[0m11:50:46,354 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 65) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'test.war#analytics-datasource'
[0m[0m11:50:46,365 INFO [org.jboss.as.clustering.infinispan] (MSC service thread 1-4) JBAS010282: Stopped local-query cache from hibernate container
[0m[0m11:50:46,476 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment test.war (runtime-name: test.war) in 447ms
[0m[0m11:50:46,617 INFO [org.jboss.as.repository] (management-handler-thread - 2) JBAS014901: Content removed from location /usr/local/jboss/wildfly-8.2.1.Final/standalone/data/content/31/e043268729c5760564bfb64faec9b14c158cee/content
[0m[0m11:50:46,617 INFO [org.jboss.as.server] (management-handler-thread - 2) JBAS018558: Undeployed "test.war" (runtime-name: "test.war")
[0m[0m11:50:46,639 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) JBAS010409: Unbound data source [java:/analyticsDS]
[0m[0m11:50:46,639 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010409: Unbound data source [java:jboss/datasources/ExampleDS]
[0m[0m11:50:46,640 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010409: Unbound data source [java:/analyticsAuthDS]
[0m[0m11:50:46,642 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010409: Unbound data source [java:/analyticsTestDS]
[0m[0m11:50:46,642 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017532: Host default-host stopping
[0m[0m11:50:46,645 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010409: Unbound data source [java:/analyticsTimerDS]
[0m[0m11:50:46,650 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010418: Stopped Driver service with driver-name = h2
[0m[0m11:50:46,652 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010418: Stopped Driver service with driver-name = postgresnoxa
[0m[0m11:50:46,652 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017521: Undertow HTTP listener default suspending
[0m[33m11:50:46,652 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 55) IJ000615: Destroying active connection in pool: analyticsTestDS (org.jboss.jca.adapters.jdbc.xa.XAManagedConnection@1c90a7bb)
[0m[33m11:50:46,653 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 55) IJ000615: Destroying active connection in pool: analyticsTestDS (org.jboss.jca.adapters.jdbc.xa.XAManagedConnection@12575a59)
[0m[33m11:50:46,653 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 55) IJ000615: Destroying active connection in pool: analyticsTestDS (org.jboss.jca.adapters.jdbc.xa.XAManagedConnection@1668cccb)
[0m[0m11:50:46,653 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017520: Undertow HTTP listener default stopped, was bound to /127.0.0.1:8080
[0m[0m11:50:46,663 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017506: Undertow 1.1.8.Final stopping
[0m[0m11:50:46,668 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010418: Stopped Driver service with driver-name = postgresql
[0m[0m11:50:46,683 INFO [org.jboss.as] (MSC service thread 1-7) JBAS015950: WildFly 8.2.1.Final "Tweek" stopped in 44ms
[0m
测试:
package com.atomsail.analytics.datasource.service;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import javax.ejb.EJB;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.persistence.DataSource;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.atomsail.analytics.datasource.dao.data.DatasourceDataDAOLocal;
import com.atomsail.analytics.entities.datasourcedata.DatasourceData;
import com.atomsail.analytics.test.jdbc.PostgresDBTestCase;
@RunWith(Arquillian.class)
@DataSource("java:/analyticsTestDS")
@UsingDataSet("datasets/remove-data-dao.xml")
public class RemoveDataServiceImplTest extends PostgresDBTestCase {
@Deployment
public static Archive<?> createTestArchive() {
PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile("pom.xml");
File[] commonsLang = pom.resolve( "org.jadira.usertype:usertype.core",
"org.hibernate:hibernate-validator",
"org.apache.tika:tika-parsers",
"pentaho-kettle:kettle-core",
"pentaho-kettle:kettle-engine",
"pentaho:pentaho-metadata",
"org.scannotation:scannotation",
"com.amazonaws:aws-java-sdk-s3",
"monetdb:monetdb-jdbc",
"pentaho:metastore",
"simple-jndi:simple-jndi",
"joda-time:joda-time").withTransitivity().asFile();
System.out.println(commonsLang.toString());
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
.addPackages(true, "com.atomsail.analytics.datasource")
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource("ejb/remove-data-jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsResource("truncate_all_app.sql")
.addAsLibraries(commonsLang);
System.out.println(war.toString(true));
return war;
}
private String baseURL = getBaseURL();
@EJB
private DatasourceDataDAOLocal datasourceDataDao;
@Test
@InSequence(1)
public void removeData() {
assertNotNull(datasourceDataDao);
// more code here
}
@Override
protected String dropDDLScript() {
return "truncate_all_app.sql";
}
}
我的arquillian.xml
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0" />
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">/usr/local/jboss/wildfly-8.2.1.Final</property>
<property name="javaVmArguments">-Xms512m -Xmx3048m</property>
</configuration>
</container>
</arquillian>
答案 0 :(得分:0)
在你的arquillian.xml中,你可以添加它告诉wildfly使用xml配置的配置:
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">${jboss.home}</property>
<property name="serverConfig">standalone-full.xml</property>
<!-- uncomment below for debugging
<property name="javaVmArguments">-Xmx512m -XX:MaxPermSize=128m -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8787</property>
-->
</configuration>
</container>
显然,如果您使用的是不在wildfly的主要部署中的其他内容,那么请更改文件的路径,但是如果您已经在那里设置了数据源,那么应该告诉wildfly使用哪个版本。