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

This commit is contained in:
Sebastian Böckelmann 2023-11-10 19:35:44 +01:00
parent 4d655c32ed
commit 2f7fb3e2b4
4 changed files with 162 additions and 51 deletions

View File

@ -4,10 +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="TaskgroupRepsitoryTest (+Delete)"> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="FindAlltasksByUser Test">
<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" /> <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/repositories/timemanager/TaskRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskRepository.java" afterDir="false" />
<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 beforePath="$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.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" />
@ -86,8 +87,8 @@
<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.TaskRepositoryTest.findAllByUser"> <component name="RunManager" selected="JUnit.TaskRepositoryTest.findAllActive">
<configuration name="TaskRepositoryTest.findAllByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="TaskRepositoryTest.deleteAllByTaskgroup" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" /> <module name="demo" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
@ -97,70 +98,71 @@
</extension> </extension>
<option name="PACKAGE_NAME" value="core.tasks" /> <option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" /> <option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<option name="METHOD_NAME" value="findAllByUser" /> <option name="METHOD_NAME" value="deleteAllByTaskgroup" />
<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" />
</method> </method>
</configuration> </configuration>
<configuration name="TaskgroupRepsitoryTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="TaskRepositoryTest.deleteByTaskID" 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.taskgroups.*" /> <option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" /> <option name="ENABLED" value="true" />
</pattern> </pattern>
</extension> </extension>
<option name="PACKAGE_NAME" value="core.taskgroups" /> <option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" /> <option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<option name="TEST_OBJECT" value="class" /> <option name="METHOD_NAME" value="deleteByTaskID" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskgroupRepsitoryTest.delete" 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="delete" />
<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" />
</method> </method>
</configuration> </configuration>
<configuration name="TaskgroupRepsitoryTest.deleteAllByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="TaskRepositoryTest.findAllActive" 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.taskgroups.*" /> <option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" /> <option name="ENABLED" value="true" />
</pattern> </pattern>
</extension> </extension>
<option name="PACKAGE_NAME" value="core.taskgroups" /> <option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" /> <option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<option name="METHOD_NAME" value="deleteAllByUser" /> <option name="METHOD_NAME" value="findAllActive" />
<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" />
</method> </method>
</configuration> </configuration>
<configuration name="TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="TaskRepositoryTest.findAllOverdue" 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.taskgroups.*" /> <option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" /> <option name="ENABLED" value="true" />
</pattern> </pattern>
</extension> </extension>
<option name="PACKAGE_NAME" value="core.taskgroups" /> <option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupRepsitoryTest" /> <option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<option name="METHOD_NAME" value="findAllTopTaskgroupsByUser" /> <option name="METHOD_NAME" value="findAllOverdue" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskRepositoryTest.findAllUpcoming" 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="findAllUpcoming" />
<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" />
@ -175,11 +177,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.TaskRepositoryTest.findAllByUser" /> <item itemvalue="JUnit.TaskRepositoryTest.findAllActive" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.delete" /> <item itemvalue="JUnit.TaskRepositoryTest.findAllUpcoming" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest" /> <item itemvalue="JUnit.TaskRepositoryTest.findAllOverdue" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.deleteAllByUser" /> <item itemvalue="JUnit.TaskRepositoryTest.deleteByTaskID" />
<item itemvalue="JUnit.TaskgroupRepsitoryTest.findAllTopTaskgroupsByUser" /> <item itemvalue="JUnit.TaskRepositoryTest.deleteAllByTaskgroup" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -215,7 +217,8 @@
<workItem from="1699380499473" duration="2708000" /> <workItem from="1699380499473" duration="2708000" />
<workItem from="1699460935890" duration="5000" /> <workItem from="1699460935890" duration="5000" />
<workItem from="1699466564154" duration="6646000" /> <workItem from="1699466564154" duration="6646000" />
<workItem from="1699473376129" duration="1378000" /> <workItem from="1699473376129" duration="1423000" />
<workItem from="1699639316405" duration="1997000" />
</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" />
@ -417,14 +420,21 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1699471078386</updated> <updated>1699471078386</updated>
</task> </task>
<option name="localTasksCounter" value="26" /> <task id="LOCAL-00026" summary="FindAlltasksByUser Test">
<option name="closed" value="true" />
<created>1699474949938</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1699474949938</updated>
</task>
<option name="localTasksCounter" value="27" />
<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="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" />
<MESSAGE value="Delete and clear Tasks" /> <MESSAGE value="Delete and clear Tasks" />
@ -449,7 +459,8 @@
<MESSAGE value="Fix failing test case" /> <MESSAGE value="Fix failing test case" />
<MESSAGE value="TaskgroupRepsitoryTest" /> <MESSAGE value="TaskgroupRepsitoryTest" />
<MESSAGE value="TaskgroupRepsitoryTest (+Delete)" /> <MESSAGE value="TaskgroupRepsitoryTest (+Delete)" />
<option name="LAST_COMMIT_MESSAGE" value="TaskgroupRepsitoryTest (+Delete)" /> <MESSAGE value="FindAlltasksByUser Test" />
<option name="LAST_COMMIT_MESSAGE" value="FindAlltasksByUser Test" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
@ -479,6 +490,16 @@
<line>57</line> <line>57</line>
<option name="timeStamp" value="12" /> <option name="timeStamp" value="12" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.java</url>
<line>152</line>
<option name="timeStamp" value="17" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.java</url>
<line>151</line>
<option name="timeStamp" value="18" />
</line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>
</component> </component>

