Add registration test.

main
Paulo Gustavo Veiga 2024-02-04 17:31:21 -08:00
parent a681cf9b90
commit 6674c607f7
2 changed files with 35 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);
}
}