mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 23:44:54 +01:00
Add missing expoint test.
This commit is contained in:
parent
d798358fec
commit
37d7a9bb6d
@ -18,27 +18,30 @@
|
|||||||
|
|
||||||
package com.wisemapping.test.rest;
|
package com.wisemapping.test.rest;
|
||||||
|
|
||||||
|
|
||||||
import com.wisemapping.config.common.CommonConfig;
|
import com.wisemapping.config.common.CommonConfig;
|
||||||
import com.wisemapping.config.rest.RestAppConfig;
|
import com.wisemapping.config.rest.RestAppConfig;
|
||||||
import com.wisemapping.rest.AdminController;
|
import com.wisemapping.rest.AdminController;
|
||||||
import com.wisemapping.rest.MindmapController;
|
import com.wisemapping.rest.MindmapController;
|
||||||
import com.wisemapping.rest.UserController;
|
import com.wisemapping.rest.UserController;
|
||||||
import com.wisemapping.rest.model.RestUser;
|
import com.wisemapping.rest.model.RestUser;
|
||||||
|
import com.wisemapping.security.UserDetailsService;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static com.wisemapping.test.rest.RestHelper.*;
|
import static com.wisemapping.test.rest.RestHelper.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest(classes = {RestAppConfig.class, CommonConfig.class, MindmapController.class, AdminController.class, UserController.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(classes = {RestAppConfig.class, CommonConfig.class, MindmapController.class, AdminController.class, UserController.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
@AutoConfigureMockMvc
|
||||||
public class RestAccountControllerTest {
|
public class RestAccountControllerTest {
|
||||||
private static final String ADMIN_USER = "admin@wisemapping.org";
|
private static final String ADMIN_USER = "admin@wisemapping.org";
|
||||||
private static final String ADMIN_PASSWORD = "test";
|
private static final String ADMIN_PASSWORD = "test";
|
||||||
@ -46,6 +49,9 @@ public class RestAccountControllerTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDetailsService service;
|
||||||
|
|
||||||
static public RestAccountControllerTest create(@NotNull TestRestTemplate restTemplate) {
|
static public RestAccountControllerTest create(@NotNull TestRestTemplate restTemplate) {
|
||||||
final RestAccountControllerTest result = new RestAccountControllerTest();
|
final RestAccountControllerTest result = new RestAccountControllerTest();
|
||||||
result.restTemplate = restTemplate;
|
result.restTemplate = restTemplate;
|
||||||
@ -53,27 +59,40 @@ public class RestAccountControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteUser() { // Configure media types ...
|
public void deleteAccount() {
|
||||||
|
|
||||||
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
|
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
|
||||||
final TestRestTemplate adminRestTemplate = this.restTemplate.withBasicAuth(ADMIN_USER, ADMIN_PASSWORD);
|
final TestRestTemplate adminRestTemplate = this.restTemplate.withBasicAuth(ADMIN_USER, ADMIN_PASSWORD);
|
||||||
|
|
||||||
final RestUser dummyUser = createDummyUser();
|
final RestUser newUser = createDummyUser();
|
||||||
createUser(requestHeaders, adminRestTemplate, dummyUser);
|
createUser(requestHeaders, adminRestTemplate, newUser);
|
||||||
|
|
||||||
// Delete user ...
|
// Delete user ...
|
||||||
final TestRestTemplate dummyTemplate = this.restTemplate.withBasicAuth(dummyUser.getEmail(), "fooPassword");
|
final TestRestTemplate newUserTemplate = this.restTemplate.withBasicAuth(newUser.getEmail(), newUser.getPassword());
|
||||||
dummyTemplate.delete(BASE_REST_URL + "/account");
|
final ResponseEntity<String> exchange = newUserTemplate.exchange(BASE_REST_URL + "/account", HttpMethod.DELETE, null, String.class);
|
||||||
|
assertTrue(exchange.getStatusCode().is2xxSuccessful(), exchange.toString());
|
||||||
|
|
||||||
// Is the user there ?
|
// Check that the account has been deleted ...
|
||||||
// Check that the user has been created ...
|
assertThrows(UsernameNotFoundException.class, () -> {
|
||||||
// try {
|
service.loadUserByUsername(newUser.getEmail());
|
||||||
// findUser(requestHeaders, adminTemplate, location);
|
});
|
||||||
// fail("User could not be deleted !");
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void accessAccount() {
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
|
||||||
|
final TestRestTemplate adminRestTemplate = this.restTemplate.withBasicAuth(ADMIN_USER, ADMIN_PASSWORD);
|
||||||
|
|
||||||
|
final RestUser newUser = createDummyUser();
|
||||||
|
createUser(requestHeaders, adminRestTemplate, newUser);
|
||||||
|
|
||||||
|
final TestRestTemplate newUserTemplate = this.restTemplate.withBasicAuth(newUser.getEmail(), newUser.getPassword());
|
||||||
|
final ResponseEntity<RestUser> exchange = newUserTemplate.exchange(BASE_REST_URL + "/account", HttpMethod.GET, null, RestUser.class);
|
||||||
|
assertTrue(exchange.getStatusCode().is2xxSuccessful(), exchange.toString());
|
||||||
|
assertEquals(exchange.getBody().getEmail(), newUser.getEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public RestUser createNewUser() {
|
public RestUser createNewUser() {
|
||||||
// Configure media types ...
|
// Configure media types ...
|
||||||
|
@ -22,14 +22,10 @@ package com.wisemapping.test.rest;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.wisemapping.config.common.CommonConfig;
|
import com.wisemapping.config.common.CommonConfig;
|
||||||
import com.wisemapping.config.rest.RestAppConfig;
|
import com.wisemapping.config.rest.RestAppConfig;
|
||||||
import com.wisemapping.model.User;
|
|
||||||
import com.wisemapping.rest.JwtAuthController;
|
import com.wisemapping.rest.JwtAuthController;
|
||||||
import com.wisemapping.rest.model.RestJwtUser;
|
import com.wisemapping.rest.model.RestJwtUser;
|
||||||
import com.wisemapping.rest.model.RestUser;
|
|
||||||
import com.wisemapping.rest.model.RestUserRegistration;
|
|
||||||
import com.wisemapping.security.JwtTokenUtil;
|
import com.wisemapping.security.JwtTokenUtil;
|
||||||
import com.wisemapping.service.UserService;
|
import com.wisemapping.service.UserService;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
@ -38,15 +34,8 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
|
||||||
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.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.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@SpringBootTest(classes = {RestAppConfig.class, CommonConfig.class, JwtAuthController.class})
|
@SpringBootTest(classes = {RestAppConfig.class, CommonConfig.class, JwtAuthController.class})
|
||||||
|
@ -27,22 +27,20 @@ import com.wisemapping.rest.UserController;
|
|||||||
import com.wisemapping.rest.model.RestUser;
|
import com.wisemapping.rest.model.RestUser;
|
||||||
import com.wisemapping.rest.model.RestUserRegistration;
|
import com.wisemapping.rest.model.RestUserRegistration;
|
||||||
import com.wisemapping.service.UserService;
|
import com.wisemapping.service.UserService;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
import static com.wisemapping.test.rest.RestHelper.createDummyUser;
|
import static com.wisemapping.test.rest.RestHelper.createDummyUser;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
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.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
Loading…
Reference in New Issue
Block a user