So here's my very basic test, all it does is it creates a movie object and puts it into a DB. All that works fine, i can tell by putting a break point after movies.addMovie(movie) and cheking DB. The problem is that when test is finished DB is empty. All tables created during execution are gone. My question is why on earth Arquillian is doing that and how can i turn that behaviour off.
@RunWith(Arquillian.class)
@PersistenceTest
public class MoviesTest {
@Deployment
public static JavaArchive createTestArchive() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
.addClass(Movie.class)
.addClass(Movies.class)
.addAsManifestResource("test-persistence.xml",
ArchivePaths.create("persistence.xml"))
.addAsManifestResource("META-INF/beans.xml",
ArchivePaths.create("beans.xml"))
.addAsResource("ValidationMessages.properties");
System.out.println(archive.toString(true));
return archive;
}
@Inject
private Movies movies;
@Test
@InSequence(1)
public void testAddMovie() throws Exception {
final Movie movie = new Movie("Steven Spielberg", "Jurassic Park", 1993);
movies.addMovie(movie);
}
}
@Stateful
@LocalBean
public class Movies {
@PersistenceContext(unitName = "myPU", type = PersistenceContextType.EXTENDED)
private EntityManager em;
public Movie find(long id) {
return em.find(Movie.class, id);
}
public void addMovie(Movie movie) throws Exception {
em.persist(movie);
}
}
Comments