Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
database:
image: postgres:latest
ports:
- 6543:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 8258
POSTGRES_DB: postgres
28,828 changes: 28,828 additions & 0 deletions myApp.log

Large diffs are not rendered by default.

28,828 changes: 28,828 additions & 0 deletions myAppError.log

Large diffs are not rendered by default.

62 changes: 60 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<properties>
<java.version>17</java.version>
</properties>





<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -67,19 +72,72 @@
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<!--
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
-->

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>

</dependencies>




<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>4.0.0</version>

<executions>
<execution>
<id>up</id>
<phase>test-compile</phase>
<goals>
<goal>up</goal>
</goals>
<configuration>

<composeFile>${project.basedir}/docker-compose.yaml</composeFile>
<detachedMode>true</detachedMode>
</configuration>
</execution>

<execution>
<id>down</id>
<phase>post-integration-test</phase>
<goals>
<goal>down</goal>
</goals>
<configuration>

<composeFile>${project.basedir}/docker-compose.yaml</composeFile>
<detachedMode>true</detachedMode>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
Expand All @@ -28,6 +29,7 @@
@Configuration
@RequiredArgsConstructor
public class SecurityConfig {

@Autowired
// Внедряем зависимость UserDetailsService
// для работы с данными пользователя.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/weblibrary/model/Position.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class Position implements Serializable {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
// @GeneratedValue(strategy = GenerationType.AUTO)
private Integer positionId;
private String positionName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AuthUser {
// Создаем поле id для хранения идентификатора пользователя.
@Id
// Используем AUTO-генерацию идентификаторов.
@GeneratedValue(strategy = GenerationType.AUTO)
// @GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

// Создаем поле username для хранения имени пользователя.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/weblibrary/security/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Role {
// Создаем поле id-идентификатор.
@Id
// Используем AUTO-генерацию идентификаторов.
@GeneratedValue(strategy = GenerationType.AUTO)
// @GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String role;
// @ManyToOne(fetch = FetchType.LAZY)
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/example/weblibrary/service/MockitoTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

@SpringBootTest
@AutoConfigureMockMvc
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class EmployeeTest {

@Autowired
Expand All @@ -36,6 +35,7 @@ public class EmployeeTest {
@Test
@WithMockUser(username = "admin", roles = "ADMIN", password = "1234")
void givenNoBody_whenEmptyJsonArray() throws Exception {
employeeRepository.deleteAll();
// Имитируем GET-запрос к "/user"
mockMvc.perform(get("/admin/employees/all"))
// Проверяем, что статус ответа — 200 (OK)
Expand All @@ -50,6 +50,7 @@ void givenNoBody_whenEmptyJsonArray() throws Exception {
@Test
@WithMockUser(username = "admin", roles = "ADMIN", password = "1234")
void getEmployeesTest() throws Exception {
employeeRepository.deleteAll();
createEmployees();
mockMvc.perform(get("/admin/employees/all"))
.andExpect(status().isOk())
Expand All @@ -64,6 +65,7 @@ void getEmployeesTest() throws Exception {
@Test
@WithMockUser(username = "admin", roles = "USER", password = "1234")
void getEmployeeWithHighestSalary() throws Exception {
employeeRepository.deleteAll();
createEmployees();
mockMvc.perform(get("/employees/withHighestSalary"))
.andExpect(status().isOk())
Expand All @@ -73,6 +75,7 @@ void getEmployeeWithHighestSalary() throws Exception {
@Test
@WithMockUser(username = "admin", roles = "USER", password = "1234")
void getEmployeeWithsalaryHigherThan_Test() throws Exception {
employeeRepository.deleteAll();
createEmployees();
mockMvc.perform(get("/employees/salaryHigherThan?salary=15000"))
.andExpect(status().isOk())
Expand Down Expand Up @@ -107,16 +110,18 @@ void addEmployeeFromFile() throws Exception {
.andExpect(status().isOk());
mockMvc.perform(get("/admin/employees/all"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[3].name").value("Следующий"));
.andExpect(jsonPath("$.length()").value(4));
}


@Test
@WithMockUser(username = "admin", roles = "ADMIN", password = "1234")
void deleteEmployee_Test() throws Exception {
employeeRepository.deleteAll();
createEmployees();
mockMvc.perform(delete("/admin/employees/3"))
.andExpect(status().isOk());

mockMvc.perform(get("/admin/employees/all"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
Expand All @@ -128,6 +133,7 @@ void deleteEmployee_Test() throws Exception {
@Test
@WithMockUser(username = "admin", roles = "USER", password = "1234")
void getEmployeeByPage() throws Exception {
employeeRepository.deleteAll();
createEmployees();
mockMvc.perform(get("/employees/page?page=0")
.param("page", String.valueOf(0)))
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/com/example/weblibrary/controller/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.example.weblibrary.model.Employee;
import com.example.weblibrary.repository.EmployeeRepository;
import com.example.weblibrary.repository.ReportRepository;
import com.example.weblibrary.service.ReportService;
import com.example.weblibrary.model.Position;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -24,25 +25,29 @@

@SpringBootTest
@AutoConfigureMockMvc
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)

public class ReportTest {
@Autowired
MockMvc mockMvc;

@Autowired
private EmployeeRepository employeeRepository;

@Autowired
private ReportRepository reportRepository;


@Autowired
private ReportService reportService;

@Test
@WithMockUser(username = "admin", roles = "USER", password = "1234")
void getReport() throws Exception {
reportRepository.deleteAll();
employeeRepository.deleteAll();
createEmployees();
mockMvc.perform(post("/report"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").value(1));
.andExpect(status().isOk());
}

@Test
Expand Down
8 changes: 6 additions & 2 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
spring.datasource.url=jdbc:h2:mem:test;NON_KEYWORDS=USER
#spring.datasource.url=jdbc:h2:mem:test;NON_KEYWORDS=USER
spring.liquibase.change-log=classpath:../classes/liquibase/changelog-master.yml
app.env = test
app.env = test

spring.datasource.url=jdbc:postgresql://localhost:6543/postgres
spring.datasource.username=postgres
spring.datasource.password=8258
9 changes: 9 additions & 0 deletions target/classes/application-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=8258
spring.datasource.driver = org.postgresql.Driver
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
app.env = test
10 changes: 10 additions & 0 deletions target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=8258
spring.datasource.driver = org.postgresql.Driver
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
app.env = dev
spring.liquibase.change-log=classpath:liquibase/changelog-master.yml
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading