Commit cc3c66408bfb115f7c77a60e40c3475b69f4425d
1 parent
d9338bfc
test: eigene persistence.xml für die Tests
Showing
6 changed files
with
60 additions
and
35 deletions
pom.xml
... | ... | @@ -20,13 +20,7 @@ |
20 | 20 | <slf4j-version>1.7.25</slf4j-version> |
21 | 21 | <jackson-version>2.8.8.1</jackson-version> |
22 | 22 | |
23 | - <swxercise.schema>swxercise</swxercise.schema> | |
24 | - <swxercise.host>localhost</swxercise.host> | |
25 | - <swxercise.user>root</swxercise.user> | |
26 | - <swxercise.password>root</swxercise.password> | |
27 | - <swxercise.port>3306</swxercise.port> | |
28 | - | |
29 | - <!-- Legacy compatiblity --> | |
23 | + <!-- Substituiert die Platzhalter in der testenden "persistence.xml" --> | |
30 | 24 | <TEST_SCHEMA_NAME>swxercise_test</TEST_SCHEMA_NAME> |
31 | 25 | <swxercise.test.schema>${TEST_SCHEMA_NAME}</swxercise.test.schema> |
32 | 26 | <swxercise.test.host>localhost</swxercise.test.host> |
... | ... | @@ -51,11 +45,16 @@ |
51 | 45 | <version>${junit-version}</version> |
52 | 46 | <scope>test</scope> |
53 | 47 | </dependency> |
54 | - <dependency> | |
48 | + <!--dependency> | |
55 | 49 | <groupId>org.slf4j</groupId> |
56 | 50 | <artifactId>slf4j-api</artifactId> |
57 | 51 | <version>${slf4j-version}</version> |
58 | - </dependency> | |
52 | + </dependency--> | |
53 | + <dependency> | |
54 | + <groupId>org.slf4j</groupId> | |
55 | + <artifactId>slf4j-log4j12</artifactId> | |
56 | + <version>${slf4j-version}</version> | |
57 | + </dependency> | |
59 | 58 | <dependency> |
60 | 59 | <groupId>org.mockito</groupId> |
61 | 60 | <artifactId>mockito-core</artifactId> |
... | ... | @@ -67,11 +66,11 @@ |
67 | 66 | <artifactId>dbunit</artifactId> |
68 | 67 | <version>${dbunit-version}</version> |
69 | 68 | </dependency> |
70 | - <dependency> | |
71 | - <groupId>org.hibernate</groupId> | |
72 | - <artifactId>hibernate-core</artifactId> | |
73 | - <version>${hibernate-version}</version> | |
74 | - </dependency> | |
69 | + <dependency> | |
70 | + <groupId>org.hibernate</groupId> | |
71 | + <artifactId>hibernate-core</artifactId> | |
72 | + <version>${hibernate-version}</version> | |
73 | + </dependency> | |
75 | 74 | <dependency> |
76 | 75 | <groupId>mysql</groupId> |
77 | 76 | <artifactId>mysql-connector-java</artifactId> |
... | ... | @@ -86,6 +85,14 @@ |
86 | 85 | <build> |
87 | 86 | <finalName>swXercise</finalName> |
88 | 87 | |
88 | + <testResources> | |
89 | + <!-- Sorgt dafür, dass Properties-Filtering von hier in die testende "persistence.xml" funktioniert --> | |
90 | + <testResource> | |
91 | + <directory>src/test/resources</directory> | |
92 | + <filtering>true</filtering> | |
93 | + </testResource> | |
94 | + </testResources> | |
95 | + | |
89 | 96 | <plugins> |
90 | 97 | <plugin> |
91 | 98 | <artifactId>maven-compiler-plugin</artifactId> | ... | ... |
src/main/java/net/ziemers/swxercise/db/utils/JpaTestUtils.java
... | ... | @@ -97,7 +97,8 @@ public class JpaTestUtils { |
97 | 97 | overrideProperties.load(fis); |
98 | 98 | emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_TEST, overrideProperties); |
99 | 99 | } catch (Exception e) { |
100 | - logger.info("Persistence properties will not be overriden because of following error:", e); | |
100 | + // logger.info("Persistence properties will not be overriden because of following error:", e); | |
101 | + logger.info("Persistence properties will not be overriden"); | |
101 | 102 | } finally { |
102 | 103 | if (fis != null) { |
103 | 104 | try { | ... | ... |
src/main/resources/META-INF/persistence.xml
... | ... | @@ -10,24 +10,4 @@ |
10 | 10 | <property name="hibernate.hbm2ddl.auto" value="update" /> |
11 | 11 | </properties> |
12 | 12 | </persistence-unit> |
13 | - | |
14 | - <persistence-unit name="swXerciseTestPU" transaction-type="RESOURCE_LOCAL"> | |
15 | - <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> | |
16 | - <exclude-unlisted-classes>false</exclude-unlisted-classes> | |
17 | - <properties> | |
18 | - <!-- Property for WildFly to ignore this --> | |
19 | - <property name="jboss.as.jpa.managed" value="false" /> | |
20 | - <!-- Properties for Hibernate --> | |
21 | - <property name="javax.persistence.jdbc.url" value="jdbc:mysql://${swxercise.test.host}:${swxercise.test.port}/${swxercise.test.schema}" /> | |
22 | - <property name="javax.persistence.jdbc.user" value="${swxercise.test.user}" /> | |
23 | - <property name="javax.persistence.jdbc.password" value="${swxercise.test.password}" /> | |
24 | - <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> | |
25 | - <property name="hibernate.show_sql" value="false" /> | |
26 | - <property name="hibernate.format_sql" value="false" /> | |
27 | - <!--<property name="hibernate.hbm2ddl.auto" value="create-drop" / --> | |
28 | - <property name="hibernate.connection.useUnicode" value="true" /> | |
29 | - <property name="hibernate.connection.characterEncoding" value="UTF-8" /> | |
30 | - <property name="hibernate.ejb.entitymanager_factory_name" value="swXerciseTestPU" /> | |
31 | - </properties> | |
32 | - </persistence-unit> | |
33 | 13 | </persistence> | ... | ... |
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
1 | 1 | package net.ziemers.swxercise.lg.user.service; |
2 | 2 | |
3 | 3 | import net.ziemers.swxercise.db.utils.JpaTestUtils; |
4 | +import org.junit.Test; | |
4 | 5 | |
5 | 6 | public class UserServiceTest extends JpaTestUtils { |
7 | + | |
8 | + @Test | |
9 | + public void testService() { | |
10 | + txBegin(); | |
11 | + txCommit(); | |
12 | + } | |
13 | + | |
6 | 14 | } | ... | ... |
src/test/resources/META-INF/persistence.xml
0 → 100644
1 | +<persistence version="2.0" | |
2 | + xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> | |
4 | + | |
5 | + <persistence-unit name="swXerciseTestPU" transaction-type="RESOURCE_LOCAL"> | |
6 | + <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> | |
7 | + <exclude-unlisted-classes>false</exclude-unlisted-classes> | |
8 | + <properties> | |
9 | + <!-- Property for WildFly to ignore this --> | |
10 | + <property name="jboss.as.jpa.managed" value="false" /> | |
11 | + <!-- Properties for Hibernate --> | |
12 | + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://${swxercise.test.host}:${swxercise.test.port}/${swxercise.test.schema}?useSSL=false" /> | |
13 | + <property name="javax.persistence.jdbc.user" value="${swxercise.test.user}" /> | |
14 | + <property name="javax.persistence.jdbc.password" value="${swxercise.test.password}" /> | |
15 | + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> | |
16 | + <property name="hibernate.show_sql" value="false" /> | |
17 | + <property name="hibernate.format_sql" value="false" /> | |
18 | + <!--<property name="hibernate.hbm2ddl.auto" value="create-drop" / --> | |
19 | + <property name="hibernate.connection.useUnicode" value="true" /> | |
20 | + <property name="hibernate.connection.characterEncoding" value="UTF-8" /> | |
21 | + <property name="hibernate.ejb.entitymanager_factory_name" value="swXerciseTestPU" /> | |
22 | + </properties> | |
23 | + </persistence-unit> | |
24 | +</persistence> | ... | ... |
src/test/resources/log4j.properties
0 → 100644