Em 7/10/2011 17:03, Alen Vrečko escreveu:
What does the ECFEntityManager.getEntityManager() do?
Btw: You might want to take a look at an already existing Guice-JUnit
integration such as Guiceberry or Juckito.
Cheers
Alen
On Oct 6, 2:50 pm, Luiz Eduardo<[email protected]> wrote:
hi all
i have a RCP application which i'm trying to test with junit and google
guice.
i have a module like this:
@Override
protected void configure() {
bind(PapelRepository.class).to(PapelRepostitoryImpl.class).in(Scopes.SINGLE
TON);
bind(UsuarioRepository.class).to(UsuarioRepositroyImpl.class).in(Scopes.SIN
GLETON)
}
@Provides
public EntityManager getEntityManger(){
return ECFEntityManager.getEntityManager();
}
and, following some tutorials, i made 2 classes: GuiceIntegration and
GuiceTestRunner
public class GuiceTestRunner extends BlockJUnit4ClassRunner {
private final Injector injector;
/**
* Creates a new GuiceTestRunner.
*
* @param classToRun the test class to run
* @param Guice modules
* @throws InitializationError if the test class is malformed
*/
public GuiceTestRunner(final Class<?> classToRun, Module...
modules) throws InitializationError
{
super(classToRun);
this.injector = Guice.createInjector(modules);
}
@Override
public Object createTest()
{
return injector.getInstance(getTestClass().getJavaClass());
}
@Override
protected void validateZeroArgConstructor(List<Throwable> errors){}
/**
* Returns the Guice injector.
*
* @return the Guice injector
*/
protected Injector getInjector()
{
return injector;
}
}
and
public class GuiceIntegration extends GuiceTestRunner {
public GuiceIntegration(Class<?> classToRun) throws
InitializationError {
super(classToRun, new GermantechModule());
}
}
and when i try to run my test, it throws the follwoing error:
http://pastie.org/2649430
as you can see, entitymanager can't be instantiated...
but on my app, the entitymanager and the @Provider runs perfectly.
what am i missing here?
my entityManager:
public abstract class ECFEntityManager {
private static EntityManagerFactory emf;
private static Map<String, Object> properties = new HashMap<String,
Object>();
private static final ThreadLocal<EntityManager> ENTITY_MANAGER_CACHE =
new ThreadLocal<EntityManager>();
private synchronized static void init() {
properties.put(PersistenceUnitProperties.TARGET_DATABASE,
TargetDatabase.PostgreSQL);
properties.put(PersistenceUnitProperties.JDBC_DRIVER,
Driver.class.getCanonicalName());
properties.put(PersistenceUnitProperties.JDBC_URL,
"jdbc:postgresql://127.0.0.1:5432/ecf");
properties.put(PersistenceUnitProperties.JDBC_USER, "*******");
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, "********");
properties.put(PersistenceUnitProperties.CONNECTION_POOL_MIN, "1");
properties.put(PersistenceUnitProperties.CONNECTION_POOL_MAX, "10");
properties.put(PersistenceUnitProperties.CACHE_STATEMENTS, "true");
properties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
// properties.put(PersistenceUnitProperties.LOGGING_LOGGER,
"br.com.germantech.ecf.infraestrutura.aplicacao.internal.logger.GermantechLog4jLogger");
properties.put(PersistenceUnitProperties.CLASSLOADER,
Bootstrap.class.getClassLoader());
// Cria tabelas novas (mas não atualiza)
properties.put(PersistenceUnitProperties.DDL_GENERATION,
PersistenceUnitProperties.CREATE_ONLY);
// Cria os arquivos de geração do banco de dados
// properties.put(PersistenceUnitProperties.CREATE_JDBC_DDL_FILE,
"createDDL_ddlGeneration.jdbc");
// properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,
PersistenceUnitProperties.DDL_BOTH_GENERATION);
properties.put("eclipselink.logging.level", "FINE");
properties.put("eclipselink.logging.timestamp", "true");
properties.put("eclipselink.logging.session", "true");
properties.put("eclipselink.logging.thread", "true");
properties.put("eclipselink.logging.exceptions", "true");
emf = new PersistenceProvider().createEntityManagerFactory("gtech",
properties);
}
/**
* Retorna um {@link EntityManager}. Caso não exista, cria um novo
*/
public synchronized static EntityManager getEntityManager() {
EntityManager entityManager = ENTITY_MANAGER_CACHE.get();
if (entityManager == null) {
init();
ENTITY_MANAGER_CACHE.set(entityManager = emf.createEntityManager());
}
return entityManager;
}
i'll take a look to guiceberry :P
thanks a lot
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.