tests #43

Merged
sebastian merged 41 commits from tests into master 2023-11-11 11:20:50 +01:00
23 changed files with 1284 additions and 62 deletions

View File

@ -0,0 +1,27 @@
name: Java CI with Maven
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Set up Maven
uses: stCarolas/setup-maven@v4.5
with:
maven-version: 3.8.2
- name: Build with Maven
run: mvn -B package --file backend/pom.xml
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
#uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

View File

@ -4,13 +4,9 @@
<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="Fix marking finished task as overdue"> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Remove entityManager from TaskService">
<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/tasks/TaskServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/app-routing.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/app-routing.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/app.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/app.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/app.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/app.module.ts" 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" />
@ -29,7 +25,7 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$/.." value="master" /> <entry key="$PROJECT_DIR$/.." value="test-failing" />
</map> </map>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
@ -56,9 +52,10 @@
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;extract.method.default.visibility&quot;: &quot;private&quot;, &quot;extract.method.default.visibility&quot;: &quot;private&quot;,
&quot;git-widget-placeholder&quot;: &quot;issue-11-angular-update&quot;, &quot;git-widget-placeholder&quot;: &quot;tests&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;last_directory_selection&quot;: &quot;D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager&quot;, &quot;last_directory_selection&quot;: &quot;D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/Programmierprojekte/Dicewars/client&quot;, &quot;last_opened_file_path&quot;: &quot;/media/sebastian/Data2/Programmierprojekte/Storycreator&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
@ -70,11 +67,104 @@
}, },
&quot;keyToStringList&quot;: { &quot;keyToStringList&quot;: {
&quot;DatabaseDriversLRU&quot;: [ &quot;DatabaseDriversLRU&quot;: [
&quot;h2&quot;,
&quot;mariadb&quot; &quot;mariadb&quot;
] ]
} }
}</component> }</component>
<component name="RunManager"> <component name="RecentsManager">
<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.TaskServiceTest">
<configuration name="TaskServiceTest" 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.TaskServiceTest" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.clearTasks" 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.TaskServiceTest" />
<option name="METHOD_NAME" value="clearTasks" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.deleteTask" 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.TaskServiceTest" />
<option name="METHOD_NAME" value="deleteTask" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.finishTask" 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.TaskServiceTest" />
<option name="METHOD_NAME" value="finishTask" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.loadAllTasks" 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.TaskServiceTest" />
<option name="METHOD_NAME" value="loadAllTasks" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="DemoApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true"> <configuration name="DemoApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<module name="demo" /> <module name="demo" />
<option name="SPRING_BOOT_MAIN_CLASS" value="core.DemoApplication" /> <option name="SPRING_BOOT_MAIN_CLASS" value="core.DemoApplication" />
@ -82,6 +172,15 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.TaskServiceTest" />
<item itemvalue="JUnit.TaskServiceTest.loadAllTasks" />
<item itemvalue="JUnit.TaskServiceTest.finishTask" />
<item itemvalue="JUnit.TaskServiceTest.clearTasks" />
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
</list>
</recent_temporary>
</component> </component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
@ -111,6 +210,13 @@
<workItem from="1698499063683" duration="8312000" /> <workItem from="1698499063683" duration="8312000" />
<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="1699380499473" duration="2708000" />
<workItem from="1699460935890" duration="5000" />
<workItem from="1699466564154" duration="6646000" />
<workItem from="1699473376129" duration="1423000" />
<workItem from="1699639316405" duration="9267000" />
<workItem from="1699684493731" duration="1121000" />
</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" />
@ -272,23 +378,117 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1698592265846</updated> <updated>1698592265846</updated>
</task> </task>
<option name="localTasksCounter" value="21" /> <task id="LOCAL-00021" summary="Write simple Testcase for ci/cd">
<option name="closed" value="true" />
<created>1699207483922</created>
<option name="number" value="00021" />
<option name="presentableId" value="LOCAL-00021" />
<option name="project" value="LOCAL" />
<updated>1699207483922</updated>
</task>
<task id="LOCAL-00022" summary="Deactivate Overall System test (temporarly)">
<option name="closed" value="true" />
<created>1699207725882</created>
<option name="number" value="00022" />
<option name="presentableId" value="LOCAL-00022" />
<option name="project" value="LOCAL" />
<updated>1699207725883</updated>
</task>
<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>
<task id="LOCAL-00024" summary="TaskgroupRepsitoryTest">
<option name="closed" value="true" />
<created>1699470020407</created>
<option name="number" value="00024" />
<option name="presentableId" value="LOCAL-00024" />
<option name="project" value="LOCAL" />
<updated>1699470020407</updated>
</task>
<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>
<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>
<task id="LOCAL-00027" summary="Test TaskRepository">
<option name="closed" value="true" />
<created>1699641346158</created>
<option name="number" value="00027" />
<option name="presentableId" value="LOCAL-00027" />
<option name="project" value="LOCAL" />
<updated>1699641346158</updated>
</task>
<task id="LOCAL-00028" summary="Initialize Testing of Testservice">
<option name="closed" value="true" />
<created>1699645467388</created>
<option name="number" value="00028" />
<option name="presentableId" value="LOCAL-00028" />
<option name="project" value="LOCAL" />
<updated>1699645467388</updated>
</task>
<task id="LOCAL-00029" summary="Use @Sql instead of persit()">
<option name="closed" value="true" />
<created>1699646291964</created>
<option name="number" value="00029" />
<option name="presentableId" value="LOCAL-00029" />
<option name="project" value="LOCAL" />
<updated>1699646291964</updated>
</task>
<task id="LOCAL-00030" summary="Resolve Merge-Conflict">
<option name="closed" value="true" />
<created>1699693472182</created>
<option name="number" value="00030" />
<option name="presentableId" value="LOCAL-00030" />
<option name="project" value="LOCAL" />
<updated>1699693472182</updated>
</task>
<task id="LOCAL-00031" summary="Deleting Task test">
<option name="closed" value="true" />
<created>1699694400508</created>
<option name="number" value="00031" />
<option name="presentableId" value="LOCAL-00031" />
<option name="project" value="LOCAL" />
<updated>1699694400508</updated>
</task>
<task id="LOCAL-00032" summary="Consider increased number of tasks">
<option name="closed" value="true" />
<created>1699694552466</created>
<option name="number" value="00032" />
<option name="presentableId" value="LOCAL-00032" />
<option name="project" value="LOCAL" />
<updated>1699694552466</updated>
</task>
<task id="LOCAL-00033" summary="Remove entityManager from TaskService">
<option name="closed" value="true" />
<created>1699695051881</created>
<option name="number" value="00033" />
<option name="presentableId" value="LOCAL-00033" />
<option name="project" value="LOCAL" />
<updated>1699695051881</updated>
</task>
<option name="localTasksCounter" value="34" />
<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="Datastructure for Tasks" />
<MESSAGE value="Implementing edit route for tasks" />
<MESSAGE value="Delete and clear Tasks" />
<MESSAGE value="Delete and clear Tasks (Frontend)" />
<MESSAGE value="Define Entity BasicTaskSchedule and Taskcontroller" />
<MESSAGE value="Delete Schedules" />
<MESSAGE value="Deliver Schedule Path Info when fetching Schedules" />
<MESSAGE value="Removed unused TaskgroupShortInfo.java" />
<MESSAGE value="Fix Foreign Key Constraint Fail when deleting Taskgroups" /> <MESSAGE value="Fix Foreign Key Constraint Fail when deleting Taskgroups" />
<MESSAGE value="Stop and Finish TaskSchedules" /> <MESSAGE value="Stop and Finish TaskSchedules" />
<MESSAGE value="Include TaskScheduleStopResponse" /> <MESSAGE value="Include TaskScheduleStopResponse" />
@ -300,16 +500,25 @@
<MESSAGE value="List missed Schedules" /> <MESSAGE value="List missed Schedules" />
<MESSAGE value="Forget single schedule" /> <MESSAGE value="Forget single schedule" />
<MESSAGE value="Fix marking finished task as overdue" /> <MESSAGE value="Fix marking finished task as overdue" />
<option name="LAST_COMMIT_MESSAGE" value="Fix marking finished task as overdue" /> <MESSAGE value="Write simple Testcase for ci/cd" />
<MESSAGE value="Deactivate Overall System test (temporarly)" />
<MESSAGE value="Fix failing test case" />
<MESSAGE value="TaskgroupRepsitoryTest" />
<MESSAGE value="TaskgroupRepsitoryTest (+Delete)" />
<MESSAGE value="FindAlltasksByUser Test" />
<MESSAGE value="Test TaskRepository" />
<MESSAGE value="Initialize Testing of Testservice" />
<MESSAGE value="Use @Sql instead of persit()" />
<MESSAGE value="Make the Test Transactional" />
<MESSAGE value="Resolve Merge-Conflict" />
<MESSAGE value="Deleting Task test" />
<MESSAGE value="Consider increased number of tasks" />
<MESSAGE value="Remove entityManager from TaskService" />
<option name="LAST_COMMIT_MESSAGE" value="Remove entityManager from TaskService" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.java</url>
<line>52</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url> <url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url>
<line>87</line> <line>87</line>
@ -325,6 +534,11 @@
<line>202</line> <line>202</line>
<option name="timeStamp" value="10" /> <option name="timeStamp" value="10" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/entities/User.java</url>
<line>57</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>
</component> </component>

View File

@ -54,6 +54,17 @@
<artifactId>jjwt</artifactId> <artifactId>jjwt</artifactId>
<version>0.9.1</version> <version>0.9.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -18,7 +18,7 @@ public class DemoApplication{
} }
@Bean /*@Bean
public CommandLineRunner init(RoleRepository roleRepository, UserRepository userRepository, PropertyService propertyService) { public CommandLineRunner init(RoleRepository roleRepository, UserRepository userRepository, PropertyService propertyService) {
return args -> { return args -> {
for (UserRole userRole : UserRole.values()) { for (UserRole userRole : UserRole.values()) {
@ -32,5 +32,5 @@ public class DemoApplication{
FirstUserObserver observer = new FirstUserObserver(userRepository); FirstUserObserver observer = new FirstUserObserver(userRepository);
observer.start(); observer.start();
}; };
} }*/
} }

View File

@ -15,6 +15,14 @@ public class TaskgroupFieldInfo {
private long parentID; private long parentID;
public TaskgroupFieldInfo(String name, long parentID) {
this.name = name;
this.parentID = parentID;
}
public TaskgroupFieldInfo() {
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -14,6 +14,16 @@ public class TaskFieldInfo {
private LocalDate startDate; private LocalDate startDate;
private LocalDate deadline; private LocalDate deadline;
public TaskFieldInfo() {
}
public TaskFieldInfo(String taskName, int eta, LocalDate startDate, LocalDate deadline) {
this.taskName = taskName;
this.eta = eta;
this.startDate = startDate;
this.deadline = deadline;
}
public String getTaskName() { public String getTaskName() {
return taskName; return taskName;
} }

View File

@ -8,6 +8,7 @@ import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
@Entity @Entity
@ -50,6 +51,13 @@ public class User {
this.password = password; this.password = password;
} }
public User(Long id, String username, String email, String password) {
this.id = id;
this.username = username;
this.email = email;
this.password = password;
}
public Long getId() { public Long getId() {
return id; return id;
} }
@ -89,4 +97,17 @@ public class User {
public void setRoles(Set<RoleEntity> roles) { public void setRoles(Set<RoleEntity> roles) {
this.roles = roles; this.roles = roles;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Objects.equals(username, user.username) && Objects.equals(email, user.email) && Objects.equals(password, user.password) && Objects.equals(roles, user.roles);
}
@Override
public int hashCode() {
return Objects.hash(username, email, password, roles);
}
} }

View File

@ -12,7 +12,7 @@ import java.util.Set;
public class Task { public class Task {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.IDENTITY)
private long taskID; private long taskID;
@ManyToOne @ManyToOne
@ -113,19 +113,6 @@ public class Task {
this.workTime += workTime; this.workTime += workTime;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Task task = (Task) o;
return taskID == task.taskID;
}
@Override
public int hashCode() {
return Objects.hash(taskID);
}
public void setTaskID(long taskID) { public void setTaskID(long taskID) {
this.taskID = taskID; this.taskID = taskID;
} }
@ -150,4 +137,31 @@ public class Task {
public void increaseActiveTime(int minutesSpent) { public void increaseActiveTime(int minutesSpent) {
this.workTime += minutesSpent; this.workTime += minutesSpent;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Task task = (Task) o;
return taskID == task.taskID && eta == task.eta && finished == task.finished && workTime == task.workTime && Objects.equals(taskgroup, task.taskgroup) && Objects.equals(taskName, task.taskName) && Objects.equals(startDate, task.startDate) && Objects.equals(deadline, task.deadline);
}
@Override
public int hashCode() {
return Objects.hash(taskID, taskgroup, taskName, startDate, deadline, eta, finished, workTime);
}
@Override
public String toString() {
return "Task{" +
"taskID=" + taskID +
", taskgroup=" + taskgroup +
", taskName='" + taskName + '\'' +
", startDate=" + startDate +
", deadline=" + deadline +
", eta=" + eta +
", finished=" + finished +
", workTime=" + workTime +
'}';
}
} }

View File

@ -11,7 +11,7 @@ import java.util.*;
public class Taskgroup { public class Taskgroup {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.IDENTITY)
private long taskgroupID; private long taskgroupID;
@NotBlank @NotBlank
@ -29,6 +29,7 @@ public class Taskgroup {
@JoinColumn(name = "parent_id") @JoinColumn(name = "parent_id")
private Taskgroup parent; private Taskgroup parent;
@OneToMany(mappedBy = "taskgroup", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(mappedBy = "taskgroup", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Task> tasks; private Set<Task> tasks;
@ -116,4 +117,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);
}
} }

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

@ -5,5 +5,6 @@ public enum ServiceExitCode {
OK, OK,
ENTITY_ALREADY_EXIST, ENTITY_ALREADY_EXIST,
MISSING_ENTITY, MISSING_ENTITY,
INVALID_OPERATION; INVALID_OPERATION,
INVALID_PARAMETER;
} }

View File

@ -20,12 +20,15 @@ public class TaskService {
private final TaskRepository taskRepository; private final TaskRepository taskRepository;
private final TaskScheduleService taskScheduleService; private final TaskScheduleService taskScheduleService;
private final TaskgroupRepository taskgroupRepository;
public TaskService(@Autowired TaskRepository taskRepository, public TaskService(@Autowired TaskRepository taskRepository,
@Autowired TaskScheduleService taskScheduleService) { @Autowired TaskScheduleService taskScheduleService,
TaskgroupRepository taskgroupRepository) {
this.taskRepository = taskRepository; this.taskRepository = taskRepository;
this.taskScheduleService = taskScheduleService; this.taskScheduleService = taskScheduleService;
this.taskgroupRepository = taskgroupRepository;
} }
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) { public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
@ -33,6 +36,11 @@ public class TaskService {
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST); return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
} }
//Check for invalid date (deadline before start
if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
}
Task task = new Task(taskgroup, taskFieldInfo.getTaskName(), taskFieldInfo.getStartDate(), taskFieldInfo.getDeadline(), taskFieldInfo.getEta()); Task task = new Task(taskgroup, taskFieldInfo.getTaskName(), taskFieldInfo.getStartDate(), taskFieldInfo.getDeadline(), taskFieldInfo.getEta());
taskgroup.getTasks().add(task); taskgroup.getTasks().add(task);
@ -57,11 +65,25 @@ public class TaskService {
} }
public ServiceResult<Task> editTask(Task task, TaskFieldInfo taskFieldInfo) { public ServiceResult<Task> editTask(Task task, TaskFieldInfo taskFieldInfo) {
if(!task.getTaskName().equals(taskFieldInfo.getTaskName()) && !existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) { if(!task.getTaskName().equals(taskFieldInfo.getTaskName())) {
task.setTaskName(taskFieldInfo.getTaskName()); //taskname will be updated
if(existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) {
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
} else {
task.setTaskName(taskFieldInfo.getTaskName());
}
}
} else if(!task.getTaskName().equals(taskFieldInfo.getTaskName()) && existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) { //Check for invalid date (deadline before start
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST); if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
}
//Check for invalid date (deadline before start
if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
} }
task.setEta(taskFieldInfo.getEta()); task.setEta(taskFieldInfo.getEta());
task.setStartDate(taskFieldInfo.getStartDate()); task.setStartDate(taskFieldInfo.getStartDate());

