tests #43

Merged
sebastian merged 41 commits from tests into master 2023-11-11 11:20:50 +01:00
6 changed files with 133 additions and 33 deletions
Showing only changes of commit 2c23952a5e - Show all commits

View File

@ -5,12 +5,13 @@
</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="Fix marking finished task as overdue">
<change afterPath="$PROJECT_DIR$/src/test/java/core/users/UserRepositoryTests.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/resources/application.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" 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$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" 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$/src/main/java/core/DemoApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/DemoApplication.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$/src/main/java/core/entities/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/User.java" 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" />
@ -46,35 +47,52 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RequestMappingsPanelOrder0&quot;: &quot;0&quot;, "RequestMappingsPanelOrder0": "0",
&quot;RequestMappingsPanelOrder1&quot;: &quot;1&quot;, "RequestMappingsPanelOrder1": "1",
&quot;RequestMappingsPanelWidth0&quot;: &quot;75&quot;, "RequestMappingsPanelWidth0": "75",
&quot;RequestMappingsPanelWidth1&quot;: &quot;75&quot;, "RequestMappingsPanelWidth1": "75",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, "WebServerToolWindowFactoryState": "false",
&quot;extract.method.default.visibility&quot;: &quot;private&quot;, "extract.method.default.visibility": "private",
&quot;git-widget-placeholder&quot;: &quot;issue-11-angular-update&quot;, "git-widget-placeholder": "tests",
&quot;last_directory_selection&quot;: &quot;D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;last_opened_file_path&quot;: &quot;D:/Programmierprojekte/Dicewars/client&quot;, "last_directory_selection": "D:/Programmierprojekte/TimeManager/backend/src/main/java/core/api/models/timemanager",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "last_opened_file_path": "D:/Programmierprojekte/Dicewars/client",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;settings.editor.selected.configurable&quot;: &quot;swagger&quot;, "nodejs_package_manager_path": "npm",
&quot;ts.external.directory.path&quot;: &quot;/snap/intellij-idea-ultimate/459/plugins/javascript-impl/jsLanguageServicesImpl/external&quot;, "settings.editor.selected.configurable": "swagger",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "ts.external.directory.path": "/snap/intellij-idea-ultimate/459/plugins/javascript-impl/jsLanguageServicesImpl/external",
"vue.rearranger.settings.migration": "true"
}, },
&quot;keyToStringList&quot;: { "keyToStringList": {
&quot;DatabaseDriversLRU&quot;: [ "DatabaseDriversLRU": [
&quot;mariadb&quot; "mariadb"
] ]
} }
}</component> }]]></component>
<component name="RunManager"> <component name="RunManager" selected="JUnit.UserRepositoryTests.test_findByUsername">
<configuration name="UserRepositoryTests.test_findByUsername" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.users.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.users" />
<option name="MAIN_CLASS_NAME" value="core.users.UserRepositoryTests" />
<option name="METHOD_NAME" value="test_findByUsername" />
<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 +100,11 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.UserRepositoryTests.test_findByUsername" />
</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 +134,7 @@
<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="1800000" />
</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" />
@ -325,6 +349,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>56</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>
</component> </component>

View File

@ -54,6 +54,12 @@
<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>1.3.176</version>
<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

@ -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(id, user.id) && 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(id, username, email, password, roles);
}
} }

View File

@ -0,0 +1,37 @@
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.junit.jupiter.SpringExtension;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
@DataJpaTest
@DirtiesContext
@ExtendWith(SpringExtension.class)
public class UserRepositoryTests {
@Autowired
private UserRepository userRepository;
@Autowired
private TestEntityManager testEntityManager;
@Test
void test_findByUsername() {
assertTrue(userRepository.findByUsername("FawKes100").isEmpty());
userRepository.save(new User(1L,"FawKes100", "mail@fawkes100.de", "123456"));
Optional<User> findResult = userRepository.findByUsername("FawKes100");
assertTrue(findResult.isPresent());
assertEquals(new User(1L, "FawKes100", "mail@fawkes100.de", "123456"),findResult.get());
}
}

View File

@ -0,0 +1,7 @@
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:file:~/testdb;MODE=LEGACY
spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.flyway.enabled=false
spring.liquibase.enabled=false
hibernate.dialect=org.hibernate.dialect.H2Dialect