Commit 096b67cc4450187d7d46dcee937e7d6dedfa5024
1 parent
cc3c6640
test: Testumgebung fertiggestellt
Showing
5 changed files
with
36 additions
and
34 deletions
pom.xml
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | <version>0.0.1-SNAPSHOT</version> |
8 | 8 | <name>swXercise Maven Webapp</name> |
9 | 9 | <url>http://maven.apache.org</url> |
10 | + | |
10 | 11 | <properties> |
11 | 12 | <mvn-compiler-plugin-version>3.3</mvn-compiler-plugin-version> |
12 | 13 | <jee-version>7.0</jee-version> |
... | ... | @@ -20,7 +21,7 @@ |
20 | 21 | <slf4j-version>1.7.25</slf4j-version> |
21 | 22 | <jackson-version>2.8.8.1</jackson-version> |
22 | 23 | |
23 | - <!-- Substituiert die Platzhalter in der testenden "persistence.xml" --> | |
24 | + <!-- Substituiert die Platzhalter in der "persistence.xml" --> | |
24 | 25 | <TEST_SCHEMA_NAME>swxercise_test</TEST_SCHEMA_NAME> |
25 | 26 | <swxercise.test.schema>${TEST_SCHEMA_NAME}</swxercise.test.schema> |
26 | 27 | <swxercise.test.host>localhost</swxercise.test.host> |
... | ... | @@ -28,6 +29,7 @@ |
28 | 29 | <swxercise.test.password>root</swxercise.test.password> |
29 | 30 | <swxercise.test.port>3306</swxercise.test.port> |
30 | 31 | </properties> |
32 | + | |
31 | 33 | <dependencies> |
32 | 34 | <dependency> |
33 | 35 | <groupId>javax</groupId> |
... | ... | @@ -65,6 +67,8 @@ |
65 | 67 | <groupId>org.dbunit</groupId> |
66 | 68 | <artifactId>dbunit</artifactId> |
67 | 69 | <version>${dbunit-version}</version> |
70 | + <!--scope>test</scope--> | |
71 | + <!-- TODO Wie koennen wir es erreichen, dass dies nur noch im Testkontext abhängig ist? --> | |
68 | 72 | </dependency> |
69 | 73 | <dependency> |
70 | 74 | <groupId>org.hibernate</groupId> |
... | ... | @@ -85,13 +89,13 @@ |
85 | 89 | <build> |
86 | 90 | <finalName>swXercise</finalName> |
87 | 91 | |
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> | |
92 | + <resources> | |
93 | + <!-- Sorgt dafür, dass Properties-Filtering von hier in die "persistence.xml" funktioniert --> | |
94 | + <resource> | |
95 | + <directory>src/main/resources</directory> | |
96 | + <filtering>true</filtering> | |
97 | + </resource> | |
98 | + </resources> | |
95 | 99 | |
96 | 100 | <plugins> |
97 | 101 | <plugin> | ... | ... |
src/main/resources/META-INF/persistence.xml
... | ... | @@ -5,9 +5,29 @@ |
5 | 5 | <persistence-unit name="swXercisePU" transaction-type="JTA"> |
6 | 6 | <jta-data-source>java:jboss/datasources/swXerciseDS</jta-data-source> |
7 | 7 | <properties> |
8 | - <property name="wildfly.jpa.default-unit" value="true"/> | |
8 | + <property name="wildfly.jpa.default-unit" value="true"/> | |
9 | 9 | <!-- property name="hibernate.hbm2ddl.auto" value="create-drop" / --> |
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}?useSSL=false" /> | |
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> | |
13 | 33 | </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 net.ziemers.swxercise.lg.model.user.User; | |
4 | 5 | import org.junit.Test; |
5 | 6 | |
6 | 7 | public class UserServiceTest extends JpaTestUtils { |
... | ... | @@ -8,6 +9,7 @@ public class UserServiceTest extends JpaTestUtils { |
8 | 9 | @Test |
9 | 10 | public void testService() { |
10 | 11 | txBegin(); |
12 | + getEm().persist(new User("Hein", "Blöd")); | |
11 | 13 | txCommit(); |
12 | 14 | } |
13 | 15 | ... | ... |
src/test/java/net/ziemers/swxercise/ui/UserViewControllerTest.java
... | ... | @@ -115,7 +115,7 @@ public class UserViewControllerTest { |
115 | 115 | // wir simulieren den Erfolg des userService (der hier nicht getestet werden soll), |
116 | 116 | // sofern das korrekte userDto an ihn übergeben wurde |
117 | 117 | when(userService.loginUser(userDto)).thenReturn(true); |
118 | - when(userService.getSessionUser()).thenReturn(user); | |
118 | + //when(userService.getSessionUser()).thenReturn(user); | |
119 | 119 | |
120 | 120 | actual = underTest.loginUser(userDto); |
121 | 121 | } | ... | ... |
src/test/resources/META-INF/persistence.xml deleted
100644 → 0
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> |