Last active
August 29, 2015 14:16
-
-
Save aslakknutsen/cdde48b1c735a01ae307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.aslak.arquillian.test; | |
import javax.enterprise.inject.Produces; | |
import javax.persistence.EntityManager; | |
import javax.persistence.PersistenceContext; | |
public class EMProducer { | |
@PersistenceContext | |
private EntityManager em; | |
@Produces | |
public EntityManager get() { | |
return em; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.aslak.arquillian.test; | |
import javax.persistence.Entity; | |
import javax.persistence.Id; | |
import javax.persistence.SequenceGenerator; | |
@Entity | |
public class Foo { | |
@Id @SequenceGenerator(name = "foo_sq") | |
private long id; | |
private String name; | |
public Foo() { | |
} | |
public long getId() { | |
return id; | |
} | |
public void setId(long id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.aslak.arquillian.test; | |
import javax.ejb.Stateful; | |
import javax.enterprise.context.SessionScoped; | |
import javax.inject.Inject; | |
import javax.inject.Named; | |
import javax.persistence.EntityManager; | |
@Named @SessionScoped @Stateful | |
public class FooBean { | |
@Inject | |
private EntityManager em; | |
private Foo foo; | |
public void setFoo(Foo foo) { | |
this.foo = foo; | |
} | |
public void saveFoo() { | |
em.merge(foo); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.aslak.arquillian.test; | |
import javax.inject.Inject; | |
import org.jboss.arquillian.container.test.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.WebArchive; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
@RunWith(Arquillian.class) | |
public class FooBeanTest { | |
@Deployment | |
public static Archive<?> deploy() { | |
WebArchive archive = ShrinkWrap.create(WebArchive.class) | |
.addClasses(Foo.class, FooBean.class, EMProducer.class) | |
.addAsResource("test-persistence.xml", "META-INF/persistence.xml") | |
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | |
return archive; | |
} | |
@Inject | |
private FooBean bean; | |
@Test | |
public void shouldSave() throws Exception { | |
Foo foo = new Foo(); | |
foo.setName("Test"); | |
bean.setFoo(foo); | |
bean.saveFoo(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" | |
version="1.0"> | |
<persistence-unit name="conference"> | |
<provider>org.hibernate.ejb.HibernatePersistence</provider> | |
<jta-data-source>java:/jboss/datasources/ExampleDS</jta-data-source> | |
<exclude-unlisted-classes>false</exclude-unlisted-classes> | |
<properties> | |
<property name="hibernate.hbm2ddl.auto" value="create-drop" /> | |
<property name="hibernate.show_sql" value="true" /> | |
</properties> | |
</persistence-unit> | |
</persistence> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment