/
koskv
/
TeamSync-Tests
Обзор
Документация
Войти
/
koskv
/
TeamSync-Tests
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/test/java/TeamSyncTest/api/employee/EmployeeApiController_Test.java
81 строка
3 KB
Koskv
REF: Правка TASK api тестов
20 ноя 2025, 23:19
20 ноя 2025, 23:19
a6f564b
Код
Авторство
О чём код?
package TeamSyncTest.api.employee; import TeamSyncTest.utils.api.ApiMethodsNew; import io.qameta.allure.Epic; import io.qameta.allure.Feature; import io.qameta.allure.Owner; import io.qameta.allure.Severity; import io.qameta.allure.SeverityLevel; import io.qameta.allure.Story; import utils.api.BaseIntegrationTest; import TeamSyncTest.constants.Endpoints; import TeamSyncTest.constants.JsonPath; import TeamSyncTest.models.EmployeeDto; import TeamSyncTest.utils.api.ApiMethods_old; import TeamSyncTest.utils.api.CreateFromJson; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import static TeamSyncTest.constants.HttpStatus.NO_CONTENT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @Tag("api") @Epic("API Tests") @Feature("Employee Management - CRUD Operations") @Owner("TeamSync: AQA team") @Severity(SeverityLevel.CRITICAL) @Slf4j @TestInstance(TestInstance.Lifecycle.PER_METHOD) public class EmployeeApiController_Test extends BaseIntegrationTest { private Long createdEmployeeId; @Test @Story("Create employee: fields test") @DisplayName("Создание сотрудника - Positive") void createEmployee_ShouldReturnCreatedEmployee_positive() throws IOException { // Arrange EmployeeDto req = createEmployeeBody(); // Убедимся, что positionId установлен (важно для валидации) assertNotNull(req.getPositionId(), "Position ID must not be null in test JSON"); // Act EmployeeDto response = apiMethodsNew.create(EmployeeDto.class, req, Endpoints.EMPLOYEE_API, authToken); this.createdEmployeeId = response.getId(); // для удаления записи после теста // Assert log.info("Response: {}", response); assertNotNull(response.getId(), "Employee ID should be generated"); assertEquals(req.getPositionId(), response.getPositionId(), "Position ID should match"); assertEquals(req.getFullName(), response.getFullName(), "Employee FullName should match"); } //---------------------------------------------------------- @BeforeEach public void beforeEach() { this.createdEmployeeId = null; } @AfterEach public void cleanup() { if (createdEmployeeId != null) { System.out.println("Try to delete Employee with ID: " + createdEmployeeId); apiMethodsNew.deleteWithResponse(Endpoints.EMPLOYEE_API, createdEmployeeId, authToken); } } // Настройка тела запроса через дженерик public EmployeeDto createEmployeeBody() throws IOException { return createRequestBody(JsonPath.EMPLOYEE_JSON, EmployeeDto.class); } }