From 6e3d2bc7e16f7a14e8f75842592708ff554e51ac Mon Sep 17 00:00:00 2001 From: gerardmallol Date: Tue, 16 Apr 2024 12:21:53 +0200 Subject: [PATCH] solucionar comentaris adoptions scenarios --- .../demo/steps/StepRegisterAdoption.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/java/cat/udl/eps/softarch/demo/steps/StepRegisterAdoption.java b/src/test/java/cat/udl/eps/softarch/demo/steps/StepRegisterAdoption.java index 433531c..1c58d44 100644 --- a/src/test/java/cat/udl/eps/softarch/demo/steps/StepRegisterAdoption.java +++ b/src/test/java/cat/udl/eps/softarch/demo/steps/StepRegisterAdoption.java @@ -8,11 +8,16 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; + +import java.nio.charset.StandardCharsets; import java.util.Optional; import static java.lang.Long.parseLong; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; public class StepRegisterAdoption { @@ -59,9 +64,22 @@ public void adopt(String username, String chip) { if (!pet.isAdopted()) { Adoptions adoptions = new Adoptions(); adoptions.setPet(pet); - userRepository.findById(username).ifPresent(user -> adoptions.setUser(user)); + userRepository.findById(username).ifPresent(adoptions::setUser); pet.setAdopted(true); petRepository.save(pet); + + try { + stepDefs.result = stepDefs.mockMvc.perform( + post("/adoptions") + .contentType(MediaType.APPLICATION_JSON) + .content(stepDefs.mapper.writeValueAsString(adoptions)) + .characterEncoding(StandardCharsets.UTF_8) + .accept(MediaType.APPLICATION_JSON) + .with(AuthenticationStepDefs.authenticate())) + .andDo(print()); + } catch (Exception e) { + throw new RuntimeException(e); + } } } }