[code]
@Stateful(mappedName = “ejb/ClientManager”)
@Name(“clientManager”)
@Local(OrganizationManagerInterface.class)
@Remote(OrganizationManagerInterface.class)
@Scope(ScopeType.CONVERSATION)
public class ClientManager implements OrganizationManagerInterface {
…
…
/**
* EntityManager
*/
@In
private EntityManager entityManager;
public List<Organization> searchAll() {
..
..
..
return criteria.list();
}
} [/code]
Pessoal, já pesquisei bastante mais ainda não consegui, estou começando a utilizar o Junit para teste.
Alguem sabe como criar um mock (easymock) que consiga se comunicar realmente com o banco de dados (@in). A dificuldade para conseguir esse acesso ao BD esta muita - rsrs
Vejam como estou fazendo:
public class ClientManagerTest {
/**
* ClientManager
*/
private ClientManager clientManager;
/**
* OrganizationManagerInterface
*/
private OrganizationManagerInterface mock;
/**
* List of organization
*/
private List<Organization> organizationList = new ArrayList<Organization>();
/**
* setUp
* @throws Exception Exception
*/
@Before
public void setUp() throws Exception {
this.setClientManager(new ClientManager());
this.mock = createStrictMock(OrganizationManagerInterface.class);
}
/**
* testSearchAll
*/
@Test
public void testSearchAll() {
expect(this.mock.searchAll()).andReturn(organizationList);
replay(this.mock);
if (this.mock.searchAll().size() == 0) {
fail("busca não retornou registros.");
}
}
}
O problema q não esta existindo acesso ao BD, pois o size do searchAll retorna 0, quando na realidade essa busca teria q retornar em torno de 50 registros existente na base de dados.
Desde já agredeço!