2

Я пытаюсь сделать тест с Arquillian в проекте Maven, однако в каждом выполнении теста, который дает мне следующее исключение:Arquillian: Не удалось настроить GlassFish Embedded Runtime

Grave: Exception in command execution : java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.855 sec <<< FAILURE! 
Tests in error: 
es.costa.service.test.magali.PersonaFactorTest: Could not setup GlassFish Embedded Runtime 
Caused by: org.glassfish.embeddable.GlassFishException: PlainTextActionReporterFAILUREjava.lang.NoClassDefFoundError: javax/validation/ParameterNameProviderjava.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider 
java.lang.RuntimeException: Could not setup GlassFish Embedded Runtime 

Это ПОМ .xml:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.jboss.arquillian</groupId> 
      <artifactId>arquillian-bom</artifactId> 
      <version>1.0.3.Final</version> 
      <scope>import</scope> 
      <type>pom</type> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 
<dependencies> 
    <dependency> 
     <groupId>org.jboss.ejb3</groupId> 
     <artifactId>jboss-ejb3-ext-api</artifactId> 
     <version>2.1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>es.costa</groupId> 
     <artifactId>costa-interfaces</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.arquillian.junit</groupId> 
     <artifactId>arquillian-junit-container</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>5.1.3.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator-annotation-processor</artifactId> 
     <version>5.0.3.Final</version> 
    </dependency> 
</dependencies> 
<build> 
    <sourceDirectory>ejbModule/src/main/java</sourceDirectory> 
    <testSourceDirectory>ejbModule/src/test/java</testSourceDirectory> 
    <resources> 
     <resource> 
      <directory>ejbModule/src/main/resources</directory> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </resource> 
    </resources> 
    <testResources> 
     <testResource> 
      <directory>ejbModule/src/test/resources</directory> 
     </testResource> 
    </testResources> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>${maven-compiler-plugin.version}</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
       <encoding>Cp1252</encoding> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.12</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-ejb-plugin</artifactId> 
      <version>${maven-ejb-plugin.version}</version> 
      <configuration> 
       <ejbVersion>${ejb.version}</ejbVersion> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <artifactSet> 
        <includes> 
         <include>es.costa</include> 
        </includes> 
       </artifactSet> 
       <finalName>${artifactId}-${project.version}</finalName> 
      </configuration> 
     </plugin> 


     <plugin> 
      <groupId>org.jboss.as.plugins</groupId> 
      <artifactId>jboss-as-maven-plugin</artifactId> 
      <configuration> 
       <filename>${artifactId}-${project.version}.jar</filename> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<profiles> 
    <profile> 
     <id>dev</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <dependencies> 
      <dependency> 
       <groupId>org.hibernate</groupId> 
       <artifactId>hibernate-entitymanager</artifactId> 
       <scope>test</scope> 
      </dependency> 
      <dependency> 
       <groupId>javax.persistence</groupId> 
       <artifactId>persistence-api</artifactId> 
       <version>${javax-persistance.version}</version> 
       <scope>test</scope> 
      </dependency> 
     </dependencies> 
    </profile> 
    <profile> 
     <id>jenkins</id> 
     <dependencies> 
      <dependency> 
       <groupId>org.hibernate</groupId> 
       <artifactId>hibernate-entitymanager</artifactId> 
       <scope>test</scope> 
      </dependency> 
      <dependency> 
       <groupId>javax.persistence</groupId> 
       <artifactId>persistence-api</artifactId> 
       <version>${javax-persistance.version}</version> 
       <scope>test</scope> 
      </dependency> 
     </dependencies> 
    </profile> 
    <profile> 
     <id>arquillian-glassfish-embedded</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <dependencies> 
      <dependency> 
       <groupId>org.jboss.arquillian.container</groupId> 
       <artifactId>arquillian-glassfish-embedded-3.1</artifactId> 
       <version>1.0.0.CR3</version> 
       <scope>test</scope> 
      </dependency> 
      <dependency> 
       <groupId>org.glassfish.main.extras</groupId> 
       <artifactId>glassfish-embedded-all</artifactId> 
       <version>3.1.2</version> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>com.h2database</groupId> 
       <artifactId>h2</artifactId> 
       <version>1.3.166</version> 
       <scope>test</scope> 
      </dependency> 
     </dependencies> 
     <build> 
      <testResources> 
       <testResource> 
        <directory>ejbModule/src/test/resources</directory> 
       </testResource> 
       <testResource> 
        <directory>ejbModule/src/test/resources-glassfish-embedded</directory> 
       </testResource> 
      </testResources> 
      <plugins> 
       <plugin> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.12</version> 
        <configuration> 
         <systemPropertyVariables> 
          <arquillian.launch>glassfish-embedded</arquillian.launch> 
          <java.util.logging.config.file> 
           ${project.build.testOutputDirectory}/logging.properties 
          </java.util.logging.config.file> 
          <derby.stream.error.file> 
           ${project.build.directory}/derby.log 
          </derby.stream.error.file> 
         </systemPropertyVariables> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

