how to look up an EJB in a test class but interfac

2019-09-13 05:43发布

I work on the test of a EJB project with TestNG and by using JBoss-Embedded-EJB and I have my interfaces on another separated project and implementations sound on the project on the which I make the tests and the Entities are of their part on another project. So i have tree projects:

  1. oap-Entities
  2. oap-Interfaces (contains all my interfaces)
  3. oap-Impli (contains all the implementations of oap-interfaces project)

All these projects are mavenzed.

I try to use jboss-embedded for testing by TestNG but i gives every time after running as maven-test the following erros on the consol:

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!

i followed that quickstart:

In the pom.xml of oap-interfaces project i make the dependencies of oap-models and in the oap-impl projet i make also the dependencies of oap-interfaces project.

The test class in the oap-impl looks like :

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;
        }
    }
}

how it gives me that errors ?

0条回答
登录 后发表回答