Integrated integration test provided by Claus Graf (clausgraf@gmail.com)
authorKai Moritz <km@juplo.de>
Sat, 25 Oct 2014 14:52:34 +0000 (16:52 +0200)
committerKai Moritz <km@juplo.de>
Sun, 26 Oct 2014 10:21:26 +0000 (11:21 +0100)
pom.xml
src/it/dependency-test/dependent/pom.xml [new file with mode: 0644]
src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java [new file with mode: 0644]
src/it/dependency-test/h4mp/pom.xml [new file with mode: 0644]
src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java [new file with mode: 0644]
src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml [new file with mode: 0644]
src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java [new file with mode: 0644]
src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml [new file with mode: 0644]
src/it/dependency-test/pom.xml [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index df20ab0..6433f6f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <name>Mark Robinson</name>
       <email>mark@mrobinson.ca</email>
     </contributor>
+    <contributor>
+      <name>Claus Graf</name>
+      <email>clausgraf@gmail.com</email>
+    </contributor>
   </contributors>
 
   <distributionManagement>
diff --git a/src/it/dependency-test/dependent/pom.xml b/src/it/dependency-test/dependent/pom.xml
new file mode 100644 (file)
index 0000000..e7c15f3
--- /dev/null
@@ -0,0 +1,26 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>de.cege</groupId>
+       <artifactId>dependent</artifactId>
+       <version>0.0.1</version>
+
+       <dependencies>
+               <dependency>
+                       <groupId>javax</groupId>
+                       <artifactId>javaee-api</artifactId>
+                       <version>7.0</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-envers</artifactId>
+                       <version>4.3.5.Final</version>
+               </dependency>
+       </dependencies>
+       <properties>
+               <maven.compiler.source>1.7</maven.compiler.source>
+               <maven.compiler.target>1.7</maven.compiler.target>
+               <failOnMissingWebXml>false</failOnMissingWebXml>
+       </properties>
+</project>
\ No newline at end of file
diff --git a/src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java b/src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java
new file mode 100644 (file)
index 0000000..16bc404
--- /dev/null
@@ -0,0 +1,17 @@
+package dependent;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.Audited;
+
+@Entity
+@Audited
+public class DependentEntity {
+       @Id
+       @GeneratedValue
+       long id;
+
+       String name;
+}
diff --git a/src/it/dependency-test/h4mp/pom.xml b/src/it/dependency-test/h4mp/pom.xml
new file mode 100644 (file)
index 0000000..4e179d2
--- /dev/null
@@ -0,0 +1,85 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>de.cege</groupId>
+       <artifactId>h4mp</artifactId>
+       <version>0.0.1-SNAPSHOT</version>
+       <packaging>war</packaging>
+       <name>h4mp</name>
+
+       <dependencies>
+               <dependency>
+                       <groupId>javax</groupId>
+                       <artifactId>javaee-api</artifactId>
+                       <version>7.0</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-envers</artifactId>
+                       <version>4.3.5.Final</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.8.2</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.derby</groupId>
+                       <artifactId>derby</artifactId>
+                       <version>10.10.1.1</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-entitymanager</artifactId>
+                       <version>4.3.5.Final</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-simple</artifactId>
+                       <version>1.5.8</version>
+                       <scope>test</scope>
+               </dependency>
+
+               <dependency>
+                       <groupId>de.cege</groupId>
+                       <artifactId>dependent</artifactId>
+                       <version>0.0.1</version>
+               </dependency>
+       </dependencies>
+       <properties>
+               <maven.compiler.source>1.7</maven.compiler.source>
+               <maven.compiler.target>1.7</maven.compiler.target>
+               <failOnMissingWebXml>false</failOnMissingWebXml>
+       </properties>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>de.juplo</groupId>
+                               <artifactId>hibernate4-maven-plugin</artifactId>
+                               <version>@project.version@</version>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>export</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                               <configuration>
+                                       <target>NONE</target>
+                                       <envers>true</envers>
+                                       <format>true</format>
+                                       <delimiter>;</delimiter>
+                                       <force>true</force>
+                                       <type>CREATE</type>
+                                       <hibernateDialect>org.hibernate.dialect.PostgreSQL9Dialect</hibernateDialect>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
diff --git a/src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java b/src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java
new file mode 100644 (file)
index 0000000..f717d17
--- /dev/null
@@ -0,0 +1,21 @@
+package h4mp;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.envers.Audited;
+
+import dependent.DependentEntity;
+
+@Entity
+@Audited
+public class MainEntity {
+       @Id
+       @GeneratedValue
+       long id;
+
+       @ManyToOne
+       DependentEntity dependentEntity;
+}
diff --git a/src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml b/src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml
new file mode 100644 (file)
index 0000000..a419eda
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="2.0"
+       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_2_0.xsd">
+       <persistence-unit name="primary">
+               <jta-data-source>java:jboss/datasources/PostgreSQLDS</jta-data-source>
+
+               <class>dependent.DependentEntity</class>
+
+               <properties>
+                       <property name="hibernate.hbm2ddl.auto" value="create-drop" />
+                       <property name="hibernate.show_sql" value="true" />
+               </properties>
+       </persistence-unit>
+</persistence>
diff --git a/src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java b/src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java
new file mode 100644 (file)
index 0000000..32e528f
--- /dev/null
@@ -0,0 +1,49 @@
+package h4mp;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.core.Is.*;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import dependent.DependentEntity;
+
+public class MainEntityTest {
+
+       private EntityManager em;
+       private EntityTransaction transaction;
+
+       @Before
+       public void initializeDependencies() {
+               em = Persistence.createEntityManagerFactory("jpaIntegrationTest")
+                               .createEntityManager();
+               transaction = em.getTransaction();
+       }
+
+       @SuppressWarnings({ "rawtypes" })
+       @Test
+       public void test() {
+               DependentEntity entity = new DependentEntity();
+
+               transaction.begin();
+               em.persist(entity);
+               transaction.commit();
+
+               List resultList = em.createNativeQuery(
+                               "select * from dependententity_aud").getResultList();
+               assertThat(resultList.size(), is(1));
+       }
+
+       @After
+       public void after() {
+               em.close();
+       }
+
+}
diff --git a/src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml b/src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml
new file mode 100644 (file)
index 0000000..83e13de
--- /dev/null
@@ -0,0 +1,23 @@
+<persistence version="2.0"
+       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_2_0.xsd">
+
+       <persistence-unit name="jpaIntegrationTest"
+               transaction-type="RESOURCE_LOCAL">
+
+               <class>dependent.DependentEntity</class>
+               <class>h4mp.MainEntity</class>
+               <!-- <exclude-unlisted-classes>true</exclude-unlisted-classes> -->
+
+               <properties>
+                       <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:testDB;create=true" />
+                       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
+                       <!-- Properties for Hibernate -->
+                       <property name="hibernate.hbm2ddl.auto" value="create-drop" />
+                       <property name="hibernate.show_sql" value="false" />
+               </properties>
+       </persistence-unit>
+</persistence>
+
diff --git a/src/it/dependency-test/pom.xml b/src/it/dependency-test/pom.xml
new file mode 100644 (file)
index 0000000..8e1506e
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>de.juplo</groupId>
+  <artifactId>dependency-test</artifactId>
+  <name>Hibernate 4 Dependency-Test</name>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <modules>
+    <module>dependent</module>
+    <module>h4mp</module>
+  </modules>
+</project>