это 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"> 

<container qualifier="glassfish-embedded" default="true"> 
    <configuration> 
     <property name="resourcesXml"> 
      ejbModule/src/test/resources-glassfish-embedded/glassfish-resources.xml 
     </property> 
    </configuration> 
</container>  

Это GlassFish-resources.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE resources PUBLIC 
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" 
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> 
<resources> 
<jdbc-resource pool-name="ArquillianEmbeddedH2Pool" 
    jndi-name="jdbc/arquillian"/> 
<jdbc-connection-pool name="ArquillianEmbeddedH2Pool" 
    res-type="javax.sql.DataSource" 
    datasource-classname="org.h2.jdbcx.JdbcDataSource"> 
    <property name="user" value="sa"/> 
    <property name="password" value=""/> 
    <property name="url" value="jdbc:h2:file:target/databases/h2/db"/> 
</jdbc-connection-pool>  

ответ

0

Есть много проблем с файлами, которые я могу видеть даже не пытаясь кода. Многие из необходимых шагов и конфигураций отсутствуют в ваших файлах.

  1. Вы не имеете ссылку на arquillian контейнер с вашего pom.xml

    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId>      
        <configuration> 
         <systemPropertyVariables>        
          <arquillian.launch>glassfish-embedded</arquillian.launch> 
         </systemPropertyVariables> 
        </configuration> 
    </plugin> 
    
  2. Вы должны убедиться, что GlassFish свойства контейнера правильно указаны в arquillian.xml. Пример:

    <property name="resourcesXml">src/test/resources/domain.xml</property> 
    <property name="glassFishHome">${glassfish.managed.home}</property> 
    

    Вы можете получить полный список свойств в https://docs.jboss.org/author/display/ARQ/GlassFish+3.1+-+Embedded

  3. Обратите особое внимание на то указание glassfish-resources.xml или domain.xml в resourcesXml attrbiute. Как правило, вы можете иметь glassfish-resources.xml в комплекте с войной приложения.

Я предлагаю вам обратиться к:

  1. https://github.com/arquillian/arquillian-examples
  2. http://arquillian.org/guides/getting_started/
+0

Первый поблагодарить вас за то, чтобы ответить на мой пост: 1) Я не то, что вы имеете в виду под этим? 2) Свойства контейнера стеклянной рыбы правильно указаны в arquillian.xml – TinyOS

+0

Пояснение к точке 1: В pom.xml, контейнер arquillian должен знать, какой фактический контейнер использовать, например, glassfish, jboss и т. д. Ему нужно перейти к arquillian.xml, а затем прочитать свойства контейнера. Этот шаг включил эту ссылку. – KDK

+0

Я добавил изменения, как вы сказали, но это дает мне ту же ошибку, и я меняю местоположение файлов: 'glassfish-resources.xml' и' test-persistence.xml' и 'logging.properties' в ejbModule/src/test/resources - встроенная исходная папка – TinyOS

0

я снял блок кода:

<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-validator</artifactId> 
    <version>5.1.3.Final</version> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-validator-annotation-processor</artifactId> 
    <version>5.0.3.Final</version> 
</dependency> 

И я думаю, что он решил интерес м, но теперь у меня есть другое сообщение об ошибке:

ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer. 
+1

Я сделал это: '.... JavaArchive баночку = ShrinkWrap.create (JavaArchive.class, "ES-КПКТ-SERVI") .addPackage (PersonFactory.class.getPackage()) .addPackage (IPersonFactoryLocal.class .getPackage()) .addAsManifestResource ("test-persistence.xml", "META-INF/persistence.xml") .addAsManifestResource ("jbossas-ds.xml") .addAsManifestResource (EmptyAsset.INSTANCE, "beans. XML "); ... ' – TinyOS

+0

, и теперь у меня есть тест, прошедший с успехами, но когда я пытаюсь ввести свой ejb, используя в тестовом методе systeme.out.println (IjectedEJB.getMessage); это дает мне следующее: 'shouldFindAllGamesUsingJpqlQuery (es.costa.service.all.test.opa.IjectedEJBTest)' – TinyOS

Смежные вопросы