Fix more tests.

This commit is contained in:
Paulo Gustavo Veiga 2024-01-22 22:46:38 -08:00
parent d49766463a
commit cdbeaf5216
2 changed files with 69 additions and 72 deletions

View File

@ -135,4 +135,14 @@ public class RestErrors {
return gErrors; return gErrors;
} }
@Override
public String toString() {
return "RestErrors{" +
"errors=" + errors +
", gErrors=" + gErrors +
", messageSource=" + messageSource +
", gSeverity=" + gSeverity +
", _debugInfo='" + _debugInfo + '\'' +
'}';
}
} }

View File

@ -6,10 +6,7 @@ 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.RestMindmap; import com.wisemapping.rest.model.*;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.rest.model.RestUser;
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;
@ -18,18 +15,16 @@ import org.springframework.beans.factory.annotation.Autowired;
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.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.DefaultUriBuilderFactory;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static com.wisemapping.test.rest.RestHelper.createHeaders; import static com.wisemapping.test.rest.RestHelper.createHeaders;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.fail;
import static org.testng.AssertJUnit.assertEquals;
@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 {
@ -117,7 +112,6 @@ public class RestMindmapControllerTest {
assertEquals(newTitle, map.getTitle()); assertEquals(newTitle, map.getTitle());
} }
@Test @Test
public void validateMapsCreation() { // Configure media types ... public void validateMapsCreation() { // Configure media types ...
final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON); final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
@ -129,15 +123,10 @@ public class RestMindmapControllerTest {
addNewMap(restTemplate, title); addNewMap(restTemplate, title);
// Add map with same name ... // Add map with same name ...
try {
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<>(requestHeaders); HttpEntity<RestMindmap> createUserEntity = new HttpEntity<>(requestHeaders);
restTemplate.postForLocation("/api/restfull/maps?title=" + title, createUserEntity); final ResponseEntity<String> response = restTemplate.exchange("/api/restfull/maps?title=" + title, HttpMethod.POST, createUserEntity, String.class);
} catch (HttpClientErrorException cause) { assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
final String responseBodyAsString = cause.getResponseBodyAsString(); assertTrue(Objects.requireNonNull(response.getBody()).contains("You have already a map with the same name"));
assert (responseBodyAsString.contains("You have already a map"));
return;
}
fail("Wrong response");
} }
@ -160,60 +149,58 @@ public class RestMindmapControllerTest {
assertEquals(newDescription, map.getDescription()); assertEquals(newDescription, map.getDescription());
} }
//
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") @Test
// public void updateMapXml(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... public void updateMapXml() throws IOException { // Configure media types ...
// 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 title = "Update XML sample " + mediaType; final String title = "Update XML sample";
// final URI resourceUri = addNewMap(template, title); final URI resourceUri = addNewMap(restTemplate, title);
//
// // Update map xml content ... // Update map xml content ...
// final String resourceUrl = HOST_PORT + resourceUri.toString(); final String resourceUrl = resourceUri.toString();
// String newXmlContent = updateMapDocument(requestHeaders, template, resourceUrl); String newXmlContent = updateMapDocument(requestHeaders, restTemplate, resourceUrl, null);
//
// // Check that the map has been updated ... // Check that the map has been updated ...
// final RestMindmap response = findMap(requestHeaders, template, resourceUri); final RestMindmap response = findMap(requestHeaders, restTemplate, resourceUri);
// assertEquals(response.getXml(), newXmlContent); assertEquals(response.getXml(), newXmlContent);
// } }
//
// private String updateMapDocument(final HttpHeaders requestHeaders, final RestTemplate template, final String resourceUrl, String content) throws RestClientException { private String updateMapDocument(final HttpHeaders requestHeaders, final TestRestTemplate template, final String resourceUrl, 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);
// return newXmlContent; return newXmlContent;
// } }
//
// private String updateMapDocument(final HttpHeaders requestHeaders, final RestTemplate template, final String resourceUrl) throws RestClientException {
// return updateMapDocument(requestHeaders, template, resourceUrl, null); @Test
// } public void cloneMap() throws IOException { // Configure media types ...
// final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
// public void cloneMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
// final HttpHeaders requestHeaders = createHeaders(mediaType); // Create a sample map ...
// final RestTemplate template = createTemplate(userEmail); final String title = "Map to clone sample ";
// final String xml = "<map><node text='this is a cloned map'></map>";
// // Create a sample map ... final URI newMapUri = addNewMap(restTemplate, title, xml);
// final String title = "Map to clone sample " + mediaType;
// final String xml = "<map><node text='this is a cloned map'></map>"; // Clone map ...
// final URI newMapUri = addNewMap(template, title, xml); final RestMindmapInfo restMindmap = new RestMindmapInfo();
// restMindmap.setTitle("Cloned map but with previous content.");
// // Clone map ... restMindmap.setDescription("Cloned map desc");
// final RestMindmapInfo restMindmap = new RestMindmapInfo();
// restMindmap.setTitle("Cloned map but with previous content." + mediaType); // Create a new map ...
// restMindmap.setDescription("Cloned map desc"); final HttpEntity<RestMindmapInfo> cloneEntity = new HttpEntity<>(restMindmap, requestHeaders);
// final URI clonedMapUri = restTemplate.postForLocation(newMapUri, cloneEntity);
// // Create a new map ...
// final HttpEntity<RestMindmapInfo> cloneEntity = new HttpEntity<>(restMindmap, requestHeaders); // Check that the map has been updated ...
// final URI clonedMapUri = template.postForLocation(HOST_PORT + newMapUri, cloneEntity); final RestMindmap response = findMap(requestHeaders, restTemplate, clonedMapUri);
// assertEquals(response.getXml(), xml);
// // Check that the map has been updated ... }
// final RestMindmap response = findMap(requestHeaders, template, clonedMapUri);
// assertEquals(response.getXml(), xml);
// }
// //
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") // @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
// public void updateStarred(final @NotNull MediaType mediaType) { // Configure media types ... // public void updateStarred(final @NotNull MediaType mediaType) { // Configure media types ...