如何在测试类中查找EJB,但接口是否在其他maven项目中?

时间:2015-01-22 17:52:43

标签: java java-ee jboss ejb jndi

我正在使用TestNG测试EJB项目并使用JBoss-Embedded-EJB,我在另一个独立的项目上实现了我的接口,并且我在项目中实现了声明,我做了测试,实体是他们的参与另一个项目。 所以我有树项目:

  1. OAP-实体
  2. oap-Interfaces(包含我的所有接口)
  3. oap-Impli(包含oap-interfaces项目的所有实现)
  4. 所有这些项目都是青少年。

    我尝试使用jboss-embedded进行TestNG测试,但是我在运行maven-test之后每次都给出了以下错误:#/ p>

    T E S T S
     -------------------------------------------------------
    Running TestSuite
    WARN  22-01 17:55:41,764 (BeanSchemaBinding.java:init:233)  -You should use the 2.0 version of the Microcontainer xml. xmlns='urn:jboss:bean-deployer:2.0'
    lookup
    UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
    javax.naming.NameNotFoundException: ejb: not bound
    Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 2.408 sec <<< FAILURE!
    

    我跟着quickstart:

    在oap-interfaces项目的pom.xml中,我创建了oap-models的依赖项,而在oap-impl项目中,我也创建了oap-interfaces项目的依赖项。

    oap-impl中的测试类看起来像:

    package com.jboss.embedded.testng;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
    import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    import com.jboss.embedded.testng.Impl.PersonFact;
    import org.oap-interfaces.mine.locals.IPersonLocal;
    import org.oap-interfaces.mine.remotes.IPersonRemote;
    public class HelloWorldTest {
    private static boolean containerRunning = false;
    private EJB3StandaloneDeployer deployer;
    Private IPersonRemote iPersonRemote;
    private IPersonLocal iPersonLocal;
    
    @BeforeClass
    public void init() {
        startupEmbeddedContainer();
        InitialContext initialContext;
        try {
            initialContext = new InitialContext();
            iPersonLocal = (IPersonLocal) initialContext.lookup("PersonFact/local");
            iPersonFactoryRemote = (IPersonRemote) initialContext.lookup("PersonFact/remote");
        } catch (NamingException e) {
            System.out.println("*** Can't looked up the EJB's ***" + e);
        }
    }
    @Test
    public void localTest() {
        System.out.println("**** Local find Client by ID => "+ iPersonLocal.findByClient("1").getFirstName() + " "+iPersonLocal.findByClient("1").getLastName());
    }
    @Test
    public void remoteTest() {
        System.out.println("**** Remote find Client by ID => "+ iPersonRemote.findByClient("1").getFirstName() + " "+ iPersonLocal.findByClient("1").getLastName());
    }
    @AfterClass
    public void terminate() throws Exception {
        deployer.stop();
        deployer.destroy();
    
        EJB3StandaloneBootstrap.shutdown();
    
        containerRunning = false;
    }
    private void startupEmbeddedContainer() {
        if (!containerRunning) {
            EJB3StandaloneBootstrap.boot(null);
            deployer = EJB3StandaloneBootstrap.createDeployer();
            deployer.getArchivesByResource().add("META-INF/persistence.xml");
            try {
                deployer.create();
                deployer.start();
            } catch (Exception e) {
                System.out
                        .println("*** Deployer can't be created and the persistance.xml can't be added ***" + e);
            }
            containerRunning = true;
            }
        }
    }
    

    它是如何给我的错误的?

0 个答案:

没有答案