-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Schedule tests and some fixes (change start and end time from …
…String to ZonedDateTime)
- Loading branch information
Showing
6 changed files
with
132 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
src/main/java/cat/udl/eps/softarch/demo/repository/ScheduleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package cat.udl.eps.softarch.demo.repository; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Schedule; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
@RepositoryRestResource | ||
public interface ScheduleRepository extends CrudRepository<Schedule, Long>, PagingAndSortingRepository<Schedule, Long> { | ||
|
||
|
||
Schedule findScheduleByStartTimeAndEndTime(@NotNull ZonedDateTime startTime, @NotNull ZonedDateTime endTime); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/cat/udl/eps/softarch/demo/steps/UpdateScheduleStepDefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
|
||
import cat.udl.eps.softarch.demo.domain.Schedule; | ||
import cat.udl.eps.softarch.demo.domain.Shelter; | ||
import cat.udl.eps.softarch.demo.repository.ScheduleRepository; | ||
import cat.udl.eps.softarch.demo.steps.AuthenticationStepDefs; | ||
import cat.udl.eps.softarch.demo.steps.StepDefs; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.When; | ||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.sql.Time; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
public class UpdateScheduleStepDefs { | ||
|
||
@Autowired | ||
private StepDefs stepDefs; | ||
@Autowired | ||
private ScheduleRepository scheduleRepository; | ||
|
||
/*@Autowired | ||
private ShelterRepository shelterRepository; falta aprovar PR Shelter Test*/ | ||
public static String newResourceUri; | ||
|
||
@Given("^There is a registered schedule with startTime \"([^\"]*)\" and endTime \"([^\"]*)\"$") | ||
public void thereIsARegisteredShelterWithNameEmailMobileAndIsActiveTrue(String startTime, String endTime) { | ||
Schedule schedule = new Schedule(); | ||
ZonedDateTime start = ZonedDateTime.parse(startTime); | ||
ZonedDateTime end = ZonedDateTime.parse(endTime); | ||
schedule.setStartTime(start); | ||
schedule.setEndTime(end); | ||
scheduleRepository.save(schedule); | ||
|
||
Schedule schedule_find = scheduleRepository.findScheduleByStartTimeAndEndTime(start, end); | ||
assertThat(schedule_find).isNotNull(); | ||
} | ||
|
||
@When("I update a schedule with startTime \"([^\"]*)\" and endTime \"([^\"]*)\" with new values startTime \"([^\"]*)\" and endTime \"([^\"]*)\"$") | ||
public void iUpdateAScheduleWithStartTimeAndEndTimeWithNewValuesStartTimeAndEndTime(String existingStartTime, String existingEndTime, String newStartTime, String newEndTime) throws Exception { | ||
|
||
ZonedDateTime existingStart = ZonedDateTime.parse(existingStartTime); | ||
ZonedDateTime existingEnd = ZonedDateTime.parse(existingEndTime); | ||
ZonedDateTime newStart = ZonedDateTime.parse(newStartTime); | ||
ZonedDateTime newEnd = ZonedDateTime.parse(newEndTime); | ||
|
||
|
||
|
||
Schedule schedule = scheduleRepository.findScheduleByStartTimeAndEndTime(existingStart, existingEnd); | ||
if (schedule != null) { | ||
if (newStart != null) { | ||
if (newStart.compareTo(newEnd) >= 0) schedule.setStartTime(null); | ||
else schedule.setStartTime(newStart); | ||
} | ||
if (newEnd != null) schedule.setEndTime(newEnd); | ||
} | ||
|
||
|
||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
patch("/schedules/{id}", (schedule != null) ? schedule.getId() : "999") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(schedule)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: Update Schedule | ||
In order to update a schedule | ||
I want to update a new schedule | ||
|
||
Background: | ||
Given There is a registered user with username "username" and password "password" and email "[email protected]" | ||
|
||
Scenario: Update a schedule with valid startTime and endTime | ||
Given I can login with username "username" and password "password" | ||
And There is a registered schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" | ||
When I update a schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" with new values startTime "2024-03-17T09:00:00+01:00" and endTime "2024-03-17T20:00:00+01:00" | ||
Then The response code is 200 | ||
|
||
Scenario: Try to update a schedule without logging in | ||
Given I'm not logged in | ||
And There is a registered schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" | ||
When I update a schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" with new values startTime "2024-03-17T09:00:00+01:00" and endTime "2024-03-17T20:00:00+01:00" | ||
Then The response code is 401 | ||
|
||
Scenario: Try to update a non-created schedule | ||
Given I can login with username "username" and password "password" | ||
When I update a schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" with new values startTime "2024-03-17T09:00:00+01:00" and endTime "2024-03-17T20:00:00+01:00" | ||
Then The response code is 404 | ||
|
||
|
||
Scenario: Update a schedule with startTime higher than endTime | ||
Given I can login with username "username" and password "password" | ||
And There is a registered schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" | ||
When I update a schedule with startTime "2024-03-17T08:00:00+01:00" and endTime "2024-03-17T21:00:00+01:00" with new values startTime "2024-03-17T10:00:00+01:00" and endTime "2024-03-17T08:00:00+01:00" | ||
Then The response code is 400 |