FindAlltasksByUser Test
All checks were successful
Java CI with Maven / build (push) Successful in 34s

This commit is contained in:
Sebastian Böckelmann 2023-11-08 21:22:28 +01:00
parent 8f5e8133f8
commit 4d655c32ed
3 changed files with 148 additions and 51 deletions

View File

@ -4,8 +4,10 @@
<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="TaskgroupRepsitoryTest"> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="TaskgroupRepsitoryTest (+Delete)">
<change beforePath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/resources/taskRepositoryEntries.sql" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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" />
@ -41,36 +43,36 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RequestMappingsPanelOrder0": "0", &quot;RequestMappingsPanelOrder0&quot;: &quot;0&quot;,
"RequestMappingsPanelOrder1": "1", &quot;RequestMappingsPanelOrder1&quot;: &quot;1&quot;,
"RequestMappingsPanelWidth0": "75", &quot;RequestMappingsPanelWidth0&quot;: &quot;75&quot;,
"RequestMappingsPanelWidth1": "75", &quot;RequestMappingsPanelWidth1&quot;: &quot;75&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"WebServerToolWindowFactoryState": "false", &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
"extract.method.default.visibility": "private", &quot;extract.method.default.visibility&quot;: &quot;private&quot;,
"git-widget-placeholder": "tests", &quot;git-widget-placeholder&quot;: &quot;tests&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"last_directory_selection": "D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager", &quot;last_directory_selection&quot;: &quot;D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager&quot;,
"last_opened_file_path": "/media/sebastian/Data2/Programmierprojekte/TimeManager/backend/src/main/resources", &quot;last_opened_file_path&quot;: &quot;/media/sebastian/Data2/Programmierprojekte/Storycreator&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"settings.editor.selected.configurable": "swagger", &quot;settings.editor.selected.configurable&quot;: &quot;swagger&quot;,
"ts.external.directory.path": "/snap/intellij-idea-ultimate/459/plugins/javascript-impl/jsLanguageServicesImpl/external", &quot;ts.external.directory.path&quot;: &quot;/snap/intellij-idea-ultimate/459/plugins/javascript-impl/jsLanguageServicesImpl/external&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}, },
"keyToStringList": { &quot;keyToStringList&quot;: {
"DatabaseDriversLRU": [ &quot;DatabaseDriversLRU&quot;: [
"h2", &quot;h2&quot;,
"mariadb" &quot;mariadb&quot;
] ]
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CreateClassDialog.RecentsKey"> <key name="CreateClassDialog.RecentsKey">
<recent name="core.taskgroups" /> <recent name="core.taskgroups" />
@ -84,7 +86,23 @@
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" /> <recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
</key> </key>
</component> </component>
<component name="RunManager" selected="JUnit.TaskgroupRepsitoryTest.delete"> <component name="RunManager" selected="JUnit.TaskRepositoryTest.findAllByUser">
<configuration name="TaskRepositoryTest.findAllByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<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" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="TaskgroupRepsitoryTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" /> <module name="demo" />
<extension name="coverage"> <extension name="coverage">
@ -132,22 +150,6 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </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.findAllTopTaskgroupsByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" /> <module name="demo" />
<extension name="coverage"> <extension name="coverage">
@ -173,11 +175,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.TaskRepositoryTest.findAllByUser" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.delete" /> <item itemvalue="JUnit.TaskgroupRepsitoryTest.delete" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest" /> <item itemvalue="JUnit.TaskgroupRepsitoryTest" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.deleteAllByUser" /> <item itemvalue="JUnit.TaskgroupRepsitoryTest.deleteAllByUser" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" /> <item itemvalue="JUnit.TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.existsByTaskgroupNameAndUser" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -212,7 +214,8 @@
<workItem from="1699205483652" duration="3298000" /> <workItem from="1699205483652" duration="3298000" />
<workItem from="1699380499473" duration="2708000" /> <workItem from="1699380499473" duration="2708000" />
<workItem from="1699460935890" duration="5000" /> <workItem from="1699460935890" duration="5000" />
<workItem from="1699466564154" duration="4487000" /> <workItem from="1699466564154" duration="6646000" />
<workItem from="1699473376129" duration="1378000" />
</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" />
@ -406,14 +409,21 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1699470020407</updated> <updated>1699470020407</updated>
</task> </task>
<option name="localTasksCounter" value="25" /> <task id="LOCAL-00025" summary="TaskgroupRepsitoryTest (+Delete)">
<option name="closed" value="true" />
<created>1699471078386</created>
<option name="number" value="00025" />
<option name="presentableId" value="LOCAL-00025" />
<option name="project" value="LOCAL" />
<updated>1699471078386</updated>
</task>
<option name="localTasksCounter" value="26" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="Structure Taskgroups in Hierarchies" />
<MESSAGE value="Update gitignore for idea folder" /> <MESSAGE value="Update gitignore for idea folder" />
<MESSAGE value="Datastructure for Tasks" /> <MESSAGE value="Datastructure for Tasks" />
<MESSAGE value="Implementing edit route for tasks" /> <MESSAGE value="Implementing edit route for tasks" />
@ -438,7 +448,8 @@
<MESSAGE value="Deactivate Overall System test (temporarly)" /> <MESSAGE value="Deactivate Overall System test (temporarly)" />
<MESSAGE value="Fix failing test case" /> <MESSAGE value="Fix failing test case" />
<MESSAGE value="TaskgroupRepsitoryTest" /> <MESSAGE value="TaskgroupRepsitoryTest" />
<option name="LAST_COMMIT_MESSAGE" value="TaskgroupRepsitoryTest" /> <MESSAGE value="TaskgroupRepsitoryTest (+Delete)" />
<option name="LAST_COMMIT_MESSAGE" value="TaskgroupRepsitoryTest (+Delete)" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View File

@ -0,0 +1,68 @@
package core.tasks;
import core.entities.User;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
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.jdbc.SqlGroup;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(SpringExtension.class)
@DataJpaTest
public class TaskRepositoryTest {
@Autowired private TaskRepository taskRepository;
@Autowired private TestEntityManager testEntityManager;
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void findAllByUser() {
User testUser1 = testEntityManager.find(User.class, 1L);
User testUser2 = testEntityManager.find(User.class, 2L);
//Situation 1: Non existent user
assertEquals(0, taskRepository.findAllByUser("Rotzbakke", true).size());
assertEquals(0, taskRepository.findAllByUser("Rotzbakke", false).size());
//Situation 2: User with no tasks at all
assertEquals(0, taskRepository.findAllByUser(testUser2.getUsername(), false).size());
assertEquals(0, taskRepository.findAllByUser(testUser2.getUsername(), true).size());
//Situation 3: User with finished and unfinished tasks
List<Task> tasks_user1_false = taskRepository.findAllByUser(testUser1.getUsername(), false);
List<Task> tasks_user1_true = taskRepository.findAllByUser(testUser1.getUsername(), true);
assertEquals(7, tasks_user1_true.size());
assertEquals(7, tasks_user1_false.size());
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 1L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 3L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 5L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 7L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 9L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 11L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 12L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 2L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 4L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 6L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 8L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 10L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 13L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 14L)));
}
}

View File

@ -0,0 +1,18 @@
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (1, NULL, 0, NULL, 'Task 1', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (2, NULL, 0, NULL, 'Task 2', 2, true, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (3, '2022-03-20', 0, NULL, 'Task 3', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (4, '2022-03-20', 0, NULL, 'Task 4', 2, true, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (5, '2022-03-20', 0, '2021-03-20', 'Task 5', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (6, '2022-03-20', 0, '2021-03-20', 'Task 6', 2, true, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (7, NULL, 0, '2043-03-20', 'Task 6', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (8, NULL, 0, '2043-03-20', 'Task 6', 2, true, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (9, '2044-03-20', 0, '2043-03-20', 'Task 6', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (10, '2044-03-20', 0, '2043-03-20', 'Task 6', 2, true, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (11, NULL, 0, '2022-03-20', 'Task 6', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (12, '2044-03-20', 0, '2022-03-20', 'Task 6', 2, false, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (13, NULL, 0, '2022-03-20', 'Task 6', 2, true, 0);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (14, '2044-03-20', 0, '2022-03-20', 'Task 6', 2, true, 0);