From 6674c607f7ab2c21679ffb33f8f74c352d63bf51 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 4 Feb 2024 17:31:21 -0800 Subject: [PATCH] Add registration test. --- .../rest/model/RestUserRegistration.java | 11 ++++++++ .../test/rest/RestUserControllerTest.java | 25 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/wise-api/src/main/java/com/wisemapping/rest/model/RestUserRegistration.java b/wise-api/src/main/java/com/wisemapping/rest/model/RestUserRegistration.java index dca77ea3..3b0fb7d0 100644 --- a/wise-api/src/main/java/com/wisemapping/rest/model/RestUserRegistration.java +++ b/wise-api/src/main/java/com/wisemapping/rest/model/RestUserRegistration.java @@ -24,6 +24,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.wisemapping.model.User; +import java.awt.*; + @JsonAutoDetect( fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, @@ -47,6 +49,15 @@ public class RestUserRegistration { return user; } + public static RestUserRegistration create(String email, String password, String firstname, String lastname) { + final RestUserRegistration result = new RestUserRegistration(); + result.email = email; + result.password = password; + result.firstname = firstname; + result.lastname = lastname; + return result; + } + public String getEmail() { return email; } diff --git a/wise-api/src/test/java/com/wisemapping/test/rest/RestUserControllerTest.java b/wise-api/src/test/java/com/wisemapping/test/rest/RestUserControllerTest.java index 49320e36..f487c19e 100644 --- a/wise-api/src/test/java/com/wisemapping/test/rest/RestUserControllerTest.java +++ b/wise-api/src/test/java/com/wisemapping/test/rest/RestUserControllerTest.java @@ -25,8 +25,10 @@ import com.wisemapping.config.rest.RestAppConfig; import com.wisemapping.model.User; import com.wisemapping.rest.UserController; import com.wisemapping.rest.model.RestUser; +import com.wisemapping.rest.model.RestUserRegistration; import com.wisemapping.service.UserService; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -37,6 +39,7 @@ import org.springframework.test.web.servlet.MockMvc; import static com.wisemapping.test.rest.RestHelper.createDummyUser; import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -71,7 +74,7 @@ public class RestUserControllerTest { // Check dao ... User userBy = userService.getUserBy(result.getEmail()); - assertTrue(userBy!=null); + assertNotNull(userBy); return result; } @@ -92,4 +95,24 @@ public class RestUserControllerTest { .andDo(print()) .andExpect(status().isOk()); } + + + @Test + @Disabled + void registerNewUser() throws Exception { + final RestUserRegistration user = RestUserRegistration.create("some@example.com", "somepass", "Test", "registation"); + final String userJson = objectMapper.writeValueAsString(user); + + mockMvc.perform( + post("/api/restfull/users/"). + contentType(MediaType.APPLICATION_JSON) + .content(userJson)) + .andExpect(status().isCreated()); + + // Check dao ... + User userBy = userService.getUserBy(user.getEmail()); + assertNotNull(userBy); + } + + }