Fix more tests.

This commit is contained in:
Paulo Gustavo Veiga 2024-02-03 15:13:38 -08:00
parent 80c30daece
commit f528abaa44

View File

@ -1,20 +1,13 @@
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;
@ -172,8 +165,9 @@ public class RestMindmapControllerTest {
assertEquals(response.getXml(), newXmlContent); assertEquals(response.getXml(), newXmlContent);
} }
private String updateMapDocument(final HttpHeaders requestHeaders, final TestRestTemplate template, final String resourceUrl, String content) throws RestClientException { private String updateMapDocument(final HttpHeaders requestHeaders, final TestRestTemplate template, final String resourceUrl, final String content) throws RestClientException {
requestHeaders.setContentType(MediaType.TEXT_PLAIN); requestHeaders.setContentType(MediaType.TEXT_PLAIN);
final String newXmlContent = content != null ? content : "<map>this is not valid</map>"; final String newXmlContent = content != null ? content : "<map>this is not valid</map>";
HttpEntity<String> updateEntity = new HttpEntity<>(newXmlContent, requestHeaders); HttpEntity<String> updateEntity = new HttpEntity<>(newXmlContent, requestHeaders);
template.put(resourceUrl + "/document/xml", updateEntity); template.put(resourceUrl + "/document/xml", updateEntity);
@ -182,7 +176,7 @@ public class RestMindmapControllerTest {
@Test @Test
public void cloneMap() throws IOException { // Configure media types ... public void cloneMap() throws IOException {
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON); final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword()); final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
@ -198,7 +192,10 @@ public class RestMindmapControllerTest {
// Create a new map ... // Create a new map ...
final HttpEntity<RestMindmapInfo> cloneEntity = new HttpEntity<>(restMindmap, requestHeaders); final HttpEntity<RestMindmapInfo> cloneEntity = new HttpEntity<>(restMindmap, requestHeaders);
final URI clonedMapUri = restTemplate.postForLocation(newMapUri, cloneEntity); final ResponseEntity<Void> exchange = restTemplate.exchange(newMapUri.toString(), HttpMethod.POST, cloneEntity, Void.class);
assertTrue(exchange.getStatusCode().is2xxSuccessful());
URI clonedMapUri = exchange.getHeaders().getLocation();
// Check that the map has been updated ... // Check that the map has been updated ...
final RestMindmap response = findMap(requestHeaders, restTemplate, clonedMapUri); final RestMindmap response = findMap(requestHeaders, restTemplate, clonedMapUri);
@ -288,7 +285,7 @@ public class RestMindmapControllerTest {
// Check that the map has been updated ... // Check that the map has been updated ...
HttpEntity<RestUser> findMapEntity = new HttpEntity<>(requestHeaders); HttpEntity<RestUser> findMapEntity = new HttpEntity<>(requestHeaders);
final ResponseEntity<RestMindmap> response = restTemplate.exchange(resourceUri, HttpMethod.GET, findMapEntity, RestMindmap.class); final ResponseEntity<RestMindmap> response = restTemplate.exchange(resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
assertEquals(Objects.requireNonNull(response.getBody()).getXml(), mapToUpdate.getXml()); assertEquals(Objects.requireNonNull(response.getBody()).getXml(), mapToUpdate.getXml());
assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties()); assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties());
@ -449,7 +446,7 @@ public class RestMindmapControllerTest {
@NotNull @NotNull
private ResponseEntity<RestCollaborationList> fetchCollabs(HttpHeaders requestHeaders, TestRestTemplate template, URI resourceUri) { private ResponseEntity<RestCollaborationList> fetchCollabs(HttpHeaders requestHeaders, TestRestTemplate template, URI resourceUri) {
final HttpEntity<RestCollaborationList> findCollabs = new HttpEntity(requestHeaders); final HttpEntity<RestCollaborationList> findCollabs = new HttpEntity<>(requestHeaders);
return template.exchange(resourceUri + "/collabs", HttpMethod.GET, findCollabs, RestCollaborationList.class); return template.exchange(resourceUri + "/collabs", HttpMethod.GET, findCollabs, RestCollaborationList.class);
} }
@ -610,7 +607,7 @@ public class RestMindmapControllerTest {
// Check that the map has been updated ... // Check that the map has been updated ...
HttpEntity<RestUser> findMapEntity = new HttpEntity<>(requestHeaders); HttpEntity<RestUser> findMapEntity = new HttpEntity<>(requestHeaders);
final ResponseEntity<RestMindmap> response = restTemplate.exchange(resourceUri, HttpMethod.GET, findMapEntity, RestMindmap.class); final ResponseEntity<RestMindmap> response = restTemplate.exchange(resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
assertEquals(response.getBody().getTitle(), mapToUpdate.getTitle()); assertEquals(response.getBody().getTitle(), mapToUpdate.getTitle());
assertEquals(response.getBody().getDescription(), mapToUpdate.getDescription()); assertEquals(response.getBody().getDescription(), mapToUpdate.getDescription());
assertEquals(response.getBody().getXml(), mapToUpdate.getXml()); assertEquals(response.getBody().getXml(), mapToUpdate.getXml());
@ -640,45 +637,41 @@ public class RestMindmapControllerTest {
assertEquals(0, body.getMindmapsInfo().size()); assertEquals(0, body.getMindmapsInfo().size());
} }
//
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") @Test
// public void updatePublishState(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... public void updatePublishState() {
// 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 String mapTitle = "updatePublishState"; final String mapTitle = "updatePublishState";
// final URI mindmapUri = addNewMap(template, mapTitle); final URI mindmapUri = addNewMap(restTemplate, mapTitle);
// final String mapId = mindmapUri.getPath().replace("/api/restfull/maps/", "");
// // Change map status ...
// // Change map status ... requestHeaders.setContentType(MediaType.TEXT_PLAIN);
// requestHeaders.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> updateEntity = new HttpEntity<>(Boolean.TRUE.toString(), requestHeaders);
// //final String newPublicState = "true";
// final HttpEntity<String> updateEntity = new HttpEntity<>(Boolean.TRUE.toString(), requestHeaders); final ResponseEntity<String> exchange = restTemplate.exchange(mindmapUri + "/publish", HttpMethod.PUT, updateEntity, String.class);
// template.put(HOST_PORT + mindmapUri + "/publish", updateEntity); assertTrue(exchange.getStatusCode().is2xxSuccessful());
// }
//// //fetch public view
//// final HttpEntity findMapEntity = new HttpEntity(requestHeaders); @Test
//// ResponseEntity<String> publicView = template.exchange(HOST_PORT + mapId + "/public", HttpMethod.GET, findMapEntity, String.class); public void fetchMapHistory() {
//// assertNotNull(publicView.getBody()); final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
//// assertEquals(publicView.getStatusCodeValue(), 200); final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
// }
// // Create a sample map ...
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") final URI resourceUri = addNewMap(restTemplate, "Map to change title");
// public void fetchMapHistory(final @NotNull MediaType mediaType) { // Configure media types ... updateMapDocument(requestHeaders, restTemplate, resourceUri.toString(), null);
// final HttpHeaders requestHeaders = createHeaders(mediaType);
// final RestTemplate template = createTemplate(userEmail); //fetch map history
// final HttpEntity<RestMindmapHistoryList> findMapEntity = new HttpEntity<>(requestHeaders);
// // Create a sample map ... final ResponseEntity<RestMindmapHistoryList> maps = restTemplate.exchange(resourceUri + "/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
// final URI resourceUri = addNewMap(template, "Map to change title - " + mediaType); assertTrue(maps.getStatusCode().is2xxSuccessful(), maps.toString());
//
// updateMapDocument(requestHeaders, template, HOST_PORT + resourceUri.toString()); assertEquals(1, Objects.requireNonNull(maps.getBody()).getCount());
// }
// //fetch map history
// final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
// final ResponseEntity<RestMindmapHistoryList> maps = template.exchange(HOST_PORT + resourceUri + "/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
// assertEquals(maps.getBody().getCount(), 1);
// }
// //
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") // @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
// public void updateRevertMindmap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... // public void updateRevertMindmap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...