Skip to content

Commit cb48c21

Browse files
committed
Merge branch 'master' of github.com:javaee-samples/javaee7-samples
2 parents d0f8466 + 9b2b4fb commit cb48c21

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

jpa/datasourcedefinition/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.javaee7.jpa</groupId>
7+
<artifactId>jpa-samples</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>datasourcedefinition</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.h2database</groupId>
17+
<artifactId>h2</artifactId>
18+
<version>1.3.173</version>
19+
</dependency>
20+
</dependencies>
21+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.javaee7.jpa.datasourcedefinition;
2+
3+
import javax.annotation.sql.DataSourceDefinition;
4+
import javax.ejb.Stateless;
5+
6+
/**
7+
* @author Alexis Hassler
8+
*/
9+
@DataSourceDefinition(name = "java:global/MyApp/MyDataSource",
10+
className = "org.h2.jdbcx.JdbcDataSource",
11+
url = "jdbc:h2:mem:test")
12+
@Stateless
13+
public class DataSourceDefinitionHolder {
14+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian" xsi:schemaLocation="http://jboss.org/schema/arquillian
3+
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
4+
5+
<defaultProtocol type="Servlet 3.0"/>
6+
7+
<container qualifier="test" default="true">
8+
<configuration>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
10+
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
11+
</configuration>
12+
</container>
13+
14+
</arquillian>

jpa/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<module>unsynchronized-pc</module>
3535
<module>extended-pc</module>
3636
<module>jpa-converter</module>
37+
<module>datasourcedefinition</module>
3738
</modules>
3839

3940
</project>

0 commit comments

Comments
 (0)