Остались тесты
This commit is contained in:
parent
c4eb1070e1
commit
9d53595074
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
9156
data.trace.db
Normal file
9156
data.trace.db
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,30 +9,58 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import com.example.demo.department.model.DepartmentEntity;
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
|
import com.example.demo.directions.model.DirectionsEntity;
|
||||||
|
import com.example.demo.news.model.NewsEntity;
|
||||||
import com.example.demo.entrysData.model.EntrysDataEntity;
|
import com.example.demo.entrysData.model.EntrysDataEntity;
|
||||||
|
import com.example.demo.department.service.DepartmentService;
|
||||||
|
import com.example.demo.directions.service.DirectionsService;
|
||||||
import com.example.demo.entrysData.service.EntrysDataService;
|
import com.example.demo.entrysData.service.EntrysDataService;
|
||||||
|
import com.example.demo.news.service.NewsService;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class DemoApplication implements CommandLineRunner {
|
public class DemoApplication implements CommandLineRunner {
|
||||||
private final Logger log = LoggerFactory.getLogger(DemoApplication.class);
|
private final Logger log = LoggerFactory.getLogger(DemoApplication.class);
|
||||||
|
|
||||||
private final EntrysDataService entrysDataService;
|
private final EntrysDataService entrysDataService;
|
||||||
|
private final DepartmentService departmentService;
|
||||||
|
private final NewsService newsService;
|
||||||
|
private final DirectionsService directionsService;
|
||||||
|
|
||||||
public DemoApplication(EntrysDataService entrysDataService) {
|
public DemoApplication(EntrysDataService entrysDataService, DepartmentService departmentService,
|
||||||
this.entrysDataService = entrysDataService;
|
NewsService newsService, DirectionsService directionsService) {
|
||||||
}
|
this.entrysDataService = entrysDataService;
|
||||||
|
this.departmentService = departmentService;
|
||||||
|
this.directionsService = directionsService;
|
||||||
|
this.newsService = newsService;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(DemoApplication.class, args);
|
SpringApplication.run(DemoApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
if (args.length > 0 && Objects.equals("--populate", args[0])) {
|
if (args.length > 0 && Objects.equals("--populate", args[0])) {
|
||||||
log.info("Start work");
|
log.info("Create departments");
|
||||||
entrysDataService.create(
|
final var dep1 = departmentService.create(new DepartmentEntity("ГУМ"));
|
||||||
new EntrysDataEntity(null, "login", "password", "role",
|
final var dep2 = departmentService.create(new DepartmentEntity("ИСТ"));
|
||||||
new DepartmentEntity(null, "test")));
|
final var dep3 = departmentService.create(new DepartmentEntity("ИЯ"));
|
||||||
}
|
|
||||||
}
|
log.info("Create entrysData");
|
||||||
|
entrysDataService.create(new EntrysDataEntity("login", "password", "user", dep2));
|
||||||
|
entrysDataService.create(new EntrysDataEntity("login1", "password", "user", dep3));
|
||||||
|
entrysDataService.create(new EntrysDataEntity("login2", "password", "user", dep1));
|
||||||
|
|
||||||
|
log.info("Create directions");
|
||||||
|
|
||||||
|
directionsService.create(new DirectionsEntity("09.02.23", "Программная инженерия", dep1, "Информатика"));
|
||||||
|
directionsService.create(new DirectionsEntity("09.03.24", "ИВТ", dep2, "Информатика, математика"));
|
||||||
|
directionsService.create(new DirectionsEntity("02.05.20", "ИСТ", dep3, "Информатика, иностранный языкы"));
|
||||||
|
|
||||||
|
log.info("Create news");
|
||||||
|
newsService.create(new NewsEntity("2024-04-15", "new1", "description1", dep2));
|
||||||
|
newsService.create(new NewsEntity("2024-02-23", "new2", "description2", dep3));
|
||||||
|
newsService.create(new NewsEntity("2024-03-17", "new3", "description3", dep1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,12 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.example.demo.core.configuration.Constants;
|
import com.example.demo.core.configuration.Constants;
|
||||||
import com.example.demo.department.service.DepartmentService;
|
import com.example.demo.department.service.DepartmentService;
|
||||||
|
import com.example.demo.directions.model.DirectionsEntity;
|
||||||
import com.example.demo.department.model.DepartmentEntity;
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
@ -5,10 +5,12 @@ import java.util.stream.StreamSupport;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
import com.example.demo.department.model.DepartmentEntity;
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
import com.example.demo.department.repository.DepartmentRepository;
|
import com.example.demo.department.repository.DepartmentRepository;
|
||||||
|
import com.example.demo.directions.model.DirectionsEntity;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DepartmentService {
|
public class DepartmentService {
|
||||||
|
@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
import com.example.demo.directions.model.DirectionsEntity;
|
import com.example.demo.directions.model.DirectionsEntity;
|
||||||
import com.example.demo.directions.repository.DirectionsRepository;
|
import com.example.demo.directions.repository.DirectionsRepository;
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ public class EntrysDataController {
|
|||||||
return toDto(entrysDataService.delete(id));
|
return toDto(entrysDataService.delete(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}/password")
|
||||||
public EntrysDataDto updatePassword(@PathVariable(name = "password") Long id,
|
public EntrysDataDto updatePassword(@PathVariable(name = "id") Long id,
|
||||||
@RequestParam(name = "newPassword") String newPas,
|
@RequestParam(name = "newPassword") String newPas,
|
||||||
@RequestParam(name = "oldPassword") String oldPas) {
|
@RequestParam(name = "oldPassword") String oldPas) {
|
||||||
return toDto(entrysDataService.updatePassword(id, newPas, oldPas));
|
return toDto(entrysDataService.updatePassword(id, newPas, oldPas));
|
||||||
|
@ -2,7 +2,6 @@ package com.example.demo.entrysData.api;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
@ -10,14 +9,14 @@ public class EntrysDataDto {
|
|||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
private Long id;
|
private Long id;
|
||||||
@NotNull
|
@NotNull
|
||||||
@Min(1)
|
|
||||||
private Long departmentId;
|
|
||||||
@NotBlank
|
|
||||||
private String login;
|
private String login;
|
||||||
@NotNull
|
@NotNull
|
||||||
private String role;
|
private String role;
|
||||||
@NotBlank
|
@NotNull
|
||||||
private String password;
|
private String password;
|
||||||
|
@NotNull
|
||||||
|
@Min(1)
|
||||||
|
private Long departmentId;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -41,7 +40,6 @@ public class EntrysDataDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRole(String role) {
|
public void setRole(String role) {
|
||||||
role = "user";
|
|
||||||
this.role = role;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ spring.datasource.password=password
|
|||||||
spring.datasource.driver-class-name=org.h2.Driver
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
spring.jpa.hibernate.ddl-auto=create
|
spring.jpa.hibernate.ddl-auto=create
|
||||||
spring.jpa.open-in-view=false
|
spring.jpa.open-in-view=false
|
||||||
# spring.jpa.show-sql=true
|
spring.jpa.show-sql=true
|
||||||
# spring.jpa.properties.hibernate.format_sql=true
|
spring.jpa.properties.hibernate.format_sql=true
|
||||||
|
|
||||||
# H2 console
|
# H2 console
|
||||||
spring.h2.console.enabled=true
|
spring.h2.console.enabled=true
|
@ -67,7 +67,7 @@ class DepartmentsTests {
|
|||||||
final DepartmentEntity newEntity = departmentService.update(department.getId(),
|
final DepartmentEntity newEntity = departmentService.update(department.getId(),
|
||||||
new DepartmentEntity(testName));
|
new DepartmentEntity(testName));
|
||||||
Assertions.assertEquals(3, departmentService.getAll().size());
|
Assertions.assertEquals(3, departmentService.getAll().size());
|
||||||
Assertions.assertEquals(newEntity, departmentService.get(3L));
|
Assertions.assertEquals(newEntity, departmentService.get(department.getId()));
|
||||||
|
|
||||||
Assertions.assertEquals(testName, newEntity.getName());
|
Assertions.assertEquals(testName, newEntity.getName());
|
||||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
Assertions.assertNotEquals(oldName, newEntity.getName());
|
||||||
@ -75,14 +75,12 @@ class DepartmentsTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
departmentService.delete(3L);
|
departmentService.delete(department.getId());
|
||||||
Assertions.assertEquals(2, departmentService.getAll().size());
|
Assertions.assertEquals(2, departmentService.getAll().size());
|
||||||
final DepartmentEntity last = departmentService.get(2L);
|
|
||||||
Assertions.assertEquals(2L, last.getId());
|
|
||||||
|
|
||||||
final DepartmentEntity newEntity = departmentService
|
final DepartmentEntity newEntity = departmentService
|
||||||
.create(new DepartmentEntity("testtt"));
|
.create(new DepartmentEntity(department.getName()));
|
||||||
Assertions.assertEquals(3, departmentService.getAll().size());
|
Assertions.assertEquals(3, departmentService.getAll().size());
|
||||||
Assertions.assertEquals(4L, newEntity.getId());
|
Assertions.assertNotEquals(department.getId(), newEntity.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package com.example.demo.java;
|
package com.example.demo.java;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
import com.example.demo.department.model.DepartmentEntity;
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
|
import com.example.demo.department.service.DepartmentService;
|
||||||
import com.example.demo.directions.model.DirectionsEntity;
|
import com.example.demo.directions.model.DirectionsEntity;
|
||||||
import com.example.demo.directions.service.DirectionsService;
|
import com.example.demo.directions.service.DirectionsService;
|
||||||
|
|
||||||
@ -18,32 +22,68 @@ import com.example.demo.directions.service.DirectionsService;
|
|||||||
class DirectionsTests {
|
class DirectionsTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DirectionsService directionsService;
|
private DirectionsService directionsService;
|
||||||
|
@Autowired
|
||||||
|
private DepartmentService departmentService;
|
||||||
|
|
||||||
@Test
|
private DepartmentEntity dep1;
|
||||||
void getTest() {
|
private DepartmentEntity dep2;
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> directionsService.get(0L));
|
|
||||||
|
private DirectionsEntity direct1;
|
||||||
|
private DirectionsEntity direct2;
|
||||||
|
private DirectionsEntity direct3;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void createData() {
|
||||||
|
removeData();
|
||||||
|
|
||||||
|
dep1 = departmentService.create(new DepartmentEntity("GUM"));
|
||||||
|
dep2 = departmentService.create(new DepartmentEntity("IST"));
|
||||||
|
|
||||||
|
direct1 = directionsService
|
||||||
|
.create(new DirectionsEntity("09.03.23", "Программная инженерия", dep2, "Инф"));
|
||||||
|
direct2 = directionsService.create(
|
||||||
|
new DirectionsEntity("09.04.24", "Про", dep1, "Рус"));
|
||||||
|
direct3 = directionsService.create(
|
||||||
|
new DirectionsEntity("09.05.25", "Прогdcя", dep1, "Мат"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void removeData() {
|
||||||
|
directionsService.getAll(0L).forEach(item -> directionsService.delete(item.getId()));
|
||||||
|
departmentService.getAll().forEach(item -> departmentService.delete(item.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void createTest() {
|
void createTest() {
|
||||||
directionsService.create(new DirectionsEntity(null, "09.03.01", "Программная инженерия",
|
|
||||||
new DepartmentEntity(null, "ИСТ"), "Информатика"));
|
|
||||||
directionsService.create(new DirectionsEntity(null, "09.03.02", "ИВТ", new DepartmentEntity(null,
|
|
||||||
"ИСТ"),
|
|
||||||
"Русский язык"));
|
|
||||||
final DirectionsEntity last = directionsService.create(new DirectionsEntity(null, "09.03.03",
|
|
||||||
"АиСД", new DepartmentEntity(null, "Гум"), "Математика"));
|
|
||||||
Assertions.assertEquals(3, directionsService.getAll(0L).size());
|
Assertions.assertEquals(3, directionsService.getAll(0L).size());
|
||||||
Assertions.assertEquals(last, directionsService.get(3L));
|
Assertions.assertEquals(2, directionsService.getAll(dep1.getId()).size());
|
||||||
|
Assertions.assertEquals(1, directionsService.getAll(dep2.getId()).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
|
void createNotUniqueTest() {
|
||||||
|
final DirectionsEntity nonUniquedirection = new DirectionsEntity("09.04.24", "Про", new DepartmentEntity("ИЯ"),
|
||||||
|
"Рус");
|
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, () -> directionsService.create(nonUniquedirection));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(3)
|
||||||
|
void createNullableTest() {
|
||||||
|
final DirectionsEntity nullabledirection = new DirectionsEntity(null, null, null, null);
|
||||||
|
Assertions.assertThrows(
|
||||||
|
DataIntegrityViolationException.class,
|
||||||
|
() -> directionsService.create(nullabledirection));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(4)
|
||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String testCode = "TESTCODE";
|
final String testCode = "TESTCODE";
|
||||||
final String testName = "TESTNAME";
|
final String testName = "TESTNAME";
|
||||||
final DepartmentEntity testDep = new DepartmentEntity(null, "TESTDEP");
|
final DepartmentEntity testDep = new DepartmentEntity("TESTDEP");
|
||||||
final String testThin = "TESTTHIN";
|
final String testThin = "TESTTHIN";
|
||||||
final DirectionsEntity entity = directionsService.get(3L);
|
final DirectionsEntity entity = directionsService.get(3L);
|
||||||
final String oldCode = entity.getCode();
|
final String oldCode = entity.getCode();
|
||||||
@ -51,7 +91,7 @@ class DirectionsTests {
|
|||||||
final DepartmentEntity oldDep = entity.getDepartment();
|
final DepartmentEntity oldDep = entity.getDepartment();
|
||||||
final String oldThin = entity.getThings();
|
final String oldThin = entity.getThings();
|
||||||
final DirectionsEntity newEntity = directionsService.update(3L,
|
final DirectionsEntity newEntity = directionsService.update(3L,
|
||||||
new DirectionsEntity(1L, testCode, testName, testDep, testThin));
|
new DirectionsEntity(testCode, testName, testDep, testThin));
|
||||||
Assertions.assertEquals(3, directionsService.getAll(0L).size());
|
Assertions.assertEquals(3, directionsService.getAll(0L).size());
|
||||||
Assertions.assertEquals(newEntity, directionsService.get(3L));
|
Assertions.assertEquals(newEntity, directionsService.get(3L));
|
||||||
Assertions.assertEquals(testCode, newEntity.getCode());
|
Assertions.assertEquals(testCode, newEntity.getCode());
|
||||||
@ -68,7 +108,7 @@ class DirectionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(5)
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
directionsService.delete(3L);
|
directionsService.delete(3L);
|
||||||
Assertions.assertEquals(2, directionsService.getAll(0L).size());
|
Assertions.assertEquals(2, directionsService.getAll(0L).size());
|
||||||
@ -76,8 +116,8 @@ class DirectionsTests {
|
|||||||
Assertions.assertEquals(2L, last.getId());
|
Assertions.assertEquals(2L, last.getId());
|
||||||
|
|
||||||
final DirectionsEntity newEntity = directionsService
|
final DirectionsEntity newEntity = directionsService
|
||||||
.create(new DirectionsEntity(null, "test1", "test2",
|
.create(new DirectionsEntity("test1", "test2",
|
||||||
new DepartmentEntity(null, "test3"), "test4"));
|
new DepartmentEntity("test3"), "test4"));
|
||||||
Assertions.assertEquals(3, directionsService.getAll(0L).size());
|
Assertions.assertEquals(3, directionsService.getAll(0L).size());
|
||||||
Assertions.assertEquals(4L, newEntity.getId());
|
Assertions.assertEquals(4L, newEntity.getId());
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.example.demo.java;
|
package com.example.demo.java;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
import org.junit.jupiter.api.Order;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
import com.example.demo.department.model.DepartmentEntity;
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
@ -19,36 +21,62 @@ class EntrysDataTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EntrysDataService entrysDataService;
|
private EntrysDataService entrysDataService;
|
||||||
|
|
||||||
|
private EntrysDataEntity entrysData;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void createData() {
|
||||||
|
removeData();
|
||||||
|
|
||||||
|
entrysData = entrysDataService
|
||||||
|
.create(new EntrysDataEntity("login1", "pass1", "user", new DepartmentEntity("ГУМ")));
|
||||||
|
entrysDataService.create(
|
||||||
|
new EntrysDataEntity("login2", "pass2", "user", new DepartmentEntity("IST")));
|
||||||
|
entrysDataService.create(
|
||||||
|
new EntrysDataEntity("login3", "pass3", "user", new DepartmentEntity("IYA")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void removeData() {
|
||||||
|
entrysDataService.getAll(0L).forEach(item -> entrysDataService.delete(item.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getTest() {
|
void getTest() {
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> entrysDataService.get(0L));
|
Assertions.assertThrows(NotFoundException.class, () -> entrysDataService.get(0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
|
||||||
void createTest() {
|
void createTest() {
|
||||||
entrysDataService
|
|
||||||
.create(new EntrysDataEntity(null, "dyctator", "12345", "user", new DepartmentEntity(null, "ИСТ")));
|
|
||||||
entrysDataService.create(new EntrysDataEntity(null, "user2", "12345", "user",
|
|
||||||
new DepartmentEntity(null, "ИСТ")));
|
|
||||||
final EntrysDataEntity last = entrysDataService.create(new EntrysDataEntity(null, "user3", "12345", "user",
|
|
||||||
new DepartmentEntity(null, "Гум")));
|
|
||||||
Assertions.assertEquals(3, entrysDataService.getAll(0L).size());
|
Assertions.assertEquals(3, entrysDataService.getAll(0L).size());
|
||||||
Assertions.assertEquals(last, entrysDataService.get(3L));
|
Assertions.assertEquals(entrysData, entrysDataService.get(entrysData.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNotUniqueTest() {
|
||||||
|
final EntrysDataEntity nonUniquedirection = new EntrysDataEntity("login4", "pass4", "user",
|
||||||
|
new DepartmentEntity("IYA"));
|
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, () -> entrysDataService.create(nonUniquedirection));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNullableTest() {
|
||||||
|
final EntrysDataEntity nullabledirection = new EntrysDataEntity(null, null, null, null);
|
||||||
|
Assertions.assertThrows(
|
||||||
|
DataIntegrityViolationException.class,
|
||||||
|
() -> entrysDataService.create(nullabledirection));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
|
||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String testLog = "TESTLOG";
|
final String testLog = "TESTLOG";
|
||||||
final String testPas = "TESTPAS";
|
final String testPas = "TESTPAS";
|
||||||
final DepartmentEntity testDep = new DepartmentEntity(null, "TESTDEP");
|
final DepartmentEntity testDep = new DepartmentEntity("TESTDEP");
|
||||||
final EntrysDataEntity entity = entrysDataService.get(3L);
|
final EntrysDataEntity entity = entrysDataService.get(3L);
|
||||||
final String oldLog = entity.getLogin();
|
final String oldLog = entity.getLogin();
|
||||||
final String oldPas = entity.getLogin();
|
final String oldPas = entity.getLogin();
|
||||||
final DepartmentEntity oldDep = entity.getDepartment();
|
final DepartmentEntity oldDep = entity.getDepartment();
|
||||||
final EntrysDataEntity newEntity = entrysDataService.update(3L,
|
final EntrysDataEntity newEntity = entrysDataService.update(3L,
|
||||||
new EntrysDataEntity(1L, testLog, testPas, entity.getRole(), testDep));
|
new EntrysDataEntity(testLog, testPas, entity.getRole(), testDep));
|
||||||
Assertions.assertEquals(3, entrysDataService.getAll(0L).size());
|
Assertions.assertEquals(3, entrysDataService.getAll(0L).size());
|
||||||
Assertions.assertEquals(newEntity, entrysDataService.get(3L));
|
Assertions.assertEquals(newEntity, entrysDataService.get(3L));
|
||||||
|
|
||||||
@ -63,7 +91,6 @@ class EntrysDataTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
entrysDataService.delete(3L);
|
entrysDataService.delete(3L);
|
||||||
Assertions.assertEquals(2, entrysDataService.getAll(0L).size());
|
Assertions.assertEquals(2, entrysDataService.getAll(0L).size());
|
||||||
@ -71,14 +98,13 @@ class EntrysDataTests {
|
|||||||
Assertions.assertEquals(2L, last.getId());
|
Assertions.assertEquals(2L, last.getId());
|
||||||
|
|
||||||
final EntrysDataEntity newEntity = entrysDataService
|
final EntrysDataEntity newEntity = entrysDataService
|
||||||
.create(new EntrysDataEntity(null, "user4", "12345", "user",
|
.create(new EntrysDataEntity("user4", "12345", "user",
|
||||||
new DepartmentEntity(null, "testtt")));
|
new DepartmentEntity("testtt")));
|
||||||
Assertions.assertEquals(3, entrysDataService.getAll(0L).size());
|
Assertions.assertEquals(3, entrysDataService.getAll(0L).size());
|
||||||
Assertions.assertEquals(4L, newEntity.getId());
|
Assertions.assertEquals(4L, newEntity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
|
||||||
void updatePasswordTest() {
|
void updatePasswordTest() {
|
||||||
final String newPas = "TESTPAS";
|
final String newPas = "TESTPAS";
|
||||||
final EntrysDataEntity entity = entrysDataService.get(1L);
|
final EntrysDataEntity entity = entrysDataService.get(1L);
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.example.demo.java;
|
package com.example.demo.java;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
import org.junit.jupiter.api.Order;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
import com.example.demo.department.model.DepartmentEntity;
|
import com.example.demo.department.model.DepartmentEntity;
|
||||||
@ -19,38 +21,64 @@ class NewsTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NewsService newsService;
|
private NewsService newsService;
|
||||||
|
|
||||||
|
private NewsEntity news;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void createData() {
|
||||||
|
removeData();
|
||||||
|
|
||||||
|
news = newsService
|
||||||
|
.create(new NewsEntity("2024-04-13", "new1", "description1", new DepartmentEntity("ГУМ")));
|
||||||
|
newsService.create(
|
||||||
|
new NewsEntity("2024-05-14", "new2", "description2", new DepartmentEntity("IST")));
|
||||||
|
newsService.create(
|
||||||
|
new NewsEntity("2024-02-10", "new3", "description3", new DepartmentEntity("JUV")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void removeData() {
|
||||||
|
newsService.getAll(0L).forEach(item -> newsService.delete(item.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getTest() {
|
void getTest() {
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> newsService.get(0L));
|
Assertions.assertThrows(NotFoundException.class, () -> newsService.get(0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
|
||||||
void createTest() {
|
void createTest() {
|
||||||
newsService.create(new NewsEntity(null, "2023-12-23", "Новость0",
|
|
||||||
"УлГТУ000", new DepartmentEntity(null, "ИСТ")));
|
|
||||||
newsService.create(new NewsEntity(null, "2023-12-24", "Новость1", "УлГТУ111",
|
|
||||||
new DepartmentEntity(null, "ИСТ")));
|
|
||||||
final NewsEntity last = newsService.create(new NewsEntity(null, "2023-12-25",
|
|
||||||
"Новость2", "УлГТУ222", new DepartmentEntity(null, "Гум")));
|
|
||||||
Assertions.assertEquals(3, newsService.getAll(0L).size());
|
Assertions.assertEquals(3, newsService.getAll(0L).size());
|
||||||
Assertions.assertEquals(last, newsService.get(3L));
|
Assertions.assertEquals(news, newsService.get(news.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNotUniqueTest() {
|
||||||
|
final NewsEntity nonUniquedirection = new NewsEntity("2024-02-10", "new4", "description4",
|
||||||
|
new DepartmentEntity("JUV"));
|
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, () -> newsService.create(nonUniquedirection));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNullableTest() {
|
||||||
|
final NewsEntity nullabledirection = new NewsEntity(null, null, null, null);
|
||||||
|
Assertions.assertThrows(
|
||||||
|
DataIntegrityViolationException.class,
|
||||||
|
() -> newsService.create(nullabledirection));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
|
||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String testDate = "TESTDATE";
|
final String testDate = "TESTDATE";
|
||||||
final String testName = "TESTNAME";
|
final String testName = "TESTNAME";
|
||||||
final String testDes = "TESTDES";
|
final String testDes = "TESTDES";
|
||||||
final DepartmentEntity testDep = new DepartmentEntity(null, "TESTDEP");
|
final DepartmentEntity testDep = new DepartmentEntity("TESTDEP");
|
||||||
final NewsEntity entity = newsService.get(3L);
|
final NewsEntity entity = newsService.get(3L);
|
||||||
final String oldDate = entity.getDate();
|
final String oldDate = entity.getDate();
|
||||||
final String oldName = entity.getName();
|
final String oldName = entity.getName();
|
||||||
final String oldDes = entity.getDescription();
|
final String oldDes = entity.getDescription();
|
||||||
final DepartmentEntity oldDep = entity.getDepartment();
|
final DepartmentEntity oldDep = entity.getDepartment();
|
||||||
final NewsEntity newEntity = newsService.update(3L,
|
final NewsEntity newEntity = newsService.update(3L,
|
||||||
new NewsEntity(1L, testDate, testName, testDes, testDep));
|
new NewsEntity(testDate, testName, testDes, testDep));
|
||||||
Assertions.assertEquals(3, newsService.getAll(0L).size());
|
Assertions.assertEquals(3, newsService.getAll(0L).size());
|
||||||
Assertions.assertEquals(newEntity, newsService.get(3L));
|
Assertions.assertEquals(newEntity, newsService.get(3L));
|
||||||
|
|
||||||
@ -68,7 +96,6 @@ class NewsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
newsService.delete(3L);
|
newsService.delete(3L);
|
||||||
Assertions.assertEquals(2, newsService.getAll(0L).size());
|
Assertions.assertEquals(2, newsService.getAll(0L).size());
|
||||||
@ -76,7 +103,7 @@ class NewsTests {
|
|||||||
Assertions.assertEquals(2L, last.getId());
|
Assertions.assertEquals(2L, last.getId());
|
||||||
|
|
||||||
final NewsEntity newEntity = newsService
|
final NewsEntity newEntity = newsService
|
||||||
.create(new NewsEntity(null, "test1", "test2", "test3", new DepartmentEntity(null, "testtt")));
|
.create(new NewsEntity("test1", "test2", "test3", new DepartmentEntity("testtt")));
|
||||||
Assertions.assertEquals(3, newsService.getAll(0L).size());
|
Assertions.assertEquals(3, newsService.getAll(0L).size());
|
||||||
Assertions.assertEquals(4L, newEntity.getId());
|
Assertions.assertEquals(4L, newEntity.getId());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user