diff --git a/backend/.idea/workspace.xml b/backend/.idea/workspace.xml
index 0590447..0d3facc 100644
--- a/backend/.idea/workspace.xml
+++ b/backend/.idea/workspace.xml
@@ -4,11 +4,10 @@
-
-
+
+
-
-
+
@@ -87,81 +86,82 @@
-
-
+
+
-
+
-
-
-
+
+
+
-
+
-
+
-
-
-
+
+
+
-
+
-
+
-
-
-
+
+
+
-
+
-
+
-
-
-
+
+
+
+
-
+
-
+
-
-
-
+
+
+
@@ -176,11 +176,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -217,7 +217,7 @@
-
+
@@ -435,14 +435,21 @@
1699641346158
-
+
+
+ 1699645467388
+
+
+
+ 1699645467388
+
+
-
@@ -467,7 +474,8 @@
-
+
+
@@ -497,11 +505,6 @@
57
-
- file://$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupServiceTest.java
- 50
-
-
diff --git a/backend/src/test/java/core/users/UserRepositoryTests.java b/backend/src/test/java/core/users/UserRepositoryTests.java
index 65ce191..0b19155 100644
--- a/backend/src/test/java/core/users/UserRepositoryTests.java
+++ b/backend/src/test/java/core/users/UserRepositoryTests.java
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.Optional;
@@ -16,7 +17,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@DataJpaTest
-@DirtiesContext
@ExtendWith(SpringExtension.class)
public class UserRepositoryTests {
@@ -27,76 +27,61 @@ public class UserRepositoryTests {
private TestEntityManager testEntityManager;
@Test
+ @Sql("classpath:userRepisotoryTestEntries.sql")
void test_findByUsername() {
- //Situation 1: No user is present in the database, so no user should be found by a given username
- assertTrue(userRepository.findByUsername("FawKes100").isEmpty());
-
- //persist a user to the database, so a user is present
- testEntityManager.persist(new User("FawKes100", "mail@fawkes100.de", "123456"));
-
- //Situation 2: User with name "FawKes100" is present
- Optional findResult = userRepository.findByUsername("FawKes100");
+ //Situation 1: User with name "FawKes100" is present
+ User referenceUser = testEntityManager.find(User.class, 1L);
+ Optional findResult = userRepository.findByUsername(referenceUser.getUsername());
assertTrue(findResult.isPresent());
- assertEquals(new User("FawKes100", "mail@fawkes100.de", "123456"),findResult.get());
+ assertEquals(referenceUser,findResult.get());
- //Situation 3: No user with the required name is present
+ //Situation 2: No user with the required name is present
findResult = userRepository.findByUsername("fawkes1001");
assertFalse(findResult.isPresent());
}
@Test
+ @Sql("classpath:userRepisotoryTestEntries.sql")
void test_existsByMail() {
+ User referenceUser = testEntityManager.find(User.class, 1L);
//Situation 1: invalid email format should not matter
assertFalse(userRepository.existsByEmail("FawKes100"));
//Situation 2: No user exists with such a mail
assertFalse(userRepository.existsByEmail("mail@fawkes100.de"));
- //persist a user to the database, so a user is present
- testEntityManager.persist(new User("FawKes100", "mail@fawkes100.de", "123456"));
-
//Situation 3: User with this mail exists
- assertTrue(userRepository.existsByEmail("mail@fawkes100.de"));
-
- //Situation 4: No user exists with such a mail (non-empty db)
- assertFalse(userRepository.existsByEmail("mail2@fawkes100.de"));
+ assertTrue(userRepository.existsByEmail(referenceUser.getEmail()));
}
@Test
+ @Sql("classpath:userRepisotoryTestEntries.sql")
void test_existsByUsername() {
- //Situation 1: Empty database
+ User referenceUser = testEntityManager.find(User.class, 1L);
+ //Situation 1: No such user
assertFalse(userRepository.existsByUsername("FawKes100"));
- //persist a user to the database, so a user is present
- testEntityManager.persist(new User("FawKes100", "mail@fawkes100.de", "123456"));
-
//Situation 3: User with this name exists
- assertTrue(userRepository.existsByUsername("FawKes100"));
-
- //Situation 4: No user exists with such a mail (non-empty db)
- assertFalse(userRepository.existsByUsername("FawKes101"));
+ assertTrue(userRepository.existsByUsername(referenceUser.getUsername()));
}
@Test
+ @Sql("classpath:userRepisotoryTestEntries.sql")
void test_deleteUserByName() {
- //persist a user to the database, so a user is present
- User user = testEntityManager.persist(new User("FawKes100", "mail@fawkes100.de", "123456"));
- User user1 = testEntityManager.persist(new User("FawKes101", "mail@fawkes101.de", "123456"));
+ User referenceUser1 = testEntityManager.find(User.class, 1L);
+ User referenceUser2 = testEntityManager.find(User.class, 2L);
- userRepository.deleteByUsername("FawKes100");
+ userRepository.deleteByUsername(referenceUser2.getUsername());
- assertThat(testEntityManager.find(User.class, user.getId())).isNull();
- assertThat(testEntityManager.find(User.class, user1.getId())).isNotNull();
+ assertThat(testEntityManager.find(User.class, referenceUser2.getId())).isNull();
+ assertThat(testEntityManager.find(User.class, referenceUser1.getId())).isNotNull();
}
@Test
+ @Sql("classpath:userRepisotoryTestEntries.sql")
void test_countUsers() {
- assertEquals(0, userRepository.countUsers());
-
- testEntityManager.persist(new User("FawKes100", "mail@fawkes100.de", "123456"));
- assertEquals(1, userRepository.countUsers());
-
+ assertEquals(2, userRepository.countUsers());
}
}
diff --git a/backend/src/test/resources/userRepisotoryTestEntries.sql b/backend/src/test/resources/userRepisotoryTestEntries.sql
new file mode 100644
index 0000000..0caba64
--- /dev/null
+++ b/backend/src/test/resources/userRepisotoryTestEntries.sql
@@ -0,0 +1,2 @@
+INSERT INTO users (id, username, email, password) VALUES (1, 'Testuser1', 'test1@test.com', '123456');
+INSERT INTO users (id, username, email, password) VALUES (2, 'Testuser2', 'test2@test.com', '123456');
\ No newline at end of file