View File

@ -80,10 +80,6 @@ public class TaskgroupService {
taskgroupRepository.delete(taskgroup); taskgroupRepository.delete(taskgroup);
} }
public List<Taskgroup> getTaskgroupsByUser(String username) {
return taskgroupRepository.findAllByUser(username);
}
public List<Taskgroup> getTopTaskgroupsByUser(String username) { public List<Taskgroup> getTopTaskgroupsByUser(String username) {
return taskgroupRepository.findAllTopTaskgroupsByUser(username); return taskgroupRepository.findAllTopTaskgroupsByUser(username);
} }

View File

@ -3,11 +3,11 @@ package core;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest /*@SpringBootTest*/
class DemoApplicationTests { class DemoApplicationTests {
@Test /*@Test
void contextLoads() { void contextLoads() {
} }*/
} }

View File

@ -0,0 +1,112 @@
package core.taskgroups;
import core.entities.User;
import core.entities.timemanager.Task;
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();
}
}
@Test
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
void delete() {
Taskgroup no_children = testEntityManager.find(Taskgroup.class, 1L);
Taskgroup taskgroup_with_children = testEntityManager.find(Taskgroup.class, 5L);
taskgroupRepository.delete(no_children);
assertThat(testEntityManager.find(Taskgroup.class, 1L)).isNull();
for(long i=2; i<=8; i++) {
assertThat(testEntityManager.find(Taskgroup.class, i)).isNotNull();
}
taskgroupRepository.delete(taskgroup_with_children);
for(long i=5; i<=8; i++) {
assertThat(testEntityManager.find(Taskgroup.class, i)).isNull();
}
}
}

