-
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.
Added the Location features for getting an existing and non-existing …
…location
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/test/java/cat/udl/eps/softarch/demo/steps/GetLocationStepsDefs.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,58 @@ | ||
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 static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
|
||
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 GetLocationStepsDefs { | ||
|
||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private LocationRepository locationRepository; | ||
|
||
public static String newResourceUri; | ||
@When("I retrieve the location with the details:$") | ||
public void iRetrieveTheLocationWithTheDetails(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( | ||
get("/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()); | ||
} | ||
|
||
} |
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,31 @@ | ||
Feature: Get Location | ||
In order to retrieve Location information | ||
As a user with appropriate permissions | ||
I want to be able to get the Location details of a shelter | ||
|
||
Background: | ||
Given There is a registered user with username "username" and password "password" and email "[email protected]" | ||
|
||
|
||
Scenario: Get an existing Location details | ||
Given I can login with username "username" and password "password" | ||
And There is already a Location with the following details: | ||
| address | Major Street 3 | | ||
| province | Lleida | | ||
| city | Seròs | | ||
| postalCode | 25183 | | ||
When I retrieve the location with the details: | ||
| address | Major Street 3 | | ||
| province | Lleida | | ||
| city | Seròs | | ||
| postalCode | 25183 | | ||
Then The response code is 200 | ||
|
||
Scenario: Get a non-existent Location details | ||
Given I can login with username "username" and password "password" | ||
When I retrieve the location with the details: | ||
| address | Major Street 3 | | ||
| province | Lleida | | ||
| city | Seròs | | ||
| postalCode | 25183 | | ||
Then The response code is 404 |