2017-02-03 4 views
0

Я новичок в arquillian.Тестирование Java EE Microservice с Arquillian

Мы строим микросервис под Wildfly 10.1.0. Мы разработали «WAR» с зависимостью от SessionBean. SessionBean разрабатывается как «JAR». Интерфейс SessionBean разработан как дополнительный «JAR» и добавлен как «модуль WildFly». Моя проблема в том, что я должен построить тестирование с аркиллианским. Я работал с управляемой wildfly, но я стал ошибкой, что интерфейс класса не найден в «test.war» от arquillian.

Как я могу разработать «test.war» от arquillian с зависимостью от модулей WildFly.

myTestClass

package com.example.controller.dataConnector; 

import javax.inject.Inject; 
import org.jboss.arquillian.container.test.api.Deployment; 
import org.jboss.arquillian.junit.Arquillian; 
import org.jboss.shrinkwrap.api.ShrinkWrap; 
import org.jboss.shrinkwrap.api.asset.EmptyAsset; 
import org.jboss.shrinkwrap.api.spec.JavaArchive; 
import org.junit.Assert; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import com.example.controller.global.Global; 
import com.example.ejb.interfaces.SessionBeanLogic_Interface; 
import com.example.model.dataModel1; 
import com.example.model.dataModel2; 


@RunWith(Arquillian.class) 
public class dataConnectorTest 
{ 
    @Inject 
    dataConnector dataConnector; 


    @Deployment 
    public static JavaArchive createShrinkWrap() 
    { 
     return ShrinkWrap.create(JavaArchive.class).addClasses(dataConnector.class, Global.class, dataModel1.class, dataModel2.class, SessionBeanLogic_Interface.class).addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); 
    } 

    @Test 
    public void should_say_hello() 
    { 
     Assert.assertEquals("Testversuch", dataConnector.getStr_Value()); 
     System.out.println(siebeldaten.getStr_Value()); 
    } 
} 

MyArquillian.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="wildfly10" default="true"> 
     <configuration> 
      <property name="jbossHome">F:/jboss/wildfly-10.1.0.Final</property> 
     </configuration> 
</container> 
</arquillian> 

myPOM.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>DataFrontend</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>DataFrontend</name> 

    <properties> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.jboss.arquillian</groupId> 
       <artifactId>arquillian-bom</artifactId> 
       <version>1.1.12.Final</version> 
       <scope>import</scope> 
       <type>pom</type> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>EJB_Logic_Interface</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.primefaces</groupId> 
      <artifactId>primefaces</artifactId> 
      <version>6.0</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-impl</artifactId> 
      <version>2.2.14</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
     </dependency> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>7.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.code.gson</groupId> 
      <artifactId>gson</artifactId> 
      <version>2.8.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.arquillian.junit</groupId> 
      <artifactId>arquillian-junit-container</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.wildfly.arquillian</groupId> 
      <artifactId>wildfly-arquillian-container-managed</artifactId> 
      <version>2.0.0.Final</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <compilerArguments> 
         <endorseddirs>${endorsed.dir}</endorseddirs> 
        </compilerArguments> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin>    
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-ejb-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <ejbVersion>3.1</ejbVersion> 
        <archive> 
         <manifestEntries> 
          <Dependencies>com.example.Interfaces.Logic_Interface, com.example.gson.280</Dependencies> 
         </manifestEntries> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.6</version> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>copy</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${endorsed.dir}</outputDirectory> 
          <silent>true</silent> 
          <artifactItems> 
           <artifactItem> 
            <groupId>javax</groupId> 
            <artifactId>javaee-endorsed-api</artifactId> 
            <version>7.0</version> 
            <type>jar</type> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
    <repositories> 
     <repository> 
      <url>http://repository.primefaces.org/</url> 
      <id>PrimeFaces-maven-lib</id> 
      <layout>default</layout> 
      <name>Repository for library PrimeFaces-maven-lib</name> 
     </repository> 
    </repositories> 
</project> 
+1

* "но я стал ошибкой, что интерфейс интерфейса не найден в" test.war "от arquillian" *. Пожалуйста, добавьте полную ошибку, которую вы получили на вопрос. – Gimby

+0

Полная стежка будет определенно помочь нам решить проблему –

ответ

0

Вы должны добавить интерфейс, который реализует dataConnector к ShrinkWrap.create(...).addClasses(...), а не только ваш dataConnector класса.

Arquillian использует то, что явно добавлено в ваш аннотированный метод @Deployment, он не разрешает автоматические решения из maven.

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