View File

@ -0,0 +1,202 @@
package core.taskgroups;
import core.api.models.timemanager.taskgroup.TaskgroupFieldInfo;
import core.entities.User;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.UserRepository;
import core.repositories.timemanager.TaskgroupRepository;
import core.services.PermissionResult;
import core.services.ServiceExitCode;
import core.services.ServiceResult;
import core.services.TaskgroupService;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
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.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlGroup;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.SpringRunner;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@Transactional
public class TaskgroupServiceTest {
@Autowired
private TaskgroupRepository taskgroupRepository;
@Autowired
private TaskgroupService taskgroupService;
@Autowired
private EntityManager entityManager;
private static final String username = "Testuser1";
private static final String username2 = "Testuser2";
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void getTaskgroupByIDAndUsername() {
//Situation 1: correct taskgroup and username
assertFalse(taskgroupRepository.findById(1L).isEmpty());
PermissionResult<Taskgroup> permissionResult = taskgroupService.getTaskgroupByIDAndUsername(1L, username);
assertThat(permissionResult).isNotNull();
assertTrue(permissionResult.isHasPermissions());
assertEquals(ServiceExitCode.OK, permissionResult.getExitCode());
assertEquals(taskgroupRepository.findById(1L).get(), permissionResult.getResult());
//Situation 2: invalid taskgroup
PermissionResult<Taskgroup> invalid_group = taskgroupService.getTaskgroupByIDAndUsername(-1L, username);
assertThat(invalid_group).isNotNull();
assertEquals(ServiceExitCode.MISSING_ENTITY, invalid_group.getExitCode());
assertFalse(invalid_group.isHasPermissions());
//Situation 3: invalid user
PermissionResult<Taskgroup> invalid_user = taskgroupService.getTaskgroupByIDAndUsername(1L, "Rotzbakke");
assertThat(invalid_user).isNotNull();
assertEquals(ServiceExitCode.OK, invalid_user.getExitCode());
assertFalse(invalid_user.isHasPermissions());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void addTaskgroup() {
TaskgroupFieldInfo taskgroupFieldInfo = new TaskgroupFieldInfo("Taskgroup", -1);
//Situation 1: No such user
assertThrows(NoSuchElementException.class, () -> taskgroupService.addTaskgroup(taskgroupFieldInfo, "Rotzbakke"));
//Situation 2: Taskgroup already exists
Taskgroup taskgroup = taskgroupRepository.findById(1L).get();
ServiceResult<Taskgroup> creationResult = taskgroupService.addTaskgroup(new TaskgroupFieldInfo(taskgroup.getTaskgroupName(), -1), username);
assertEquals(ServiceExitCode.ENTITY_ALREADY_EXIST, creationResult.getExitCode());
assertThat(creationResult.getResult()).isNull();
//Situation 3: Taskgroup does not exist, no parent
ServiceResult<Taskgroup> creationResult_3 = taskgroupService.addTaskgroup(taskgroupFieldInfo, username);
assertEquals(ServiceExitCode.OK, creationResult_3.getExitCode());
assertTrue(taskgroupRepository.existsById(creationResult_3.getResult().getTaskgroupID()));
//Situation 4: Taskgroup does not exist, with parent; invalid parent (no existent)
ServiceResult<Taskgroup> creationResult_4 = taskgroupService.addTaskgroup(new TaskgroupFieldInfo("Situation 4", 100L), username);
assertEquals(ServiceExitCode.MISSING_ENTITY, creationResult_4.getExitCode());
//Situation 5: Taskgroup does not exist, parent exist
ServiceResult<Taskgroup> creationResult_5 = taskgroupService.addTaskgroup(new TaskgroupFieldInfo("Situation 5", 2L), username);
assertEquals(ServiceExitCode.OK, creationResult_5.getExitCode());
assertTrue(taskgroupRepository.existsById(creationResult_5.getResult().getTaskgroupID()));
//Situation 6: taskgroup exist on another user
ServiceResult<Taskgroup> creationResult_6 = taskgroupService.addTaskgroup(new TaskgroupFieldInfo(taskgroup.getTaskgroupName(), -1), username2);
assertEquals(ServiceExitCode.OK, creationResult_6.getExitCode());
assertTrue(taskgroupRepository.existsById(creationResult_6.getResult().getTaskgroupID()));
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void editTaskgroup() {
Taskgroup taskgroup = taskgroupRepository.findById(1L).get();
//Situation 1: Nothing changed
ServiceExitCode exitCode_1 = taskgroupService.editTaskgroup(taskgroup, new TaskgroupFieldInfo(taskgroup.getTaskgroupName(),-1));
assertEquals(ServiceExitCode.OK, exitCode_1);
//Situation 2: Name is already taken
ServiceExitCode exitCode_2 = taskgroupService.editTaskgroup(taskgroup, new TaskgroupFieldInfo("Taskgroup 1", -1));
assertEquals(ServiceExitCode.ENTITY_ALREADY_EXIST, exitCode_2);
//Situation 3: All fine
ServiceExitCode exitCode_3 = taskgroupService.editTaskgroup(taskgroup, new TaskgroupFieldInfo("Situation 3", -1));
assertEquals(ServiceExitCode.OK, exitCode_3);
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteTaskgroup() {
taskgroupService.deleteTaskgroup(entityManager.find(Taskgroup.class, 1L));
assertThat(entityManager.find(Taskgroup.class, 1L)).isNull();
taskgroupService.deleteTaskgroup(entityManager.find(Taskgroup.class, 2L));
assertThat(entityManager.find(Taskgroup.class, 2L)).isNull();
assertThat(entityManager.find(Taskgroup.class, 3L)).isNull();
for(long i=1; i<=14; i++) {
assertThat(entityManager.find(Task.class, i)).isNull();
}
taskgroupService.deleteTaskgroup(entityManager.find(Taskgroup.class, 5L));
assertThat(entityManager.find(Taskgroup.class, 5L)).isNull();
assertThat(entityManager.find(Taskgroup.class, 6L)).isNull();
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void getTopTaskgroupsByUser() {
//Situation 1: User without taskgroups
List<Taskgroup> taskgroups_user2 = taskgroupService.getTopTaskgroupsByUser(username2);
assertEquals(0, taskgroups_user2.size());
//Situation 2: user with taskgroups
List<Taskgroup> taskgroups_user1 = taskgroupService.getTopTaskgroupsByUser(username);
assertEquals(3, taskgroups_user1.size());
assertTrue(taskgroups_user1.contains(entityManager.find(Taskgroup.class, 1L)));
assertTrue(taskgroups_user1.contains(entityManager.find(Taskgroup.class, 2L)));
assertTrue(taskgroups_user1.contains(entityManager.find(Taskgroup.class, 5L)));
//Situation 3: No existent username
assertEquals(0, taskgroupService.getTopTaskgroupsByUser("Rotzbakke").size());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteTaskgroupByUser() {
User referenceUser1 = entityManager.find(User.class, 1L);
User referenceUser2 = entityManager.find(User.class, 2L);
taskgroupService.deleteTaskgroupByUser(referenceUser2);
for(long i=1; i<=8; i++) {
assertThat(entityManager.find(Taskgroup.class, i)).isNotNull();
}
taskgroupService.deleteTaskgroupByUser(referenceUser1);
for(long i=1; i<=8; i++) {
assertThat(entityManager.find(Taskgroup.class, i)).isNull();
}
for(long i=1; i<=14; i++) {
assertThat(entityManager.find(Task.class, i)).isNull();
}
}
}

View File

@ -0,0 +1,160 @@
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.time.LocalDate;
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.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(8, 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)));
}
@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(6, 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)));
}
}

