在OpenShift上托管的WildFly实例上进行Arquillian测试

技术提示#54解释了如何为现有Java EE项目启用Arquillian。 在该技巧中,测试是针对本地安装的WildFly服务器运行的。 如果此WildFly实例在OpenShift上运行,那么同一个适配器也可以工作吗? 没有!

因为与xlocalhost相比,PaaS的安全性约束和要求是不同的。 让我们看一下对OpenShift上托管的WildFly实例在javaee7-simple-sample中运行测试所需要的条件。

让我们开始吧!

  1. 技术提示52中所述 ,在OpenShift上创建WildFly应用程序,如下所示:
    workspaces>rhc app-create mywildfly jboss-wildfly-8
    Application Options
    -------------------
    Domain:     milestogo
    Cartridges: jboss-wildfly-8
    Gear Size:  default
    Scaling:    no
    
    Creating application 'mywildfly' ... Artifacts deployed: ./ROOT.war
    done
    
      WildFly 8 administrator added.  Please make note of these credentials:
    
       Username: adminMYtMTDb
       Password: tq1K-QYLFgBD
       
       run 'rhc port-forward mywildfly' to access the web admin area on port 9990.
    
    Waiting for your DNS name to be available ... done
    
    Cloning into 'mywildfly'...
    Warning: Permanently added the RSA host key for IP address '54.163.64.193' to the list of known hosts.
    
    Your application 'mywildfly' is now available.
    
      URL:        http://mywildfly-milestogo.rhcloud.com/
      SSH to:     54699516ecb8d41cb8000016@mywildfly-milestogo.rhcloud.com
      Git remote: ssh://54699516ecb8d41cb8000016@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/
      Cloned to:  /Users/arungupta/workspaces/mywildfly
    
    Run 'rhc show-app mywildfly' for more details about your app.

    从日志中记下ssh用户名。 这是@之前与SSH to对应的值中的部分。

  2. FORGEPLUGINS-177解决之前,我们需要手动添加Maven配置文件并在“ arquillian.xml”中提供容器配置信息。 将以下<profile>添加到“ pom.xml”:
    <profile>
        <id>arquillian-wildfly-openshift</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.14.1</version>
                    <configuration>
                        <systemPropertyVariables>
                            <arquillian.launch>arquillian-wildfly-openshift</arquillian.launch>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian.container</groupId>
                <artifactId>arquillian-openshift</artifactId>
                <version>1.0.0.Final-SNAPSHOT</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

    这是使用arquillian-openshift容器,并引用arquillian-wildfly-openshift配置,该配置将与“ arquillian.xml”中的相应容器匹配。 因此,这就是更新的“ arquillian.xml”的外观:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <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="arquillian-wildfly-remote"/>
        <container qualifier="arquillian-wildfly-openshift">
            <configuration>
                <property name="namespace">milestogo</property>
                <property name="application">mywildfly</property>
                <property name="libraDomain">rhcloud.com</property>
                <property name="sshUserName">54699516ecb8d41cb8000016</property>
                <property name="login">arungupta@redhat.com</property>
                <property name="deploymentTimeoutInSeconds">300</property>
                <property name="disableStrictHostChecking">true</property> 
            </configuration>
        </container>
    </arquillian>

    注意带有限定符arquillian-wildfly-openshift的新<container> 。 它提供有关服务器位置以及其他一些配置属性的信息。 sshUserName属性值应与先前创建的WildFly实例的值相同。

  3. 就是这样,现在您可以在OpenShift上针对WildFly实例运行测试:
    javaee7-simple-sample> mvn test -Parquillian-wildfly-openshift
    [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 17, 2014 11:18:24 AM org.jboss.arquillian.container.openshift.OpenShiftContainer start
    INFO: Preparing Arquillian OpenShift container at http://mywildfly-milestogo.rhcloud.com
    Nov 17, 2014 11:19:19 AM org.jboss.arquillian.container.openshift.OpenShiftRepository push
    INFO: Pushed to the remote repository ssh://54699516ecb8d41cb8000016@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/
    Nov 17, 2014 11:20:56 AM org.jboss.arquillian.container.openshift.OpenShiftRepository push
    INFO: Pushed to the remote repository ssh://54699516ecb8d41cb8000016@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 152.653 sec
    Nov 17, 2014 11:20:56 AM org.jboss.arquillian.container.openshift.OpenShiftContainer stop
    INFO: Shutting down Arquillian OpenShift container at http://mywildfly-milestogo.rhcloud.com
    
    Results :
    
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 05:46 min
    [INFO] Finished at: 2014-11-17T11:24:09+02:00
    [INFO] Final Memory: 12M/309M
    [INFO] ------------------------------------------------------------------------

请享用!

翻译自: https://www.javacodegeeks.com/2014/11/arquillian-tests-on-a-wildfly-instance-hosted-on-openshift.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值