-
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.
Merge pull request #88 from UdL-EPS-SoftArch/83-feature-getadvertisment
83 feature getadvertisment
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/test/java/cat/udl/eps/softarch/demo/steps/GetAdvertismentStepDefs.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,56 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
|
||
import cat.udl.eps.softarch.demo.repository.ApartmentRepository; | ||
import io.cucumber.java.en.And; | ||
import org.springframework.http.MediaType; | ||
import cat.udl.eps.softarch.demo.domain.*; | ||
import cat.udl.eps.softarch.demo.repository.AdvertisementRepository; | ||
import cat.udl.eps.softarch.demo.repository.AdvertisementStatusRepository; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class GetAdvertismentStepDefs { | ||
|
||
@Autowired | ||
private AdvertisementRepository advertisementRepository; | ||
|
||
@Autowired | ||
private ApartmentRepository apartmentRepository; | ||
@Autowired | ||
private AdvertisementStatusRepository advertisementStatusRepository; | ||
private AdvertisementStatus status; | ||
private ResponseEntity<String> response; | ||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@When("I get the apartment advertisement with title {string}") | ||
public void iGetTheApartmentAdvertisement(String title) throws Exception { | ||
Advertisement ad = advertisementRepository.findByTitle(title).stream().findFirst().orElse(null); | ||
|
||
if (ad == null) { | ||
stepDefs.result = stepDefs.mockMvc.perform( | ||
get("/advertisements/{id}", 9999) | ||
.accept(MediaType.APPLICATION_JSON) | ||
).andDo(print()); | ||
} else { | ||
stepDefs.result = stepDefs.mockMvc.perform( | ||
get("/advertisements/{id}", ad.getId()) | ||
.accept(MediaType.APPLICATION_JSON) | ||
).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,28 @@ | ||
Feature: Get Advertisement | ||
In order to use the app | ||
users can retrieve advertisement details for existing apartments | ||
|
||
Scenario: Get an existing apartment advertisement by title | ||
Given There is an existing apartment with id "1" named "Cozy Apartment" | ||
And I login as "owner" with password "password" | ||
And There is an existing advertisement status "Available" | ||
And There is an advertisement with title "Apartment for rent", description "A beautiful apartment", price "1200", zipCode "12345", address "456 Elm St", country "Spain", status "Available", apartment title "Cozy Apartment" | ||
When I get the apartment advertisement with title "Apartment for rent" | ||
Then The response code is 200 | ||
|
||
Scenario: Get a non-existing apartment advertisement by title | ||
Given There is an existing apartment with id "1" named "Cozy Apartment" | ||
And I login as "owner" with password "password" | ||
And There is an existing advertisement status "Available" | ||
And There is an advertisement with title "Apartment for rent", description "A beautiful apartment", price "1200", zipCode "12345", address "456 Elm St", country "Spain", status "Available", apartment title "Cozy Apartment" | ||
When I get the apartment advertisement with title "non existing title" | ||
Then The response code is 404 | ||
|
||
|
||
Scenario: Get apartment advertisement when not authenticated | ||
Given There is an existing apartment with id "1" named "Cozy Apartment" | ||
And There is an existing advertisement status "Available" | ||
And There is an advertisement with title "Apartment for rent", description "A beautiful apartment", price "1200", zipCode "12345", address "456 Elm St", country "Spain", status "Available", apartment title "Cozy Apartment" | ||
Given I'm not logged in | ||
When I get the apartment advertisement with title "Apartment for rent" | ||
Then The response code is 200 |