View File

@ -0,0 +1,278 @@
package core.tasks;
import core.api.models.timemanager.tasks.TaskFieldInfo;
import core.api.models.timemanager.tasks.TaskScope;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
import core.repositories.timemanager.TaskgroupRepository;
import core.services.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlGroup;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@Transactional
public class TaskServiceTest {
@Autowired
private TaskService taskService;
@Autowired
private EntityManager entityManager;
private static final String username = "Testuser1";
private static final String username2 = "Testuser2";
@Autowired
private TaskRepository taskRepository;
@Autowired
private TaskgroupRepository taskgroupRepository;
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void createTask() {
//Situation 1: Task with that name already exists in a taskgroup
TaskFieldInfo taskFieldInfo_1 = new TaskFieldInfo(entityManager.find(Task.class, 1L).getTaskName(), 0, null, null);
ServiceResult<Task> situation_1 = taskService.createTask(entityManager.find(Taskgroup.class, 2L), taskFieldInfo_1);
assertEquals(ServiceExitCode.ENTITY_ALREADY_EXIST, situation_1.getExitCode());
//Situation 2: Task with that name exists in another taskgroup
TaskFieldInfo taskFieldInfo_2 = new TaskFieldInfo(entityManager.find(Task.class, 1L).getTaskName(), 0, null, null);
ServiceResult<Task> result_2 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_2);
assertEquals(ServiceExitCode.OK, result_2.getExitCode());
assertThat(entityManager.find(Task.class, result_2.getResult().getTaskID())).isNotNull();
//Situation 3: Normal, everything fine
TaskFieldInfo taskFieldInfo_3 = new TaskFieldInfo("Situation 3", 0, null, null);
ServiceResult<Task> result_3 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_3);
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
assertThat(entityManager.find(Task.class, result_3.getResult().getTaskID())).isNotNull();
//Robustness - Test for invalid dates
//Situation 4: Deadline, no start
TaskFieldInfo taskFieldInfo_4 = new TaskFieldInfo("Situation 4", 0, null, LocalDate.now());
ServiceResult<Task> result_4 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_4);
assertEquals(ServiceExitCode.OK, result_4.getExitCode());
assertThat(entityManager.find(Task.class, result_4.getResult().getTaskID())).isNotNull();
//Situation 5: Start but no deadline
TaskFieldInfo taskFieldInfo_5 = new TaskFieldInfo("Situation 5", 0, LocalDate.now(),null);
ServiceResult<Task> result_5 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_5);
assertEquals(ServiceExitCode.OK, result_5.getExitCode());
assertThat(entityManager.find(Task.class, result_5.getResult().getTaskID())).isNotNull();
//Situation 6: Deadline before start (invalid)
TaskFieldInfo taskFieldInfo_6 = new TaskFieldInfo("Situation 6", 0, LocalDate.now(),LocalDate.of(2010, 3, 20));
ServiceResult<Task> result_6= taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_6);
assertEquals(ServiceExitCode.INVALID_PARAMETER, result_6.getExitCode());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void getTaskPermissions() {
//Situation 1: correct task and username
PermissionResult<Task> permissionResult_1 = taskService.getTaskPermissions(1L, username);
assertEquals(ServiceExitCode.OK, permissionResult_1.getExitCode());
assertTrue(permissionResult_1.isHasPermissions());
assertEquals(entityManager.find(Task.class, 1L), permissionResult_1.getResult());
//Situation 2: invalid taskgroup
PermissionResult<Task> permissionResult_2 = taskService.getTaskPermissions(200L, username);
assertEquals(ServiceExitCode.MISSING_ENTITY, permissionResult_2.getExitCode());
assertFalse(permissionResult_2.isHasPermissions());
assertThat(permissionResult_2.getResult()).isNull();
//Situation 3: invalid user
PermissionResult<Task> permissionResult_3 = taskService.getTaskPermissions(1L, username2);
assertEquals(ServiceExitCode.OK, permissionResult_3.getExitCode());
assertFalse(permissionResult_2.isHasPermissions());
assertEquals(entityManager.find(Task.class, 1L), permissionResult_3.getResult());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void editTask() {
//Situation 1: Nothing is updated
Task task_1 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_1 = new TaskFieldInfo(entityManager.find(Task.class, 1L).getTaskName(), 0, null, null);
ServiceResult<Task> result_1 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_1);
assertEquals(ServiceExitCode.OK, result_1.getExitCode());
assertEquals(task_1, result_1.getResult());
//Situation 2: Name is updated to name that already exists within the taskgroup
Task task_2 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_2 = new TaskFieldInfo(entityManager.find(Task.class, 2L).getTaskName(), 0, null, null);
ServiceResult<Task> result_2 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_2);
task_2.setTaskName(entityManager.find(Task.class, 2L).getTaskName());
assertEquals(ServiceExitCode.ENTITY_ALREADY_EXIST, result_2.getExitCode());
assertNotEquals(task_2, result_2.getResult());
//Situation 3: Name is updated to nonexistend Name
Task task_3 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_3 = new TaskFieldInfo("Situation 3", 0, null, null);
ServiceResult<Task> result_3 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_3);
task_3.setTaskName("Situation 3");
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
assertEquals(task_3, result_3.getResult());
//Situation 4: eta is updated
Task task_4 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_4 = new TaskFieldInfo(task_4.getTaskName(), 90, null, null);
ServiceResult<Task> result_4 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_4);
task_4.setEta(90);
assertEquals(ServiceExitCode.OK, result_4.getExitCode());
assertEquals(task_4, result_4.getResult());
//Situation 5: deadline and start is updated in a valid way
Task task_5 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_5 = new TaskFieldInfo(task_5.getTaskName(), task_5.getEta(), LocalDate.of(2023, 4, 9), LocalDate.of(2023,5,9));
ServiceResult<Task> result_5 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_5);
task_5.setStartDate(LocalDate.of(2023,4,9));
task_5.setDeadline(LocalDate.of(2023,5,9));
assertEquals(ServiceExitCode.OK, result_5.getExitCode());
assertEquals(task_5, result_5.getResult());
//Situation 6: Deadline and start are updated in a not valid way
Task task_6 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_6 = new TaskFieldInfo(task_5.getTaskName(), task_5.getEta(), LocalDate.of(2023, 5, 9), LocalDate.of(2023,4,9));
ServiceResult<Task> result_6 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_6);
task_6.setStartDate(LocalDate.of(2023,5,9));
task_6.setDeadline(LocalDate.of(2023,4,9));
assertEquals(ServiceExitCode.INVALID_PARAMETER, result_6.getExitCode());
assertNotEquals(task_6, result_6.getResult());
//Situation 10 Startdate = null;
Task task_10 = entityManager.find(Task.class, 5L);
TaskFieldInfo taskFieldInfo_10 = new TaskFieldInfo(task_10.getTaskName(), task_10.getEta(),null, task_10.getDeadline());
ServiceResult<Task> result_10 = taskService.editTask(entityManager.find(Task.class, 5L), taskFieldInfo_10);
task_10.setStartDate(null);
assertEquals(ServiceExitCode.OK, result_10.getExitCode());
assertEquals(task_10, result_10.getResult());
//Situation 11 Deadline = null
Task task_11 = entityManager.find(Task.class, 5L);
TaskFieldInfo taskFieldInfo_11 = new TaskFieldInfo(task_11.getTaskName(), task_11.getEta(),task_11.getStartDate(), null);
ServiceResult<Task> result_11 = taskService.editTask(entityManager.find(Task.class, 5L), taskFieldInfo_11);
task_11.setDeadline(null);
assertEquals(ServiceExitCode.OK, result_11.getExitCode());
assertEquals(task_11, result_11.getResult());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteTask() {
for(long i=1; i<=15; i++) {
taskService.deleteTask(entityManager.find(Task.class, i));
assertThat(entityManager.find(Task.class, i)).isNull();
}
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void clearTasks() {
//Situation 1: Delete from taskgroup with no tasks
taskService.clearTasks(entityManager.find(Taskgroup.class, 1L));
for(long i=1; i<=15; i++) {
assertThat(entityManager.find(Task.class, i)).isNotNull();
}
//Situation 2: Delete from taskgroup with tasks
taskService.clearTasks(entityManager.find(Taskgroup.class, 2L));
for(long i=1; i<=15; i++) {
assertThat(entityManager.find(Task.class, i)).isNull();
}
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void finishTask() {
taskService.finishTask(entityManager.find(Task.class, 1L));
assertTrue(entityManager.find(Task.class, 1L).isFinished());
taskService.finishTask(entityManager.find(Task.class, 2L));
assertTrue(entityManager.find(Task.class, 1L).isFinished());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void loadAllTasks() {
//Situation 1: No tasks existing
List<Task> result_1 = taskService.loadAllTasks(username2, TaskScope.UNFINISHED);
assertEquals(0, result_1.size());
//Situation 2: Tasks existing, Unfinished#
List<Task> result_2 = taskService.loadAllTasks(username, TaskScope.UNFINISHED);
assertEquals(8, result_2.size());
assertTrue(result_2.contains(entityManager.find(Task.class, 1L)));
assertTrue(result_2.contains(entityManager.find(Task.class, 3L)));
assertTrue(result_2.contains(entityManager.find(Task.class, 5L)));
assertTrue(result_2.contains(entityManager.find(Task.class, 7L)));
assertTrue(result_2.contains(entityManager.find(Task.class, 9L)));
assertTrue(result_2.contains(entityManager.find(Task.class, 11L)));
assertTrue(result_2.contains(entityManager.find(Task.class, 12L)));
//Situation 3: Finished tasks
List<Task> result_3 = taskService.loadAllTasks(username, TaskScope.FINISHED);
assertEquals(7, result_3.size());
assertTrue(result_3.contains(entityManager.find(Task.class, 2L)));
assertTrue(result_3.contains(entityManager.find(Task.class, 4L)));
assertTrue(result_3.contains(entityManager.find(Task.class, 6L)));
assertTrue(result_3.contains(entityManager.find(Task.class, 8L)));
assertTrue(result_3.contains(entityManager.find(Task.class, 10L)));
assertTrue(result_3.contains(entityManager.find(Task.class, 13L)));
assertTrue(result_3.contains(entityManager.find(Task.class, 14L)));
//overdue
List<Task> result_4 = taskService.loadAllTasks(username, TaskScope.OVERDUE);
assertEquals(2, result_4.size());
assertTrue(result_4.contains(entityManager.find(Task.class, 3L)));
assertTrue(result_4.contains(entityManager.find(Task.class, 5L)));
//upcoming
List<Task> result_5 = taskService.loadAllTasks(username, TaskScope.UPCOMING);
assertEquals(2, result_5.size());
assertTrue(result_5.contains(entityManager.find(Task.class, 7L)));
assertTrue(result_5.contains(entityManager.find(Task.class, 9L)));
//Active
List<Task> result_6 = taskService.loadAllTasks(username, TaskScope.ACTIVE);
assertEquals(6, result_6.size());
assertTrue(result_6.contains(entityManager.find(Task.class, 1L)));
assertTrue(result_6.contains(entityManager.find(Task.class, 3L)));
assertTrue(result_6.contains(entityManager.find(Task.class, 5L)));
assertTrue(result_6.contains(entityManager.find(Task.class, 11L)));
assertTrue(result_6.contains(entityManager.find(Task.class, 12L)));
}
}

View File

@ -0,0 +1,87 @@
package core.users;
import core.entities.User;
import core.repositories.UserRepository;
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.annotation.DirtiesContext;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.Optional;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@DataJpaTest
@ExtendWith(SpringExtension.class)
public class UserRepositoryTests {
@Autowired
private UserRepository userRepository;
@Autowired
private TestEntityManager testEntityManager;
@Test
@Sql("classpath:userRepisotoryTestEntries.sql")
void test_findByUsername() {
//Situation 1: User with name "FawKes100" is present
User referenceUser = testEntityManager.find(User.class, 1L);
Optional<User> findResult = userRepository.findByUsername(referenceUser.getUsername());
assertTrue(findResult.isPresent());
assertEquals(referenceUser,findResult.get());
//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"));
//Situation 3: User with this mail exists
assertTrue(userRepository.existsByEmail(referenceUser.getEmail()));
}
@Test
@Sql("classpath:userRepisotoryTestEntries.sql")
void test_existsByUsername() {
User referenceUser = testEntityManager.find(User.class, 1L);
//Situation 1: No such user
assertFalse(userRepository.existsByUsername("FawKes100"));
//Situation 3: User with this name exists
assertTrue(userRepository.existsByUsername(referenceUser.getUsername()));
}
@Test
@Sql("classpath:userRepisotoryTestEntries.sql")
void test_deleteUserByName() {
User referenceUser1 = testEntityManager.find(User.class, 1L);
User referenceUser2 = testEntityManager.find(User.class, 2L);
userRepository.deleteByUsername(referenceUser2.getUsername());
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(2, userRepository.countUsers());
}
}

View File

@ -0,0 +1,13 @@
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:file:~/testdb;MODE=LEGACY
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.flyway.enabled=false
spring.liquibase.enabled=false
demo.webapp.jwtSecret=demoWebappSecretKey
demo.webapp.jwtExpirationMS=86400000
spring.sql.init.mode=always
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true

View File

@ -0,0 +1,19 @@
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);
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (15, NULL, 0, NULL, 'Task 15', 2, false, 0);

View File

@ -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);

View File

@ -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');