conda-forge_使用Forge插件在现有Java EE项目上启用Arquillian

conda-forge

conda-forge

技术提示#34解释了如何创建可测试的Java EE 7应用程序。 如果您要启动新的应用程序,这将很有用。 但是,如果您已经有一个应用程序并启用Arquillian怎么办?

这就是ForgeForge-Arquillian附加组件派上用场的地方。 这就是我在javaee7-simple-sample中添加对Arquillian的支持的方式。

让我们看看已经完成了!

  1. 下载并安装Forge。 您可以在自己喜欢的位置下载ZIP并解压缩,也可以使用下面的命令为您完成:
    Downloads> curl http://forge.jboss.org/sh | sh
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  2725    0  2725    0     0   4641      0 --:--:-- --:--:-- --:--:--  4642
    /usr/bin/java
    Downloading Forge
    ######################################################################## 100.0%
    Archive:  /Users/arungupta/.forge/forge_installer.zip
       creating: /Users/arungupta/forge/forge-distribution-2.12.2.Final/
       creating: /Users/arungupta/forge/forge-distribution-2.12.2.Final/img/
    
    . . .
    
    If you have not yet seen the Forge built-in commands, you may either press TAB to see a list of the currently available commands, or get a more descriptive list by typing:
    
    $ command-list
    
    Then to get started - see the docs at
    http://forge.jboss.org/documentation 
    Consider installing Git and Maven 3.1+ (both optional)
    
    Restart Terminal to use forge.
  2. 克隆simple-javaee7-sample仓库
    git clone https://github.com/javaee-samples/javaee7-simple-sample.git
  3. 将目录更改为javaee7-simple-sample并启动Forge:
    javaee7-simple-sample> ~/tools/forge-distribution-2.12.2.Final/bin/forge
    Using Forge at /Users/arungupta/tools/forge-distribution-2.12.2.Final
    
        _____                    
       |  ___|__  _ __ __ _  ___ 
       | |_ / _ \| `__/ _` |/ _ \  \\
       |  _| (_) | | | (_| |  __/  //
       |_|  \___/|_|  \__, |\___| 
                       |__/      
    
    JBoss Forge, version [ 2.12.2.Final ] - JBoss, by Red Hat, Inc. [ http://forge.jboss.org ]
  4. 安装Forge-Arquillian附加组件:
    [javaee7-simple-sample]$ addon-install-from-git --url https://github.com/forge/addon-arquillian.git
    ***INFO*** Installing Addon from Git 	[0/4] ...
    ***INFO*** Installing Addon from Git:Cloning repository in /var/folders/3v/syxsk5zx3yqd_8g9m206py_h0000gn/T/1416131293813-0 	[0/4] ...
    ***INFO*** Installing Addon from Git:Installing project into local repository 	[1/4] ...
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Arquillian Forge Addon 1.0.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    
    . . .
    
    Downloading: http://repo1.maven.org/maven2/org/jboss/forge/addon/maven-impl-projects/2.12.2.Final/maven-impl-projects-2.12.2.Final.pom
    Downloaded: http://repo1.maven.org/maven2/org/jboss/forge/addon/maven-impl-projects/2.12.2.Final/maven-impl-projects-2.12.2.Final.pom (4 KB at 16.9 KB/sec)
    ***SUCCESS*** Addon org.arquillian.forge:arquillian-addon,1.0.0-SNAPSHOT was installed successfully.
  5. 配置Arquillian附加组件并安装WildFly适配器:
    [javaee7-simple-sample]$ arquillian-setup --testFramework junit --containerAdapter wildfly-remote 
    Downloading: http://repo1.maven.org/maven2/org/wildfly/wildfly-arquillian-container-remote/maven-metadata.xml
    Downloaded: http://repo1.maven.org/maven2/org/wildfly/wildfly-arquillian-container-remote/maven-metadata.xml (702 B at 4.2 KB/sec)
    ***SUCCESS*** Arquillian setup complete
    ***SUCCESS*** Installed Arquillian 1.1.5.Final
    ***SUCCESS*** Installed junit
    ***SUCCESS*** Installed Arquillian Container WildFly Remote 8.x
    ***SUCCESS*** Installed Arquillian Container WildFly Remote 8.x dependencies

    适配器列表如下所示:

    glassfish-embedded-3.1       jetty-embedded-6.1           tomee-remote                 
    glassfish-managed-3.1        jetty-embedded-7             was-embedded-8               
    glassfish-remote-3.1         openejb-embedded-3.1         was-remote-7                 
    jbossas-embedded-6           openejb-embedded-4           was-remote-8                 
    jbossas-managed-4.2          openshift-express            weld-ee-embedded-1.1         
    jbossas-managed-5.1          openwebbeans-embedded-1      weld-se-embedded-1           
    jbossas-managed-6            tomcat-embedded-6            weld-se-embedded-1.1         
    jbossas-managed-7            tomcat-embedded-7            wildfly-managed              
    jbossas-remote-4.2           tomcat-managed-5.5           wildfly-remote               
    jbossas-remote-5             tomcat-managed-6             wls-remote-10.3              
    jbossas-remote-5.1           tomcat-managed-7             
    jbossas-remote-6             tomcat-remote-6

    这使您可以配置所选的容器。 这会将以下配置文件添加到您的“ pom.xml”中:

    
         
         
        
          
          
           
           arquillian-wildfly-remote
          
          
        
          
          
            
           
           
                
            
            
                    
             
             
               maven-surefire-plugin 
             
                    
             
             
               2.14.1 
             
                    
             
              
               
               
                 arquillian-wildfly-remote 
                
               
             
                
            
            
            
           
           
        
          
          
        
          
          
            
           
           
                
            
            
             
             org.wildfly
            
            
                
            
            
             
             wildfly-arquillian-container-remote
            
            
                
            
            
             
             8.1.0.Final
            
            
                
            
            
             
             test
            
            
            
           
           
        
          
          
    
         
         

    该配置文件包括“ wildfly-arquillian-container-remote”依赖性,该依赖性使Arquillian可以与在远程“模式”下运行的WildFly连接。 默认主机为“ localhost”,端口为“ 8080”。 “ maven-surefire-plugin”将传递一个值为“ arquillian-wildfly-remote”的“ arquillian.launch”配置属性。 这与生成的“ arquillian.xml”中的“容器”限定符匹配。“ arquillian.xml”用于定义配置设置以定位容器或与容器通信。 在我们的情况下,WildFly在默认主机和端口上运行,因此不需要更新此文件。 需要注意的重要部分是“容器”限定符与“ arquillian.launch”限定符值匹配。

    
         
         
    
         
         
        
          
          
    
         
         

    这个文件。 有关此配置文件的更多详细信息,请参见此处

  6. 在修复FORGE-2148之前,还需要添加JAX-RS实现以及相应的JAXB提供程序。 该测试使用的是RESTEasy,因此需要添加以下内容:
    
         
         
        
          
          
           
           org.jboss.resteasy
          
          
        
          
          
           
           resteasy-client
          
          
        
          
          
           
           3.0.5.Final
          
          
        
          
          
           
           test
          
          
    
         
         
    
         
         
        
          
          
           
           org.jboss.resteasy
          
          
        
          
          
           
           resteasy-jaxb-provider
          
          
        
          
          
           
           3.0.5.Final
          
          
        
          
          
           
           test
          
          
    
         
         

    可以在概要文件或项目范围的依赖项中添加它。

现在您可以测试了!

下载WildFly 8.1并解压缩。 以以下方式启动服务器:

./bin/standalone.sh

运行测试:

javaee7-simple-sample> mvn test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloworld ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloworld ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.14.1:test (default-test) @ helloworld ---
[INFO] Surefire report directory: /Users/arungupta/workspaces/javaee7-simple-sample/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.javaee7.sample.PersonTest
Nov 16, 2014 1:53:57 PM org.xnio.Xnio 
INFO: XNIO version 3.2.0.Beta4
Nov 16, 2014 1:53:57 PM org.xnio.nio.NioXnio 
INFO: XNIO NIO Implementation Version 3.2.0.Beta4
Nov 16, 2014 1:53:57 PM org.jboss.remoting3.EndpointImpl 
INFO: JBoss Remoting version (unknown)
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.963 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.403 s
[INFO] Finished at: 2014-11-16T13:53:59+02:00
[INFO] Final Memory: 17M/309M
[INFO] ------------------------------------------------------------------------

现在,您已经使用Arquillian启用了现有项目!

在此处提交任何问题

请享用!

翻译自: https://www.javacodegeeks.com/2014/11/enable-arquillian-on-an-existing-java-ee-project-using-forge-addon.html

conda-forge

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值