-
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 #80 from UdL-EPS-SoftArch/Feature-Edit-Shelter
Feature - Edit shelter
- Loading branch information
Showing
5 changed files
with
140 additions
and
13 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
87 changes: 83 additions & 4 deletions
87
src/test/java/cat/udl/eps/softarch/demo/steps/EditShelterStepDefs.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,34 +1,113 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Shelter; | ||
import cat.udl.eps.softarch.demo.domain.User; | ||
import cat.udl.eps.softarch.demo.domain.ShelterVolunteer; | ||
import cat.udl.eps.softarch.demo.domain.Admin; | ||
|
||
|
||
import cat.udl.eps.softarch.demo.repository.AdminRepository; | ||
import cat.udl.eps.softarch.demo.repository.ShelterRepository; | ||
import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository; | ||
import cat.udl.eps.softarch.demo.repository.UserRepository; | ||
|
||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.When; | ||
import org.json.JSONObject; | ||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
import static com.jayway.jsonpath.internal.path.PathCompiler.fail; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class EditShelterStepDefs { | ||
|
||
@Autowired | ||
ShelterRepository shelterRepository; | ||
User user = new User(); | ||
@Autowired | ||
UserRepository userRepository; | ||
@And("^There a shelter with name \"([^\"]*)\" email \"([^\"]*)\" and mobile \"([^\"]*)\"$") | ||
public void thereAShelterWithNameEmailAndMobile(String name, String email, String mobile) { | ||
@Autowired | ||
AdminRepository adminRepository; | ||
@Autowired | ||
ShelterVolunteerRepository shelterVolunteerRepository; | ||
@Autowired | ||
StepDefs stepDefs; | ||
@And("^There is already a shelter with name \"([^\"]*)\" email \"([^\"]*)\" and mobile \"([^\"]*)\"$") | ||
public void thereIsAlreadyAShelterWithNameEmailAndMobile(String name, String email, String mobile) { | ||
Shelter shelter = new Shelter(); | ||
shelter.setName(name); | ||
shelter.setEmail(email); | ||
shelter.setMobile(mobile); | ||
shelterRepository.save(shelter); | ||
} | ||
|
||
@When("^I update the shelter with name \"([^\"]*)\" to name \"([^\"]*)\" email \"([^\"]*)\" and mobile \"([^\"]*)\"$") | ||
public void iUpdateTheShelterWithNameToNameEmailAndMobile(String prevName, String newName, String email, String mobile) | ||
throws Throwable { | ||
Shelter shelter = shelterRepository.findByName(prevName).get(0); | ||
if (shelter != null) { | ||
shelter = shelterRepository.findByName(prevName).get(0); | ||
} | ||
stepDefs.result = stepDefs.mockMvc.perform(patch(shelter.getUri()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(new JSONObject().put("name", newName) | ||
.put("email", email) | ||
.put("mobile", mobile).toString()) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
|
||
@Given("^There is a registered volunteer with username \"([^\"]*)\" and password \"([^\"]*)\"$") | ||
public void thereIsARegisteredVolunteerWithUsernameAndPasswordAndEmail(String name, String mobile) { | ||
if (!shelterVolunteerRepository.existsById(name)) { | ||
ShelterVolunteer volunteer = new ShelterVolunteer(); | ||
volunteer.setEmail("[email protected]"); | ||
volunteer.setId(name); | ||
volunteer.setPassword(mobile); | ||
volunteer.encodePassword(); | ||
shelterVolunteerRepository.save(volunteer); | ||
} | ||
} | ||
|
||
@And("^I get the shelter with name \"([^\"]*)\"") | ||
public void iGetTheShelterWithName(String newname) throws Exception { | ||
List<Shelter> shelters = shelterRepository.findByName(newname); | ||
Shelter shelter = shelters.get(0); | ||
stepDefs.result = stepDefs.mockMvc.perform(get("/shelters/" + shelter.getId()) | ||
.accept(MediaType.APPLICATION_JSON)).andDo(print()); | ||
JSONObject jsonObject = new JSONObject(stepDefs.result.andReturn().getResponse().getContentAsString()); | ||
jsonObject.getString("name"); | ||
try { | ||
String actualName = jsonObject.getString("name"); | ||
Assert.assertEquals(newname, actualName); | ||
} catch (Exception e) { | ||
fail("Key not found"); | ||
} | ||
} | ||
|
||
|
||
@Given("There is a registered already admin with username \"([^\"]*)\" and password \"([^\"]*)\" and email \"([^\"]*)\"$") | ||
public void thereIsARegisteredAlreadyAdminWithUsernameAndPasswordAndEmail(String adminname, String adminPasswd, String adminEmail) { | ||
if (!adminRepository.existsById(adminname)) { | ||
Admin user = new Admin(); | ||
user.setEmail(adminEmail); | ||
user.setId(adminname); | ||
user.setPassword(adminPasswd); | ||
user.encodePassword(); | ||
adminRepository.save(user); | ||
|
||
} | ||
} | ||
} |
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,4 +1,4 @@ | ||
Feature: | ||
Feature: Delete Pet | ||
in order to use the app | ||
As a Shelter Volunteer | ||
I must be able to delete a Pet | ||
|
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,53 @@ | ||
Feature: Edit Shelter | ||
In order to update shelter information | ||
As a shelter manager | ||
I want to edit a shelter | ||
|
||
Background: | ||
Given There is a registered user with username "user" and password "existing" and email "[email protected]" | ||
Given There is a registered already admin with username "admin" and password "admin" and email "[email protected]" | ||
Given There is a registered volunteer with username "volunteer" and password "volunteer" | ||
And There is already a shelter with name "Shelter 1" email "[email protected]" and mobile "999999999" | ||
|
||
Scenario: Edit shelter without being logged in | ||
Given I'm not logged in | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
Then The response code is 401 | ||
And The error message is "Unauthorized" | ||
|
||
Scenario: Edit shelter with user | ||
Given I login as "client" with password "existing" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
Then The response code is 401 | ||
And The error message is "Unauthorized" | ||
|
||
Scenario: Edit shelter with admin | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
And I get the shelter with name "Another Shelter" | ||
Then The response code is 200 | ||
|
||
Scenario: Edit shelter with volunteer | ||
Given I login as "volunteer" with password "volunteer" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
And I get the shelter with name "Another Shelter" | ||
Then The response code is 200 | ||
|
||
Scenario: Edit shelter with missing new name | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "" email "[email protected]" and mobile "123123123" | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
|
||
Scenario: Edit shelter with missing new email | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "" and mobile "123123123" | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
|
||
Scenario: Edit shelter with missing new mobile | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "" | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
|
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 |
---|---|---|
|
@@ -5,10 +5,10 @@ Feature: Kick ShelterVolunteer from Shelter | |
|
||
Background: | ||
Given There is a registered user with username "user" and password "pass" and email "[email protected]" | ||
And There a shelter with name "shelter1" email "[email protected]" and mobile "12345678" | ||
And There is already a shelter with name "shelter1" email "[email protected]" and mobile "12345678" | ||
And There is a shelter volunteer with username "volunteer" and password "pass" in the shelter "shelter1" | ||
And There is a shelter volunteer with username "volunteer1" and password "pass" in the shelter "shelter1" | ||
And There a shelter with name "shelter2" email "[email protected]" and mobile "12345679" | ||
And There is already a shelter with name "shelter2" email "[email protected]" and mobile "12345679" | ||
And There is a shelter volunteer with username "volunteer2" and password "pass" in the shelter "shelter2" | ||
|
||
Scenario: Kick volunteer from shelter | ||
|
@@ -17,18 +17,13 @@ Feature: Kick ShelterVolunteer from Shelter | |
Then The response code is 200 | ||
And I cannot login with username "volunteer1" and password "pass" | ||
|
||
|
||
|
||
Scenario: Kick volunteer from shelter as user | ||
|
||
And I can login with username "user" and password "pass" | ||
When I kick user "volunteer1" from shelter "shelter" | ||
Then The response code is 403 | ||
And I can login with username "volunteer1" and password "pass" | ||
|
||
|
||
Scenario: Kick volunteer from shelter as volunteer in another shelter | ||
|
||
Given I can login with username "volunteer" and password "pass" | ||
When I kick user "volunteer2" from shelter "shelter" | ||
Then The response code is 412 | ||
|