Skip to content
Draft
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
4 changes: 3 additions & 1 deletion src/test/java/school/hei/haapi/integration/AttendanceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import school.hei.haapi.endpoint.rest.client.ApiException;
import school.hei.haapi.endpoint.rest.model.*;
import school.hei.haapi.integration.conf.FacadeITMockedThirdParties;
import school.hei.haapi.integration.conf.MockUtils;
import school.hei.haapi.integration.conf.TestUtils;
import school.hei.haapi.model.User;
import school.hei.haapi.repository.UserRepository;
Expand All @@ -39,6 +40,7 @@ class AttendanceIT extends FacadeITMockedThirdParties {
@Autowired CheckAttendanceTriggeredService checkAttendanceTriggeredService;
@Autowired UserRepository userRepository;
@Autowired UserService userService;
@Autowired MockUtils mockUtils;

private ApiClient anApiClient(String token) {
return TestUtils.anApiClient(token, localPort);
Expand Down Expand Up @@ -215,7 +217,7 @@ void default_attendance_unchecked() throws ApiException {
List<Event> events =
api.crupdateEvents(
List.of(
someCreatableEvent(
mockUtils.someCreatableEvent(
COURSE, TEACHER1_ID, Instant.now(), Instant.now().plusSeconds(10))),
null,
null,
Expand Down
18 changes: 14 additions & 4 deletions src/test/java/school/hei/haapi/integration/EventIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import static school.hei.haapi.integration.conf.TestUtils.group1;
import static school.hei.haapi.integration.conf.TestUtils.setUpCognito;
import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service;
import static school.hei.haapi.integration.conf.TestUtils.someCreatableEvent;
import static school.hei.haapi.integration.conf.TestUtils.someCreatableEventByManager1;
import static school.hei.haapi.integration.conf.TestUtils.student1AttendEvent2;
import static school.hei.haapi.integration.conf.TestUtils.student1MissEvent1;
import static school.hei.haapi.integration.conf.TestUtils.student2AttendEvent2;
Expand All @@ -51,6 +49,7 @@
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.testcontainers.junit.jupiter.Testcontainers;
import school.hei.haapi.endpoint.rest.api.EventsApi;
Expand All @@ -64,12 +63,14 @@
import school.hei.haapi.endpoint.rest.model.EventStats;
import school.hei.haapi.endpoint.rest.model.UpdateEventParticipant;
import school.hei.haapi.integration.conf.FacadeITMockedThirdParties;
import school.hei.haapi.integration.conf.MockUtils;
import school.hei.haapi.integration.conf.TestUtils;

@Slf4j
@Testcontainers
@AutoConfigureMockMvc
public class EventIT extends FacadeITMockedThirdParties {
@Autowired MockUtils mockUtils;

private ApiClient anApiClient(String token) {
return TestUtils.anApiClient(token, localPort);
Expand Down Expand Up @@ -348,7 +349,16 @@ void delete_event_student_ko_and_manager_ko() throws ApiException {
EventsApi managerApi = new EventsApi(anApiClient(MANAGER1_TOKEN));
List<Event> events =
managerApi.crupdateEvents(
List.of(someCreatableEventByManager1(INTEGRATION)), MONDAY, 1, "09:00", "12:00");
List.of(
mockUtils.someCreatableEvent(
INTEGRATION,
MANAGER_ID,
Instant.parse("2023-12-08T08:00:00.00Z"),
Instant.parse("2023-12-08T10:00:00.00Z"))),
MONDAY,
1,
"09:00",
"12:00");

assertThrowsForbiddenException(() -> studentApi.deleteEventById(events.getFirst().getId()));

Expand Down Expand Up @@ -380,7 +390,7 @@ void event_stats_are_exact() throws ApiException {
List<Event> createdEvents =
managerApi.crupdateEvents(
List.of(
someCreatableEvent(
mockUtils.someCreatableEvent(
COURSE, MANAGER_ID, Instant.now(), Instant.now().plus(Duration.of(4, HOURS)))),
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;
import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION;
import static school.hei.haapi.model.User.Role.STUDENT;
import static school.hei.haapi.model.User.Status.ENABLED;
Expand All @@ -15,6 +16,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext;
import org.testcontainers.junit.jupiter.Testcontainers;
import school.hei.haapi.endpoint.event.model.LateFeeVerified;
import school.hei.haapi.integration.conf.FacadeITMockedThirdParties;
Expand All @@ -26,7 +28,8 @@

@Testcontainers
@AutoConfigureMockMvc
public class LateFeeVerifiedServiceIT extends FacadeITMockedThirdParties {
@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)
class LateFeeVerifiedServiceIT extends FacadeITMockedThirdParties {
@Autowired private LateFeeVerifiedService subject;
@Autowired private UserRepository userRepository;
@MockBean private Mailer mailer;
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/school/hei/haapi/integration/OrganizerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException;
import static school.hei.haapi.integration.conf.TestUtils.setUpCognito;
import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge;
import static school.hei.haapi.integration.conf.TestUtils.someCreatableEvent;
import static school.hei.haapi.integration.conf.TestUtils.student1MissEvent1;
import static school.hei.haapi.integration.conf.TestUtils.student3AttendEvent1;
import static school.hei.haapi.integration.conf.TestUtils.uploadProfilePicture;
Expand Down Expand Up @@ -47,6 +46,7 @@
import school.hei.haapi.endpoint.rest.model.EventType;
import school.hei.haapi.endpoint.rest.model.Organizer;
import school.hei.haapi.integration.conf.FacadeITMockedThirdParties;
import school.hei.haapi.integration.conf.MockUtils;
import school.hei.haapi.integration.conf.TestUtils;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;

Expand All @@ -56,6 +56,7 @@
public class OrganizerIT extends FacadeITMockedThirdParties {
@MockBean private EventBridgeClient eventBridgeClientMock;
@Autowired ObjectMapper objectMapper;
@Autowired MockUtils mockUtils;

private ApiClient anApiClient(String token) {
return TestUtils.anApiClient(token, localPort);
Expand Down Expand Up @@ -148,7 +149,7 @@ void manipulate_events_ok() throws ApiException {
EventsApi api = new EventsApi(organizerClient);

CreateEvent createEvent =
someCreatableEvent(
mockUtils.someCreatableEvent(
EventType.EXAM, ORGANIZER1_ID, Instant.now(), Instant.now().plus(1, HOURS));

List<Event> events = api.crupdateEvents(List.of(createEvent), null, null, null, null);
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/school/hei/haapi/integration/PaginationIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -32,20 +33,22 @@
import school.hei.haapi.endpoint.rest.model.Payment;
import school.hei.haapi.endpoint.rest.model.Student;
import school.hei.haapi.integration.conf.FacadeITMockedThirdParties;
import school.hei.haapi.integration.conf.MockUtils;
import school.hei.haapi.integration.conf.TestUtils;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;

@Testcontainers
@AutoConfigureMockMvc
class PaginationIT extends FacadeITMockedThirdParties {
@MockBean private EventBridgeClient eventBridgeClientMock;
@Autowired private MockUtils mockUtils;

private ApiClient anApiClient(String token) {
return TestUtils.anApiClient(token, localPort);
}

@BeforeEach
public void setUp() throws ApiException {
void setUp() {
setUpCognito(cognitoComponentMock);
setUpEventBridge(eventBridgeClientMock);
setUpS3Service(fileService, student1());
Expand All @@ -56,7 +59,7 @@ public void setUp() throws ApiException {
private void someCreatableStudentList(int nbOfNewStudents) throws ApiException {
List<CrupdateStudent> newStudents = new ArrayList<>();
for (int i = 0; i < nbOfNewStudents; i++) {
newStudents.add(StudentIT.someCreatableStudent());
newStudents.add(mockUtils.someCreatableStudent());
}
ApiClient manager1Client = anApiClient(MANAGER1_TOKEN);
UsersApi api = new UsersApi(manager1Client);
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/school/hei/haapi/integration/PaymentIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static school.hei.haapi.endpoint.rest.model.EnableStatus.ENABLED;
import static school.hei.haapi.endpoint.rest.model.EnableStatus.SUSPENDED;
import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.PAID;
import static school.hei.haapi.integration.StudentIT.someCreatableStudent;
import static school.hei.haapi.integration.StudentIT.student1;
import static school.hei.haapi.integration.conf.TestUtils.FEE1_ID;
import static school.hei.haapi.integration.conf.TestUtils.FEE3_ID;
Expand Down Expand Up @@ -53,6 +52,7 @@
import school.hei.haapi.endpoint.rest.model.Payment;
import school.hei.haapi.endpoint.rest.model.Student;
import school.hei.haapi.integration.conf.FacadeITMockedThirdParties;
import school.hei.haapi.integration.conf.MockUtils;
import school.hei.haapi.integration.conf.TestUtils;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;

Expand All @@ -61,6 +61,7 @@
class PaymentIT extends FacadeITMockedThirdParties {
@Autowired EntityManager entityManager;
@MockBean private EventBridgeClient eventBridgeClientMock;
@Autowired private MockUtils mockUtils;

private ApiClient anApiClient(String token) {
return TestUtils.anApiClient(token, localPort);
Expand Down Expand Up @@ -278,7 +279,7 @@ void student_is_now_enabled_after_paying_fee() throws ApiException {
ApiClient manager1Client = anApiClient(MANAGER1_TOKEN);
PayingApi payingApi = new PayingApi(manager1Client);
UsersApi usersApi = new UsersApi(manager1Client);
CrupdateStudent subject = someCreatableStudent();
CrupdateStudent subject = mockUtils.someCreatableStudent();
subject.setStatus(ENABLED);

// Assert before all that the actual student is SUSPENDED ...
Expand Down Expand Up @@ -365,7 +366,7 @@ void manager_write_with_some_bad_fields_ko() {
}

@Test
void manager_write_with_non_given_creation_datetime_ko() throws ApiException {
void manager_write_with_non_given_creation_datetime_ko() {
ApiClient manager1Client = anApiClient(MANAGER1_TOKEN);
PayingApi api = new PayingApi(manager1Client);

Expand All @@ -376,7 +377,7 @@ void manager_write_with_non_given_creation_datetime_ko() throws ApiException {
}

@Test
void manager_write_with_creation_datetime_after_current_time_ko() throws ApiException {
void manager_write_with_creation_datetime_after_current_time_ko() {
ApiClient manager1Client = anApiClient(MANAGER1_TOKEN);
PayingApi api = new PayingApi(manager1Client);

Expand Down
Loading