Initialize Testing of Testservice
Some checks failed
Java CI with Maven / build (push) Failing after 1m2s
Some checks failed
Java CI with Maven / build (push) Failing after 1m2s
This commit is contained in:
parent
2f7fb3e2b4
commit
21015ff06d
@ -4,11 +4,11 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="FindAlltasksByUser Test">
|
||||
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Test TaskRepository">
|
||||
<change afterPath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupServiceTest.java" 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" />
|
||||
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/test/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/resources/application.properties" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -87,39 +87,7 @@
|
||||
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="JUnit.TaskRepositoryTest.findAllActive">
|
||||
<configuration name="TaskRepositoryTest.deleteAllByTaskgroup" 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="deleteAllByTaskgroup" />
|
||||
<option name="TEST_OBJECT" value="method" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TaskRepositoryTest.deleteByTaskID" 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="deleteByTaskID" />
|
||||
<option name="TEST_OBJECT" value="method" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<component name="RunManager" selected="JUnit.TaskgroupServiceTest.getTaskgroupByIDAndUsername">
|
||||
<configuration name="TaskRepositoryTest.findAllActive" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="demo" />
|
||||
<extension name="coverage">
|
||||
@ -168,6 +136,37 @@
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TaskgroupServiceTest" 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.TaskgroupServiceTest" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TaskgroupServiceTest.getTaskgroupByIDAndUsername" 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.TaskgroupServiceTest" />
|
||||
<option name="METHOD_NAME" value="getTaskgroupByIDAndUsername" />
|
||||
<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">
|
||||
<module name="demo" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="core.DemoApplication" />
|
||||
@ -177,11 +176,11 @@
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="JUnit.TaskgroupServiceTest.getTaskgroupByIDAndUsername" />
|
||||
<item itemvalue="JUnit.TaskgroupServiceTest" />
|
||||
<item itemvalue="JUnit.TaskRepositoryTest.findAllActive" />
|
||||
<item itemvalue="JUnit.TaskRepositoryTest.findAllUpcoming" />
|
||||
<item itemvalue="JUnit.TaskRepositoryTest.findAllOverdue" />
|
||||
<item itemvalue="JUnit.TaskRepositoryTest.deleteByTaskID" />
|
||||
<item itemvalue="JUnit.TaskRepositoryTest.deleteAllByTaskgroup" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
@ -218,7 +217,7 @@
|
||||
<workItem from="1699460935890" duration="5000" />
|
||||
<workItem from="1699466564154" duration="6646000" />
|
||||
<workItem from="1699473376129" duration="1423000" />
|
||||
<workItem from="1699639316405" duration="1997000" />
|
||||
<workItem from="1699639316405" duration="5468000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
||||
<option name="closed" value="true" />
|
||||
@ -428,14 +427,21 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1699474949938</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="27" />
|
||||
<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>
|
||||
<option name="localTasksCounter" value="28" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<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)" />
|
||||
@ -460,7 +466,8 @@
|
||||
<MESSAGE value="TaskgroupRepsitoryTest" />
|
||||
<MESSAGE value="TaskgroupRepsitoryTest (+Delete)" />
|
||||
<MESSAGE value="FindAlltasksByUser Test" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="FindAlltasksByUser Test" />
|
||||
<MESSAGE value="Test TaskRepository" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Test TaskRepository" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
@ -491,14 +498,9 @@
|
||||
<option name="timeStamp" value="12" />
|
||||
</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" />
|
||||
<url>file://$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupServiceTest.java</url>
|
||||
<line>50</line>
|
||||
<option name="timeStamp" value="21" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
|
@ -57,7 +57,12 @@
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.176</version>
|
||||
<version>2.2.224</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -0,0 +1,68 @@
|
||||
package core.taskgroups;
|
||||
|
||||
import core.entities.User;
|
||||
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.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 java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
public class TaskgroupServiceTest {
|
||||
|
||||
@Autowired
|
||||
private TaskgroupRepository taskgroupRepository;
|
||||
@Autowired
|
||||
private TaskgroupService taskgroupService;
|
||||
|
||||
private static final String username = "Testuser1";
|
||||
@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());
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,12 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user