From 56e4970861b7d1cea03d5389f405a3dc9e9f25a6 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 22 Jan 2024 23:11:20 -0800 Subject: [PATCH] Fix more test. --- .../src/main/resources/application.properties | 2 +- .../test/rest/RestMindmapControllerTest.java | 60 +++++++++---------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/wise-webapp/src/main/resources/application.properties b/wise-webapp/src/main/resources/application.properties index 69842795..eb6b13ec 100755 --- a/wise-webapp/src/main/resources/application.properties +++ b/wise-webapp/src/main/resources/application.properties @@ -12,7 +12,7 @@ spring.sql.init.mode=always spring.sql.init.platform=hsqldb # LOG -logging.level.root=TRACE +logging.level.root=INFO logging.level.org.apache.tomcat=INFO ################################################################################## diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapControllerTest.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapControllerTest.java index e4cf785d..ca686e57 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapControllerTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapControllerTest.java @@ -16,6 +16,7 @@ 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.http.*; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.util.DefaultUriBuilderFactory; @@ -390,38 +391,35 @@ public class RestMindmapControllerTest { return newCollab; } - // -// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") -// public void deleteCollabsWithInvalidEmail(final @NotNull MediaType mediaType) { -// final HttpHeaders requestHeaders = createHeaders(mediaType); -// final RestTemplate template = createTemplate(userEmail); + + @Test + public void deleteCollabsWithInvalidEmail() { + final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON); + final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword()); + + // Create a sample map ... + final URI resourceUri = addNewMap(restTemplate, "deleteCollabsWithInvalidEmail"); + + // Remove with invalid email ... + try { + restTemplate.delete(resourceUri + "/collabs?email=invalidEmail"); + } catch (HttpClientErrorException e) { + assertEquals(e.getRawStatusCode(), 400); + assertTrue(e.getMessage().contains("Invalid email exception:")); + } + + // Check that it has been removed ... + final ResponseEntity afterDeleteResponse = fetchCollabs(requestHeaders, restTemplate, resourceUri); + assertEquals(Objects.requireNonNull(afterDeleteResponse.getBody()).getCollaborations().size(), 1); + } + +// @Test +// public void deleteCollabsWithoutOwnerPermission() { +// final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON); +// final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword()); // // // Create a sample map ... -// final URI resourceUri = addNewMap(template, "deleteCollabsWithInvalidEmail"); -// -// // Remove with invalid email ... -// try { -// -// template.delete(HOST_PORT + resourceUri + "/collabs?email=invalidEmail"); -// } catch (HttpClientErrorException e) { -// assertEquals(e.getRawStatusCode(), 400); -// assertTrue(e.getMessage().contains("Invalid email exception:")); -// } -// -// // Check that it has been removed ... -// final ResponseEntity afterDeleteResponse = fetchCollabs(requestHeaders, template, resourceUri); -// assertEquals(afterDeleteResponse.getBody().getCollaborations().size(), 1); -// } -// -// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") -// public void deleteCollabsWithoutOwnerPermission(final @NotNull MediaType mediaType) { -// -// -// final HttpHeaders requestHeaders = createHeaders(mediaType); -// RestTemplate template = createTemplate(userEmail); -// -// // Create a sample map ... -// final URI resourceUri = addNewMap(template, "deleteWithoutOwnerPermission"); +// final URI resourceUri = addNewMap(restTemplate, "deleteWithoutOwnerPermission"); // // final String newCollab = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON); // template = createTemplate(newCollab + ":admin"); @@ -453,7 +451,7 @@ public class RestMindmapControllerTest { // assertTrue(e.getMessage().contains("Can not remove owner collab")); // } // } -// + @NotNull private ResponseEntity fetchCollabs(HttpHeaders requestHeaders, TestRestTemplate template, URI resourceUri) { final HttpEntity findCollabs = new HttpEntity(requestHeaders);