TaskgroupRepsitoryTest
All checks were successful
Java CI with Maven / build (push) Successful in 34s
All checks were successful
Java CI with Maven / build (push) Successful in 34s
This commit is contained in:
parent
7199174736
commit
5cf04a6858
@ -4,8 +4,11 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Deactivate Overall System test (temporarly)">
|
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Fix failing test case">
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/test/resources/taskgroupRepositoryTestEntries.sql" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Taskgroup.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Taskgroup.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -54,7 +57,7 @@
|
|||||||
"git-widget-placeholder": "tests",
|
"git-widget-placeholder": "tests",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"last_directory_selection": "D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager",
|
"last_directory_selection": "D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager",
|
||||||
"last_opened_file_path": "D:/Programmierprojekte/Dicewars/client",
|
"last_opened_file_path": "/media/sebastian/Data2/Programmierprojekte/TimeManager/backend/src/main/resources",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
@ -66,22 +69,99 @@
|
|||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"DatabaseDriversLRU": [
|
"DatabaseDriversLRU": [
|
||||||
|
"h2",
|
||||||
"mariadb"
|
"mariadb"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RunManager" selected="JUnit.UserRepositoryTests.test_findByUsername">
|
<component name="RecentsManager">
|
||||||
<configuration name="UserRepositoryTests.test_findByUsername" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
<key name="CreateClassDialog.RecentsKey">
|
||||||
|
<recent name="core.taskgroups" />
|
||||||
|
</key>
|
||||||
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
|
<recent name="$PROJECT_DIR$/src/main/resources" />
|
||||||
|
<recent name="$PROJECT_DIR$/src/test/resources/core/taskgroups" />
|
||||||
|
</key>
|
||||||
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
|
<recent name="$PROJECT_DIR$/src/test/resources" />
|
||||||
|
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
|
||||||
|
</key>
|
||||||
|
</component>
|
||||||
|
<component name="RunManager" selected="JUnit.TaskgroupRepsitoryTest">
|
||||||
|
<configuration name="TaskgroupRepsitoryTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
<module name="demo" />
|
<module name="demo" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
<pattern>
|
<pattern>
|
||||||
<option name="PATTERN" value="core.users.*" />
|
<option name="PATTERN" value="core.taskgroups.*" />
|
||||||
<option name="ENABLED" value="true" />
|
<option name="ENABLED" value="true" />
|
||||||
</pattern>
|
</pattern>
|
||||||
</extension>
|
</extension>
|
||||||
<option name="PACKAGE_NAME" value="core.users" />
|
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
||||||
<option name="MAIN_CLASS_NAME" value="core.users.UserRepositoryTests" />
|
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" />
|
||||||
<option name="METHOD_NAME" value="test_findByUsername" />
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<configuration name="TaskgroupRepsitoryTest.deleteAllByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="demo" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="core.taskgroups.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" />
|
||||||
|
<option name="METHOD_NAME" value="deleteAllByUser" />
|
||||||
|
<option name="TEST_OBJECT" value="method" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<configuration name="TaskgroupRepsitoryTest.existsByTaskgroupNameAndUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="demo" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="core.taskgroups.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" />
|
||||||
|
<option name="METHOD_NAME" value="existsByTaskgroupNameAndUser" />
|
||||||
|
<option name="TEST_OBJECT" value="method" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<configuration name="TaskgroupRepsitoryTest.findAllByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="demo" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="core.taskgroups.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" />
|
||||||
|
<option name="METHOD_NAME" value="findAllByUser" />
|
||||||
|
<option name="TEST_OBJECT" value="method" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<configuration name="TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="demo" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="core.taskgroups.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" />
|
||||||
|
<option name="METHOD_NAME" value="findAllTopTaskgroupsByUser" />
|
||||||
<option name="TEST_OBJECT" value="method" />
|
<option name="TEST_OBJECT" value="method" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
@ -96,7 +176,11 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="JUnit.UserRepositoryTests.test_findByUsername" />
|
<item itemvalue="JUnit.TaskgroupRepsitoryTest" />
|
||||||
|
<item itemvalue="JUnit.TaskgroupRepsitoryTest.deleteAllByUser" />
|
||||||
|
<item itemvalue="JUnit.TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" />
|
||||||
|
<item itemvalue="JUnit.TaskgroupRepsitoryTest.existsByTaskgroupNameAndUser" />
|
||||||
|
<item itemvalue="JUnit.TaskgroupRepsitoryTest.findAllByUser" />
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
@ -129,6 +213,9 @@
|
|||||||
<workItem from="1698557538577" duration="18000" />
|
<workItem from="1698557538577" duration="18000" />
|
||||||
<workItem from="1698557567325" duration="1724000" />
|
<workItem from="1698557567325" duration="1724000" />
|
||||||
<workItem from="1699205483652" duration="3298000" />
|
<workItem from="1699205483652" duration="3298000" />
|
||||||
|
<workItem from="1699380499473" duration="2708000" />
|
||||||
|
<workItem from="1699460935890" duration="5000" />
|
||||||
|
<workItem from="1699466564154" duration="3193000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@ -306,7 +393,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1699207725883</updated>
|
<updated>1699207725883</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="23" />
|
<task id="LOCAL-00023" summary="Fix failing test case">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1699380549911</created>
|
||||||
|
<option name="number" value="00023" />
|
||||||
|
<option name="presentableId" value="LOCAL-00023" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1699380549911</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="24" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@ -336,7 +431,8 @@
|
|||||||
<MESSAGE value="Fix marking finished task as overdue" />
|
<MESSAGE value="Fix marking finished task as overdue" />
|
||||||
<MESSAGE value="Write simple Testcase for ci/cd" />
|
<MESSAGE value="Write simple Testcase for ci/cd" />
|
||||||
<MESSAGE value="Deactivate Overall System test (temporarly)" />
|
<MESSAGE value="Deactivate Overall System test (temporarly)" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Deactivate Overall System test (temporarly)" />
|
<MESSAGE value="Fix failing test case" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Fix failing test case" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
@ -116,4 +116,17 @@ public class Taskgroup {
|
|||||||
}
|
}
|
||||||
return activeAmountTasks;
|
return activeAmountTasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Taskgroup taskgroup = (Taskgroup) o;
|
||||||
|
return taskgroupID == taskgroup.taskgroupID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(taskgroupID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,93 @@
|
|||||||
|
package core.taskgroups;
|
||||||
|
|
||||||
|
import core.entities.User;
|
||||||
|
import core.entities.timemanager.Taskgroup;
|
||||||
|
import core.repositories.timemanager.TaskgroupRepository;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
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.context.jdbc.Sql;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@DataJpaTest
|
||||||
|
public class TaskgroupRepsitoryTest {
|
||||||
|
|
||||||
|
@Autowired private TaskgroupRepository taskgroupRepository;
|
||||||
|
@Autowired private TestEntityManager testEntityManager;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
|
||||||
|
void findAllByUser() {
|
||||||
|
User testUser1 = testEntityManager.find(User.class, 1L);
|
||||||
|
User testUser2 = testEntityManager.find(User.class, 2L);
|
||||||
|
|
||||||
|
List<Taskgroup> result_user2 = taskgroupRepository.findAllByUser(testUser2.getUsername());
|
||||||
|
assertEquals(0, result_user2.size());
|
||||||
|
|
||||||
|
List<Taskgroup> result_user1 = taskgroupRepository.findAllByUser(testUser1.getUsername());
|
||||||
|
assertEquals(8, result_user1.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
|
||||||
|
void existsByTaskgroupNameAndUser() {
|
||||||
|
User testUser1 = testEntityManager.find(User.class, 1L);
|
||||||
|
User testUser2 = testEntityManager.find(User.class, 2L);
|
||||||
|
|
||||||
|
//Situation 1: Taskgroup exists but within another user
|
||||||
|
assertFalse(taskgroupRepository.existsByTaskgroupNameAndUser("No children", testUser2));
|
||||||
|
|
||||||
|
//Situation 2: Taskgroup exists not
|
||||||
|
assertFalse(taskgroupRepository.existsByTaskgroupNameAndUser("ada", testUser1));
|
||||||
|
|
||||||
|
//Situation 3: Taskgroup (top) exists on user
|
||||||
|
assertTrue(taskgroupRepository.existsByTaskgroupNameAndUser("No children", testUser1));
|
||||||
|
|
||||||
|
//Situation 4: Taskgroup exists on user but not on top level
|
||||||
|
assertTrue(taskgroupRepository.existsByTaskgroupNameAndUser("Taskgroup 1.1", testUser1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
|
||||||
|
void findAllTopTaskgroupsByUser() {
|
||||||
|
User testUser1 = testEntityManager.find(User.class, 1L);
|
||||||
|
User testUser2 = testEntityManager.find(User.class, 2L);
|
||||||
|
|
||||||
|
//Situation 1: Empty user, no taskgroups
|
||||||
|
assertEquals(0, taskgroupRepository.findAllTopTaskgroupsByUser(testUser2.getUsername()).size());
|
||||||
|
|
||||||
|
//Situation 2: Only top taskgroups are returned
|
||||||
|
List<Taskgroup> topgroups_user1 = taskgroupRepository.findAllTopTaskgroupsByUser(testUser1.getUsername());
|
||||||
|
assertEquals(3, topgroups_user1.size());
|
||||||
|
assertTrue(topgroups_user1.contains(testEntityManager.find(Taskgroup.class, 1L)));
|
||||||
|
assertTrue(topgroups_user1.contains(testEntityManager.find(Taskgroup.class, 2L)));
|
||||||
|
assertTrue(topgroups_user1.contains(testEntityManager.find(Taskgroup.class, 5L)));
|
||||||
|
|
||||||
|
//Situation 3: User with username does not exist
|
||||||
|
assertEquals(0, taskgroupRepository.findAllTopTaskgroupsByUser("Rotzbakke").size());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
|
||||||
|
void deleteAllByUser() {
|
||||||
|
User testUser1 = testEntityManager.find(User.class, 1L);
|
||||||
|
User testUser2 = testEntityManager.find(User.class, 2L);
|
||||||
|
|
||||||
|
taskgroupRepository.deleteAllByUser(testUser2);
|
||||||
|
for(long i=1; i<=8; i++) {
|
||||||
|
assertThat(testEntityManager.find(Taskgroup.class, i)).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
taskgroupRepository.deleteAllByUser(testUser1);
|
||||||
|
for(long i=1; i<=8; i++) {
|
||||||
|
assertThat(testEntityManager.find(Taskgroup.class, i)).isNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
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');
|
||||||
|
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (1, 'No children', null, 1);
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (2, 'Taskgroup 1', null, 1);
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (3, 'Taskgroup 1.1', 2, 1);
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (4, 'Taskgroup 1.2', 2, 1);
|
||||||
|
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (5, 'Taskgroup 2', null, 1);
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (6, 'Taskgroup 2.1', 5, 1);
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (7, 'Taskgroup 2.2', 5, 1);
|
||||||
|
INSERT INTO taskgroups (taskgroupid, name, parent_id, taskgroupuser) VALUES (8, 'Taskgroup 2.1.2', 6, 1);
|
Loading…
Reference in New Issue
Block a user