View File

@ -17,22 +17,21 @@ public interface TaskRepository extends CrudRepository<Task, Long> {
@Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.finished = ?2") @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.finished = ?2")
List<Task> findAllByUser(String username, boolean finished); List<Task> findAllByUser(String username, boolean finished);
@Transactional
@Modifying @Modifying
@Query(value = "DELETE FROM Task t WHERE t.taskgroup = ?1") @Transactional
void deleteAllByTaskgroup(Taskgroup taskgroup); void deleteAllByTaskgroup(Taskgroup taskgroup);
@Transactional @Transactional
@Modifying @Modifying
@Query(value = "DELETE FROM Task t WHERE t.taskID = ?1")
void deleteByTaskID(long taskID); void deleteByTaskID(long taskID);
@Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.deadline is NOT NULL AND t.deadline > ?2 AND t.finished = FALSE") @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.deadline is NOT NULL AND t.deadline < ?2 AND t.finished = FALSE")
List<Task> findAllOverdue(String username, LocalDate now); List<Task> findAllOverdue(String username, LocalDate now);
@Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.startDate IS NOT NULL AND t.startDate > ?2 AND t.finished = FALSE") @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.startDate IS NOT NULL AND t.startDate > ?2 AND t.finished = FALSE")
List<Task> findAllUpcoming(String username, LocalDate now); List<Task> findAllUpcoming(String username, LocalDate now);
@Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.startDate IS NULL OR t.startDate <= ?2 AND t.finished = FALSE") @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND (t.startDate IS NULL OR t.startDate <= ?2) AND t.finished = FALSE")
List<Task> findAllActive(String username, LocalDate now); List<Task> findAllActive(String username, LocalDate now);
} }

View File

@ -108,6 +108,5 @@ public class TaskgroupRepsitoryTest {
for(long i=5; i<=8; i++) { for(long i=5; i<=8; i++) {
assertThat(testEntityManager.find(Taskgroup.class, i)).isNull(); assertThat(testEntityManager.find(Taskgroup.class, i)).isNull();
} }
} }
} }

View File

@ -13,8 +13,10 @@ import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlGroup; import org.springframework.test.context.jdbc.SqlGroup;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.time.LocalDate;
import java.util.List; import java.util.List;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -65,4 +67,94 @@ public class TaskRepositoryTest {
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 13L))); assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 13L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 14L))); assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 14L)));
} }
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteAllByTaskgroup() {
Taskgroup taskgroup_no_tasks = testEntityManager.find(Taskgroup.class, 1L);
taskRepository.deleteAllByTaskgroup(taskgroup_no_tasks);
for(long i=1; i<=14; i++) {
assertThat(testEntityManager.find(Task.class, i)).isNotNull();
}
Taskgroup taskgroup_with_task = testEntityManager.find(Taskgroup.class, 2L);
taskRepository.deleteAllByTaskgroup(taskgroup_with_task);
for(long i=1; i<=14; i++) {
Task task = testEntityManager.find(Task.class, i);
assertThat(task).isNull();
}
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteByTaskID() {
taskRepository.deleteByTaskID(-1);
for(long i=1; i<=14; i++) {
assertThat(testEntityManager.find(Task.class, i)).isNotNull();
}
taskRepository.deleteByTaskID(1);
assertThat(testEntityManager.find(Task.class, 1L)).isNull();
for(long i=2; i<=14; i++) {
assertThat(testEntityManager.find(Task.class, i)).isNotNull();
}
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void findAllOverdue() {
User testuser1 = testEntityManager.find(User.class, 1L);
LocalDate referenceDate = LocalDate.of(2023, 10, 11);
List<Task> overdue = taskRepository.findAllOverdue(testuser1.getUsername(), referenceDate);
assertEquals(2, overdue.size());
assertTrue(overdue.contains(testEntityManager.find(Task.class, 3L)));
assertTrue(overdue.contains(testEntityManager.find(Task.class, 5L)));
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void findAllUpcoming() {
User testuser1 = testEntityManager.find(User.class, 1L);
LocalDate referenceDate = LocalDate.of(2023, 10, 11);
List<Task> upcoming = taskRepository.findAllUpcoming(testuser1.getUsername(), referenceDate);
assertEquals(2, upcoming.size());
assertTrue(upcoming.contains(testEntityManager.find(Task.class, 7L)));
assertTrue(upcoming.contains(testEntityManager.find(Task.class, 9L)));
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void findAllActive() {
User testuser1 = testEntityManager.find(User.class, 1L);
LocalDate referenceDate = LocalDate.of(2023, 10, 11);
List<Task> active = taskRepository.findAllActive(testuser1.getUsername(), referenceDate);
//1,3,5,11,12
assertEquals(5, active.size());
assertTrue(active.contains(testEntityManager.find(Task.class, 1L)));
assertTrue(active.contains(testEntityManager.find(Task.class, 3L)));
assertTrue(active.contains(testEntityManager.find(Task.class, 5L)));
assertTrue(active.contains(testEntityManager.find(Task.class, 11L)));
assertTrue(active.contains(testEntityManager.find(Task.class, 12L)));
}
} }