-
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.
- Loading branch information
Showing
41 changed files
with
1,543 additions
and
90 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
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
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/cat/udl/eps/softarch/demo/repository/PermissionRepository.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,8 @@ | ||
package cat.udl.eps.softarch.demo.repository; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Permission; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
|
||
public interface PermissionRepository extends CrudRepository<Permission, String>, PagingAndSortingRepository<Permission, String> { | ||
} |
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
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); | ||
} |
102 changes: 102 additions & 0 deletions
102
src/test/java/cat/udl/eps/softarch/demo/steps/CreateLocationStepsDefs.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,102 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Location; | ||
import cat.udl.eps.softarch.demo.repository.LocationRepository; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.When; | ||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
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.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
|
||
public class CreateLocationStepsDefs { | ||
|
||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private LocationRepository locationRepository; | ||
|
||
public static String newResourceUri; | ||
|
||
@When("There is already a Location with the following details:$") | ||
public void thereIsAlreadyALocationWithTheFollowingDetails(Map<String, String> locationDetails) throws Throwable{ | ||
Location location = new Location(); | ||
location.setAddress(locationDetails.get("address")); | ||
location.setProvince(locationDetails.get("province")); | ||
location.setCity(locationDetails.get("city")); | ||
location.setPostalCode(Integer.parseInt(locationDetails.get("postalCode"))); | ||
locationRepository.save(location); | ||
} | ||
@When("I create a new Location with the following details:$") | ||
public void iCreateANewLocationWithTheFollowingDetails(Map<String, String> locationDetails) throws Throwable { | ||
Location existingLocation = locationRepository.findLocationByAddressAndProvinceAndCityAndPostalCode( | ||
locationDetails.get("address"), | ||
locationDetails.get("province"), | ||
locationDetails.get("city"), | ||
Integer.parseInt(locationDetails.get("postalCode")) | ||
); | ||
|
||
if (existingLocation == null) { | ||
|
||
Location location = new Location(); | ||
location.setAddress(locationDetails.get("address")); | ||
location.setProvince(locationDetails.get("province")); | ||
location.setCity(locationDetails.get("city")); | ||
location.setPostalCode(Integer.parseInt(locationDetails.get("postalCode"))); | ||
|
||
// Verify and assign latitude and longitude if exists | ||
if (locationDetails.containsKey("longitude") && locationDetails.get("longitude") != null) { | ||
location.setLongitude(Float.parseFloat(locationDetails.get("longitude"))); | ||
} | ||
|
||
|
||
if (locationDetails.containsKey("latitude") && locationDetails.get("latitude") != null) { | ||
location.setLatitude(Float.parseFloat(locationDetails.get("latitude"))); | ||
} | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
post("/locations") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(location)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
newResourceUri = stepDefs.result.andReturn().getResponse().getHeader("Location"); | ||
|
||
} else { | ||
assertThat(existingLocation).isNotNull(); | ||
} | ||
} | ||
|
||
|
||
|
||
@And("There is (\\d+) Location created$") | ||
public void thereIsLocationCreated(int locationCreatedNum) { | ||
Assert.assertEquals(locationCreatedNum, locationRepository.count()); | ||
} | ||
|
||
@And("There is only (\\d+) Location with the details:$") | ||
public void thereIsOnlyLocationWithTheDeatils(int locationCreatedNum, Map<String, String> locationDetails) { | ||
Assert.assertEquals(locationCreatedNum, locationRepository.count()); | ||
} | ||
|
||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/cat/udl/eps/softarch/demo/steps/DeleteLocationStepsDefs.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,63 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
|
||
import cat.udl.eps.softarch.demo.domain.Location; | ||
import cat.udl.eps.softarch.demo.repository.LocationRepository; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.When; | ||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
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 DeleteLocationStepsDefs { | ||
|
||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private LocationRepository locationRepository; | ||
|
||
public static String newResourceUri; | ||
@When("I delete the location with the details:$") | ||
public void iDeleteTheLocationWithTheDetails(Map<String, String> locationDetails) throws Throwable{ | ||
Location existingLocation = locationRepository.findLocationByAddressAndProvinceAndCityAndPostalCode( | ||
locationDetails.get("address"), | ||
locationDetails.get("province"), | ||
locationDetails.get("city"), | ||
Integer.parseInt(locationDetails.get("postalCode")) | ||
); | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
delete("/locations/{id}", (existingLocation != null) ? existingLocation.getId() : "999") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(existingLocation)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
|
||
@And("There is (\\d+) Location with the details:$") | ||
public void thereIsOnlyLocationWithTheDeatils(int locationNum, Map<String, String> locationDetails) { | ||
Assert.assertEquals(locationNum, locationRepository.count()); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.