arquillian webarchive CDI为空

时间:2019-06-26 04:13:56

标签: jboss-arquillian arquillian-drone

我有两个页面的简单spring应用程序。 经过Arquillian测试,似乎MyService CDI始终为null。 在托管容器eap 7中运行 在@controller中正常工作

任何建议,谢谢。

package my.arq.test;

import com.journaldev.spring.service.MyService;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OverProtocol;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

import javax.inject.Inject;
import java.io.File;
import java.net.URL;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.jboss.arquillian.graphene.Graphene.guardHttp;

@RunWith(Arquillian.class)
public class MyFirstTest {

    @Drone
    private WebDriver browser;

    @ArquillianResource
    private URL deploymentUrl;

    @FindBy(how = How.ID, using = "userName")                                  // 2. injects an element
    private WebElement userName;

    @FindBy(id = "login")
    private WebElement loginButton;

    @FindBy(id = "resp")
    private WebElement respElem;

    @Deployment
    @OverProtocol("Servlet 3.0")
    public static WebArchive createDeployment() {
        return ShrinkWrap.
                  create(ZipImporter.class, "project1.war")
                .importFrom(new File("target/spring-me.war"))
                .as(WebArchive.class)
                        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    }

    @Inject
    private MyService myService;

    @RunAsClient
    @Test
    public void bingo() {
        browser.get(deploymentUrl.toExternalForm());
        userName.sendKeys("dummy");
        guardHttp(loginButton).click();
        assertThat(respElem.getText(), is("Hi dummy"));
        assertThat(myService, is(not(nullValue())); // fails here
    }
}

0 个答案:

没有答案