Hey,
I setup Arquillain testing.
Some tests worked, and I use hibernate to recreate my database tables when the unittests start.
So in the @BeforeClass I want to add some data to my database using the entityManager.
However, I get a nullpointer exception when trying to persist something with the entitymanager.
Here is my TestClass:
@RunWith(Arquillian.class)
public class ProfileServiceTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addPackages(true, "dao", "dto", "entities", "filters", "rest", "security", "services")
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@PersistenceContext(name = "kwetterTestPu")
private static EntityManager entityManager;
private static Profile p1;
private static Profile p2;
private static String name1;
private static String name2;
private static String email1;
private static String email2;
private static String password;
@BeforeClass
public static void setup(){
name1 = "Bart";
name2 = "Jules";
email1 = "Bart@email.com";
email2 = "Jules@email.com";
password = "password";
p1 = new Profile(email1,password, name1);
p2 = new Profile(email2, password, name2);
p1.getFollowing().add(p2);
entityManager.persist(p1);
entityManager.flush();
}
I found this topic on StackOverflow:
https://stackoverflow.com/questions/44905874/arquillian-beforeclass-injected-entitymanager-null
But there is no answer posted.
What am I doing wrong?