mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 06:07:57 +01:00
Fix more test.
This commit is contained in:
parent
f528abaa44
commit
e28302236b
@ -1,13 +1,20 @@
|
|||||||
package com.wisemapping.test.rest;
|
package com.wisemapping.test.rest;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wisemapping.config.common.CommonConfig;
|
||||||
|
import com.wisemapping.config.rest.RestAppConfig;
|
||||||
import com.wisemapping.exceptions.WiseMappingException;
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
|
import com.wisemapping.rest.AdminController;
|
||||||
|
import com.wisemapping.rest.MindmapController;
|
||||||
|
import com.wisemapping.rest.UserController;
|
||||||
import com.wisemapping.rest.model.*;
|
import com.wisemapping.rest.model.*;
|
||||||
import jakarta.annotation.Nullable;
|
import jakarta.annotation.Nullable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
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.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.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
@ -23,12 +30,12 @@ import java.util.stream.Collectors;
|
|||||||
import static com.wisemapping.test.rest.RestHelper.createHeaders;
|
import static com.wisemapping.test.rest.RestHelper.createHeaders;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
//@SpringBootTest(classes = {RestAppConfig.class, CommonConfig.class, MindmapController.class, AdminController.class, UserController.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(classes = {RestAppConfig.class, CommonConfig.class, MindmapController.class, AdminController.class, UserController.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
public class RestMindmapControllerTest {
|
public class RestMindmapControllerTest {
|
||||||
|
|
||||||
private RestUser user;
|
private RestUser user;
|
||||||
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@ -513,7 +520,7 @@ public class RestMindmapControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled("missing test: delete map should not affects others labels")
|
@Disabled("missing test: delete map should not affects others labels")
|
||||||
public void deleteMapAndCheckLabels(final @NotNull MediaType mediaType) { // Configure media types ...
|
public void deleteMapAndCheckLabels() { // Configure media types ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -672,93 +679,85 @@ public class RestMindmapControllerTest {
|
|||||||
assertEquals(1, Objects.requireNonNull(maps.getBody()).getCount());
|
assertEquals(1, Objects.requireNonNull(maps.getBody()).getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
@Test
|
||||||
// public void updateRevertMindmap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
public void updateRevertMindmap() throws IOException {
|
||||||
// final HttpHeaders requestHeaders = createHeaders(mediaType);
|
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
|
||||||
// final RestTemplate template = createTemplate(userEmail);
|
final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
|
||||||
//
|
|
||||||
// // Create a sample map ...
|
// Create a sample map ...
|
||||||
// final URI resourceUri = addNewMap(template, "map to test revert changes");
|
final URI resourceUri = addNewMap(restTemplate, "map to test revert changes");
|
||||||
// updateMapDocument(requestHeaders, template, HOST_PORT + resourceUri.toString(), "<map><node text='this is an xml to test revert changes service'></map>");
|
updateMapDocument(requestHeaders, restTemplate, resourceUri.toString(), "<map><node text='this is an xml to test revert changes service'></map>");
|
||||||
//
|
|
||||||
// updateMapDocument(requestHeaders, template, HOST_PORT + resourceUri.toString(), "<map><node text='this is an xml with modification to be reverted'></map>");
|
updateMapDocument(requestHeaders, restTemplate, resourceUri.toString(), "<map><node text='this is an xml with modification to be reverted'></map>");
|
||||||
//
|
|
||||||
// //fetch map history
|
//fetch map history
|
||||||
// final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
final HttpEntity<RestMindmapHistoryList> findMapEntity = new HttpEntity<>(requestHeaders);
|
||||||
// final ResponseEntity<RestMindmapHistoryList> mapHistories = template.exchange(HOST_PORT + resourceUri + "/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
|
final ResponseEntity<RestMindmapHistoryList> mapHistories = restTemplate.exchange(resourceUri + "/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
|
||||||
//
|
|
||||||
// //aply revert
|
//aply revert
|
||||||
// final HttpEntity<String> cloneEntity = new HttpEntity<>(requestHeaders);
|
final HttpEntity<String> cloneEntity = new HttpEntity<>(requestHeaders);
|
||||||
// template.postForLocation(HOST_PORT + resourceUri + "/history/latest", cloneEntity);
|
restTemplate.postForLocation(resourceUri + "/history/latest", cloneEntity);
|
||||||
// final RestMindmap latestStoredMap = findMap(requestHeaders, template, resourceUri);
|
final RestMindmap latestStoredMap = findMap(requestHeaders, restTemplate, resourceUri);
|
||||||
// template.postForLocation(HOST_PORT + resourceUri + "/history/" + mapHistories.getBody().getChanges().get(1).getId(), cloneEntity);
|
restTemplate.postForLocation(resourceUri + "/history/" + mapHistories.getBody().getChanges().get(1).getId(), cloneEntity);
|
||||||
// final RestMindmap firstVersionMap = findMap(requestHeaders, template, resourceUri);
|
final RestMindmap firstVersionMap = findMap(requestHeaders, restTemplate, resourceUri);
|
||||||
//
|
|
||||||
// //verify revert
|
//verify revert
|
||||||
// assertEquals(firstVersionMap.getXml(), "<map><node text='this is an xml to test revert changes service'></map>");
|
assertEquals(firstVersionMap.getXml(), "<map><node text='this is an xml to test revert changes service'></map>");
|
||||||
// assertEquals(latestStoredMap.getXml(), "<map><node text='this is an xml with modification to be reverted'></map>");
|
assertEquals(latestStoredMap.getXml(), "<map><node text='this is an xml with modification to be reverted'></map>");
|
||||||
//
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
@Test
|
||||||
// public void addCollabWhitoutOwnerPermission(final @NotNull MediaType mediaType) {
|
public void addCollabWhitoutOwnerPermission() {
|
||||||
// final HttpHeaders requestHeaders = createHeaders(mediaType);
|
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
|
||||||
// RestTemplate template = createTemplate(userEmail);
|
final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
|
||||||
//
|
|
||||||
// // Create a sample map ...
|
// Create a sample map ...
|
||||||
// final URI resourceUri = addNewMap(template, "MaddCollabWhitoutOwnerPermission");
|
final URI resourceUri = addNewMap(restTemplate, "MaddCollabWhitoutOwnerPermission");
|
||||||
//
|
|
||||||
// // Add a new collaboration ...
|
// Add a new collaboration ...
|
||||||
// requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
// final RestCollaborationList collabs = new RestCollaborationList();
|
final RestCollaborationList collabs = new RestCollaborationList();
|
||||||
// collabs.setMessage("Adding new permission");
|
collabs.setMessage("Adding new permission");
|
||||||
//
|
|
||||||
// final String newCollab = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
final RestAccountControllerTest restAccount = RestAccountControllerTest.create(restTemplate);
|
||||||
// String role = "editor";
|
final RestUser newCollab = restAccount.createNewUser();
|
||||||
//
|
String role = "editor";
|
||||||
// addCollabToList(newCollab, role, collabs);
|
|
||||||
//
|
addCollabToList(newCollab.getEmail(), role, collabs);
|
||||||
// final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
|
||||||
// template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||||
//
|
restTemplate.put(resourceUri + "/collabs/", updateEntity);
|
||||||
// template = createTemplate(newCollab + ":admin");
|
|
||||||
// //add collab again with the new user expecting the Exception
|
final TestRestTemplate newCollabTemplate = this.restTemplate.withBasicAuth(newCollab.getEmail(), newCollab.getPassword());
|
||||||
// try {
|
final ResponseEntity<Void> exchange = newCollabTemplate.exchange(resourceUri + "/collabs/", HttpMethod.PUT, updateEntity, Void.class);
|
||||||
// template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
assertTrue(exchange.getStatusCode().is4xxClientError(), exchange.toString());
|
||||||
// } catch (HttpClientErrorException e) {
|
}
|
||||||
// assertEquals(e.getRawStatusCode(), 400);
|
|
||||||
// assertTrue(e.getMessage().contains("User must be owner to share mindmap"));
|
@Test
|
||||||
// }
|
public void addCollabWhitOwnerRole() {
|
||||||
// }
|
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
|
||||||
//
|
final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
|
||||||
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
|
||||||
// public void addCollabWhitOwnerRole(final @NotNull MediaType mediaType) {
|
// Create a sample map ...
|
||||||
// final HttpHeaders requestHeaders = createHeaders(mediaType);
|
final URI resourceUri = addNewMap(restTemplate, "addCollabWhitOwnerRole");
|
||||||
// RestTemplate template = createTemplate(userEmail);
|
|
||||||
//
|
// Add a new collaboration ...
|
||||||
// // Create a sample map ...
|
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
// final URI resourceUri = addNewMap(template, "addCollabWhitOwnerRole");
|
final RestCollaborationList collabs = new RestCollaborationList();
|
||||||
//
|
collabs.setMessage("Adding new permission");
|
||||||
// // Add a new collaboration ...
|
|
||||||
// requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
final String newCollab = "new-collaborator@mail.com";
|
||||||
// final RestCollaborationList collabs = new RestCollaborationList();
|
String role = "owner";
|
||||||
// collabs.setMessage("Adding new permission");
|
|
||||||
//
|
addCollabToList(newCollab, role, collabs);
|
||||||
// final String newCollab = "new-collaborator@mail.com";
|
|
||||||
// String role = "owner";
|
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||||
//
|
final ResponseEntity<RestCollaborationList> collabsList = restTemplate.exchange(resourceUri + "/collabs/", HttpMethod.PUT, updateEntity, RestCollaborationList.class);
|
||||||
// addCollabToList(newCollab, role, collabs);
|
assertTrue(collabsList.getStatusCode().is4xxClientError());
|
||||||
//
|
}
|
||||||
// final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
|
||||||
// try {
|
|
||||||
// template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
|
||||||
// } catch (HttpClientErrorException e) {
|
|
||||||
// assertEquals(e.getRawStatusCode(), 400);
|
|
||||||
// assertTrue(e.getMessage().contains("Collab email can not be change"));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
private String changeMapTitle(final HttpHeaders requestHeaders, final MediaType mediaType, final TestRestTemplate template, final URI resourceUri) throws RestClientException {
|
private String changeMapTitle(final HttpHeaders requestHeaders, final MediaType mediaType, final TestRestTemplate template, final URI resourceUri) throws RestClientException {
|
||||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||||
final String result = "New map to change title - " + mediaType;
|
final String result = "New map to change title - " + mediaType;
|
||||||
@ -791,7 +790,7 @@ public class RestMindmapControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RestMindmap findMap(@NotNull HttpHeaders requestHeaders, @NotNull TestRestTemplate template, URI resourceUri) {
|
private RestMindmap findMap(@NotNull HttpHeaders requestHeaders, @NotNull TestRestTemplate template, URI resourceUri) {
|
||||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
final HttpEntity<RestMindmap> findMapEntity = new HttpEntity<>(requestHeaders);
|
||||||
final ResponseEntity<RestMindmap> response = template.exchange("http://localhost:8081/" + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
final ResponseEntity<RestMindmap> response = template.exchange("http://localhost:8081/" + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||||
|
|
||||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user