|
| 1 | +package org.javaee7.jpa.datasourcedefinition; |
| 2 | + |
| 3 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 4 | +import org.jboss.arquillian.junit.Arquillian; |
| 5 | +import org.jboss.shrinkwrap.api.Archive; |
| 6 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 7 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 8 | +import org.jboss.shrinkwrap.resolver.api.maven.Maven; |
| 9 | +import org.junit.Test; |
| 10 | +import org.junit.runner.RunWith; |
| 11 | + |
| 12 | +import javax.annotation.Resource; |
| 13 | +import javax.sql.DataSource; |
| 14 | + |
| 15 | +import java.io.File; |
| 16 | + |
| 17 | +import static org.hamcrest.CoreMatchers.is; |
| 18 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 19 | +import static org.junit.Assert.assertThat; |
| 20 | + |
| 21 | +/** |
| 22 | + * @author Alexis Hassler |
| 23 | + */ |
| 24 | +@RunWith(Arquillian.class) |
| 25 | +public class DataSourceDefinitionTest { |
| 26 | + @Deployment |
| 27 | + public static Archive<?> deploy() { |
| 28 | + File h2Library = Maven.resolver().loadPomFromFile("pom.xml") |
| 29 | + .resolve("com.h2database:h2").withoutTransitivity() |
| 30 | + .asSingleFile(); |
| 31 | + |
| 32 | + return ShrinkWrap.create(WebArchive.class) |
| 33 | + .addClasses(DataSourceDefinitionHolder.class) |
| 34 | + .addAsLibraries(h2Library); |
| 35 | + } |
| 36 | + |
| 37 | + @Resource(lookup = "java:global/MyApp/MyDataSource") DataSource dataSource; |
| 38 | + |
| 39 | + @Test |
| 40 | + public void should_bean_be_injected() throws Exception { |
| 41 | + assertThat(dataSource, is(notNullValue())); |
| 42 | + assertThat(dataSource.getConnection(), is(notNullValue())); |
| 43 | + } |
| 44 | +} |
0 commit comments