Added test, that configure the JPA-mapping with XML-configuration-files
authorKai Moritz <kai@juplo.de>
Wed, 16 Aug 2017 08:37:49 +0000 (10:37 +0200)
committerKai Moritz <kai@juplo.de>
Wed, 16 Aug 2017 11:36:33 +0000 (13:36 +0200)
src/test/java/de/juplo/jpa/converters/JPAConverterTest.java
src/test/resources/META-INF/mapping.xml [new file with mode: 0644]
src/test/resources/META-INF/persistence.xml

index 79e4405..c9f87cf 100644 (file)
@@ -43,6 +43,13 @@ public class JPAConverterTest
     testOffsetDateTime();
   }
 
+  @Test
+  public void testOffsetDateTimeXml()
+  {
+    em = Persistence.createEntityManagerFactory("xml").createEntityManager();
+    testOffsetDateTime();
+  }
+
   public void testOffsetDateTime()
   {
     EierlegendeWollmilchSau ews;
@@ -63,6 +70,7 @@ public class JPAConverterTest
     assertEquals(odt.toInstant(), ews.odt.toInstant());
   }
 
+
   @Test
   public void testZonedDateTimeAnnotated()
   {
@@ -70,6 +78,13 @@ public class JPAConverterTest
     testZonedDateTime();
   }
 
+  @Test
+  public void testZonedDateTimeXml()
+  {
+    em = Persistence.createEntityManagerFactory("xml").createEntityManager();
+    testZonedDateTime();
+  }
+
   public void testZonedDateTime()
   {
     EierlegendeWollmilchSau ews;
diff --git a/src/test/resources/META-INF/mapping.xml b/src/test/resources/META-INF/mapping.xml
new file mode 100644 (file)
index 0000000..6b49b11
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings
+    xmlns="http://java.sun.com/xml/ns/persistence/orm"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
+    version="2.1">
+
+  <converter class="de.juplo.jpa.converters.ZonedDateTimeConverter" auto-apply="true"/>
+  <converter class="de.juplo.jpa.converters.OffsetDateTimeConverter" auto-apply="true"/>
+
+  <entity class="de.juplo.jpa.converters.EierlegendeWollmilchSau" access="PROPERTY">
+    <attributes>
+      <id name="id">
+        <generated-value/>
+      </id>
+    </attributes>
+  </entity>
+
+</entity-mappings>
index f6fffeb..603cd73 100644 (file)
     </properties>
   </persistence-unit>
 
+  <persistence-unit name="xml">
+    <description>Classes are mapped with XML-configuration-files</description>
+    <mapping-file>META-INF/mapping.xml</mapping-file>
+    <exclude-unlisted-classes>true</exclude-unlisted-classes>
+    <properties>
+      <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+      <property name="javax.persistence.jdbc.user" value="sa"/>
+      <property name="javax.persistence.jdbc.password" value=""/>
+      <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:"/>
+      <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+      <property name="hibernate.hbm2ddl.auto" value="create"/>
+      <property name="hibernate.show_sql" value="true"/>
+    </properties>
+  </persistence-unit>
+
 </persistence>