-
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 branch 'main' into feature-Delete-Shelter
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 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
60 changes: 60 additions & 0 deletions
60
src/test/java/cat/udl/eps/softarch/demo/steps/LoginStepDefs.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,60 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.User; | ||
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.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
public class LoginStepDefs { | ||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Given("^There isn't registered user with username \"([^\"]*)\"$") | ||
public void thereIsNoRegisteredUserWithUsername(String user) { | ||
Assert.assertFalse("User \"" | ||
+ user + "\"shouldn't exist", | ||
userRepository.existsById(user)); | ||
} | ||
|
||
@Given("^There is a registered user with username \"([^\"]*)\" and password \"([^\"]*)\"$") | ||
public void thereIsARegisteredUserWithUsernameAndPassword(String username, String password) { | ||
if(!userRepository.existsById(username)){ | ||
User user = new User(); | ||
user.setId(username); | ||
user.setEmail("[email protected]"); | ||
user.setPassword(password); | ||
user.encodePassword(); | ||
userRepository.save(user); | ||
} | ||
} | ||
|
||
|
||
|
||
@When("^I login with username \"([^\"]*)\" and password \"([^\"]*)\"$") | ||
public void iLoginWithUsernameAndPassword(String username, String password) throws Exception { | ||
AuthenticationStepDefs.currentUsername = username; | ||
AuthenticationStepDefs.currentPassword = password; | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
get("/identity") | ||
.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,36 @@ | ||
Feature: Login User | ||
In order to use the app | ||
As a user | ||
I want to login myself to access it | ||
|
||
Scenario: Login already registered user | ||
Given There is a registered user with username "user" and password "password" | ||
And I'm not logged in | ||
When I login with username "user" and password "password" | ||
Then The response code is 200 | ||
And I can login with username "user" and password "password" | ||
|
||
Scenario: Login with a non existing user | ||
Given There isn't registered user with username "anonymous" | ||
And I'm not logged in | ||
When I login with username "anonymous" and password "password" | ||
Then The response code is 401 | ||
#And The error message is "wrong user or password" | ||
|
||
Scenario: Login with a incorrect password | ||
Given There is a registered user with username "user" and password "password" | ||
And I'm not logged in | ||
When I login with username "user" and password "anonymous" | ||
Then The response code is 401 | ||
#And The error message is "wrong user or password" | ||
|
||
Scenario: Login with empty username | ||
Given I'm not logged in | ||
When I login with username "" and password "password" | ||
Then The response code is 401 | ||
|
||
Scenario: Login with empty password | ||
Given There is a registered user with username "user" and password "password" | ||
And I'm not logged in | ||
When I login with username "user" and password "" | ||
Then The response code is 401 |