-
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
4 changed files
with
126 additions
and
7 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
84 changes: 84 additions & 0 deletions
84
src/test/java/cat/udl/eps/softarch/demo/steps/ModifyAdvertisementStatusStepDefs.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,84 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.AdvertisementStatus; | ||
import cat.udl.eps.softarch.demo.repository.AdvertisementStatusRepository; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
public class ModifyAdvertisementStatusStepDefs { | ||
@Autowired | ||
StepDefs stepDefs; | ||
|
||
@Autowired | ||
AdvertisementStatusRepository adStatusRepository; | ||
|
||
private AdvertisementStatus adStatus; | ||
|
||
private String previousStatus; | ||
|
||
private long adStatusId; | ||
|
||
@Given("^There is an advertisementStatus already created with status \"([^\"]*)\"$") | ||
public void there_is_an_advertisement_status_already_created_with_description(String status) { | ||
this.adStatus = new AdvertisementStatus(); | ||
this.adStatus.setStatus(status); | ||
this.adStatusRepository.save(this.adStatus); | ||
} | ||
|
||
@When("^I modify an advertisementStatus with status \"([^\"]*)\" and change it to \"([^\"]*)\"$") | ||
public void modify_advertisement_status(String status, String newStatus) throws Throwable { | ||
AdvertisementStatus adStatus = adStatusRepository.findByStatus(status).stream().findFirst().orElse(null); | ||
assertNotNull("Apartment with name \"" + status + "\" should exist", adStatus); | ||
this.previousStatus = this.adStatus.getStatus(); | ||
this.adStatusId = adStatus.getId(); | ||
if (newStatus.equals("null")) { | ||
adStatus.setStatus(null); | ||
} else { | ||
adStatus.setStatus(newStatus); | ||
} | ||
|
||
this.stepDefs.result = this.stepDefs.mockMvc.perform(put("/advertisementStatuses/" + this.adStatusId) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(adStatus)) // Enviar el objeto actualizado | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
|
||
} | ||
|
||
@And("The advertisementStatus has not been modified to \"([^\"]*)\"$") | ||
public void the_advertisement_status_has_not_been_modified(String descToCheck) throws Throwable { | ||
|
||
AdvertisementStatus adStatusToCheck = this.adStatusRepository.findById(this.adStatusId).get(); | ||
|
||
assertNotEquals(adStatusToCheck.getStatus(), descToCheck); | ||
assertEquals(adStatusToCheck.getStatus(), previousStatus); | ||
} | ||
|
||
@And("The advertisementStatus has been modified to \"([^\"]*)\"$") | ||
public void the_advertisement_status_has_been_modified(String status) { | ||
|
||
AdvertisementStatus adStatusToCheck = this.adStatusRepository.findById(this.adStatusId).get(); | ||
|
||
assertEquals(status, adStatusToCheck.getStatus()); | ||
} | ||
|
||
@And("^The advertisementStatus has been modified with the description \"([^\"]*)\"$") | ||
public void the_advertisement_status_has_been_modified_with_description(String newDescription) throws Throwable { | ||
|
||
AdvertisementStatus adStatusToCheck = this.adStatusRepository.findById(this.adStatusId).get(); | ||
|
||
assertEquals(adStatusToCheck.getStatus(), newDescription); | ||
assertNotEquals(adStatusToCheck.getStatus(), previousStatus); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/resources/features/ModifyAdvertisementStatus.feature
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,40 @@ | ||
Feature: Modify an Advertisement Status | ||
In order to make changes on a property | ||
As an owner | ||
I want to modify a property | ||
|
||
Background: | ||
Given There is a registered user with username "user" and password "password" and email "[email protected]" | ||
Given There is a registered owner with username "owner" and password "password" and email "[email protected]" | ||
|
||
Scenario: Modify an Advertisement Status when not logged in | ||
Given I'm not logged in | ||
And There is an advertisementStatus already created with status "Available" | ||
When I modify an advertisementStatus with status "Available" and change it to "Occupied" | ||
Then The response code is 401 | ||
And The error message is "Unauthorized" | ||
And The advertisementStatus has not been modified to "Occupied" | ||
|
||
Scenario: Modify a Advertisement Status when logged in as a user | ||
Given I login as "user" with password "password" | ||
And There is an advertisementStatus already created with status "Available" | ||
When I modify an advertisementStatus with status "Available" and change it to "Occupied" | ||
Then The response code is 403 | ||
And The error message is "Forbidden" | ||
And The advertisementStatus has not been modified to "Occupied" | ||
|
||
Scenario: Modify a Advertisement Status when logged in as a owner | ||
Given I login as "owner" with password "password" | ||
And There is an advertisementStatus already created with status "Available" | ||
When I modify an advertisementStatus with status "Available" and change it to "Occupied" | ||
Then The response code is 204 | ||
And The advertisementStatus has been modified to "Occupied" | ||
|
||
Scenario: Modify a Advertisement Status when logged in as a owner and status null | ||
Given I login as "owner" with password "password" | ||
And There is an advertisementStatus already created with status "Available" | ||
When I modify an advertisementStatus with status "Available" and change it to "null" | ||
Then The response code is 400 | ||
And The advertisementStatus has not been modified to "null" | ||
|
||
|