arquillian persistence extension doesn't work

雨燕双飞 提交于 2019-12-11 17:58:24

问题


I'm trying to get my webservice tested. This webservice uses ejb with jpa to retrieve its data. So i want to use the arquillian extension to get this done.

This is my arquillian test class:

@RunWith(Arquillian.class)
public class PersonWebServiceIT {

    private PersonWebService service;

    @Deployment(testable = false)
    public static Archive<?> createDeployment() {
        return ShrinkWrap
                .create(ZipImporter.class, "test.ear")
                .importFrom(new File("simple-webservice-ear-1.0.0-SNAPSHOT.ear"))
                .as(EnterpriseArchive.class);
    }

    @Test
    @UsingDataSet("dataset.yml")
    @SneakyThrows
    public void testFindPersons(@ArquillianResource final URL deploymentUrl) {
        loadService(deploymentUrl);

        Assert.assertEquals(2, service.findPersons().size());
    }

    private void loadService(final URL deploymentUrl)
        //load webservice
    }

}

This is my datasets/dataset.yml file:

person:
  - id: 1
    firstName: "stijn"
  - id: 2
    firstName: "cremers"

my arquillian.xml:

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/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">

 <extension qualifier="persistence">
        <property name="defaultDataSource">java:/DefaultDS</property>
    </extension>

</arquillian>

My test data never gets loaded. I even tried with a wrongly formatted yml file, but even then i get no error.


回答1:


The problem is with your test run mode. When you define your @Deployment with the attribute testable=false, all tests are run in the client mode, i.e. they're not run in-container.

The Arquillian Persistence Extension (as of 1.0.0.Alpha5) does not support running tests in client mode; only in-container tests are supported for now. Support for client mode tests in APE may come in a future release.




回答2:


<property name="defaultDataSource">java:/DefaultDS</property>

U're specifying the Datasource which is defined in the server.

In client mode, test cases are run outside the Container(ie. Other JVM)

So that only persistence extension can not make use of data source and hence you can not use arquillian persistence extension client mode.

If there is anyway to specify jdbc url instead of datasource name in arquillian.xml file.Then u may use persistence extension



来源:https://stackoverflow.com/questions/14694738/arquillian-persistence-extension-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!