Skip to content

Commit

Permalink
Merge branch 'main' into feature-Delete-Shelter
Browse files Browse the repository at this point in the history
  • Loading branch information
vGerJ02 committed Mar 19, 2024
2 parents 9996bc5 + 9b877c9 commit 7925794
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
public interface PetRepository extends CrudRepository<Pet, Long>, PagingAndSortingRepository<Pet, Long> {
List<Pet> findBySize(@Param("size") String size);
List<Pet> findByName(@Param("name") String name);
List<Pet> findByIsAdopted(@Param("isAdopted") Boolean isAdopted);
List<Pet> findByBreed(@Param("breed") String breed);
//Pet findByShelter(@Param("id") Long shelterId);

}
60 changes: 60 additions & 0 deletions src/test/java/cat/udl/eps/softarch/demo/steps/LoginStepDefs.java
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());
}



}
36 changes: 36 additions & 0 deletions src/test/resources/features/LoginUser.feature
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

0 comments on commit 7925794

Please sign in to comment.