package com.nowbesure.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.nowbesure.domain.Product;
import com.nowbesure.service.jpa.EntityManagerProvider;
@RunWith(Arquillian.class)
public class BeanManagerTest {
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(JavaArchive.class).addClass(HelloWorld.class)
.addClass(EntityManagerProvider.class)
.addManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Inject
BeanManager beanManager;
@Inject
HelloWorld helloWorld;
@Inject
EntityManager em;
@Test
public void testCdiBootstrap() {
assertNotNull(beanManager);
assertFalse(beanManager.getBeans(BeanManager.class).isEmpty());
assertEquals("Hello, World!", helloWorld.getText());
em.getTransaction().begin();
Product p = em.find(Product.class, 1L);
assertNotNull(p);
em.getTransaction().commit();
}
}