From 80c30daecef937e71db269cc3894226710a2c7f6 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 3 Feb 2024 14:51:59 -0800 Subject: [PATCH] More tests fixed. --- .../src/main/resources/application.properties | 2 +- .../test/rest/RestAccountControllerTest.java | 4 +- .../test/rest/RestLabelControllerTest.java | 1 - .../test/rest/RestMindmapControllerTest.java | 74 +++++++++---------- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/wise-webapp/src/main/resources/application.properties b/wise-webapp/src/main/resources/application.properties index 34375dd7..69842795 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=DEBUG +logging.level.root=TRACE logging.level.org.apache.tomcat=INFO ################################################################################## diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountControllerTest.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountControllerTest.java index 1dda7003..1a577610 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountControllerTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountControllerTest.java @@ -46,7 +46,7 @@ public class RestAccountControllerTest { @Autowired private TestRestTemplate restTemplate; - static public RestAccountControllerTest create(@NotNull TestRestTemplate restTemplate) { + static public RestAccountControllerTest create(@NotNull TestRestTemplate restTemplate) { final RestAccountControllerTest result = new RestAccountControllerTest(); result.restTemplate = restTemplate; return result; @@ -94,6 +94,8 @@ public class RestAccountControllerTest { result = findUserByEmail(requestHeaders, templateRest, restUser.getEmail()); assertEquals(result.getBody().getEmail(), restUser.getEmail(), "Returned object object seems not be the same."); + // Assign generated id ... + restUser.setId(result.getBody().getId()); return restUser; } diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java index c694a86c..6114fd61 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java @@ -17,7 +17,6 @@ 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.util.DefaultUriBuilderFactory; import java.net.URI; 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 ea011ac7..5c37751d 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 @@ -30,12 +30,12 @@ import java.util.stream.Collectors; import static com.wisemapping.test.rest.RestHelper.createHeaders; 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 { private RestUser user; - @Autowired + // @Autowired private TestRestTemplate restTemplate; @BeforeEach @@ -90,7 +90,8 @@ public class RestMindmapControllerTest { final URI resourceUri = addNewMap(restTemplate, title1); // Now remove it ... - restTemplate.delete(resourceUri.toString()); + final ResponseEntity exchange = restTemplate.exchange(resourceUri.toString(), HttpMethod.DELETE, null, String.class); + assertTrue(exchange.getStatusCode().is2xxSuccessful(), "Status code:" + exchange.getStatusCode()); // Check that has been removed ... try { @@ -249,7 +250,8 @@ public class RestMindmapControllerTest { addNewMap(secondTemplate, title2); final TestRestTemplate superadminTemplate = this.restTemplate.withBasicAuth("admin@wisemapping.org", "test"); - superadminTemplate.delete("/admin/users/" + secondUser.getId()); + final ResponseEntity exchange = superadminTemplate.exchange("/api/restfull/admin/users/" + secondUser.getId(), HttpMethod.DELETE, null, String.class); + assertTrue(exchange.getStatusCode().is2xxSuccessful(), "Status Code:" + exchange.getStatusCode() + "- " + exchange.getBody()); // Validate that the two maps are there ... final RestMindmapList body = fetchMaps(requestHeaders, firstUser); @@ -371,7 +373,8 @@ public class RestMindmapControllerTest { assertEquals(responseCollbs.getCount(), 2); // Now, remove it ... - restTemplate.delete(resourceUri + "/collabs?email=" + newCollab); + final ResponseEntity exchange = restTemplate.exchange(resourceUri + "/collabs?email=" + newCollab, HttpMethod.DELETE, null, String.class); + assertTrue(exchange.getStatusCode().is2xxSuccessful()); // Check that it has been removed ... final ResponseEntity afterDeleteResponse = fetchCollabs(requestHeaders, restTemplate, resourceUri); @@ -491,7 +494,9 @@ public class RestMindmapControllerTest { restTemplate.postForLocation("/api/restfull/maps/" + mapId + "/labels", labelEntity); // Remove label from map - restTemplate.delete("/api/restfull//maps/" + mapId + "/labels/" + labelId); + final ResponseEntity exchange = restTemplate.exchange("/api/restfull//maps/" + mapId + "/labels/" + labelId, HttpMethod.DELETE, null, String.class); + assertTrue(exchange.getStatusCode().is2xxSuccessful()); + Optional mindmapInfo = fetchMap(requestHeaders, restTemplate, mapId); assertEquals(0, mindmapInfo.get().getLabels().size()); @@ -574,8 +579,7 @@ public class RestMindmapControllerTest { updateEntity = new HttpEntity<>(collabs, requestHeaders); restTemplate.postForLocation(resourceUri + "/collabs/", updateEntity); - - RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, restTemplate, resourceUri); + final RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, restTemplate, resourceUri); // Has been another-collaboration list updated ? assertTrue(responseCollbs.getCollaborations().stream().anyMatch(x -> x.getEmail().equals("another-collab@example.com"))); @@ -584,9 +588,8 @@ public class RestMindmapControllerTest { @Test - @Disabled - public void updateProperties(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { - final HttpHeaders requestHeaders = createHeaders(mediaType); + public void updateProperties() throws IOException, WiseMappingException { + final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON); final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword()); // Create a sample map ... @@ -614,34 +617,31 @@ public class RestMindmapControllerTest { assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties()); } + + @Test + public void batchDelete() { + final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON); + final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword()); + + // Create a sample map ... + final String title1 = "Batch delete map 1"; + addNewMap(restTemplate, title1); + + final String title2 = "Batch delete map 2"; + addNewMap(restTemplate, title2); + + final String maps = fetchMaps(requestHeaders, restTemplate).getMindmapsInfo().stream().map(map -> String.valueOf(map.getId())).collect(Collectors.joining(",")); + + final ResponseEntity exchange = restTemplate.exchange("/api/restfull/maps/batch?ids=" + maps , HttpMethod.DELETE, null, String.class); + assertTrue(exchange.getStatusCode().is2xxSuccessful(), "Status code:" + exchange.getStatusCode() + " - " + exchange.getBody()); + + // Validate that the two maps are there ... + final RestMindmapList body = fetchMaps(requestHeaders, restTemplate); + assertEquals(0, body.getMindmapsInfo().size()); + } + // // @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") -// public void batchDelete(final @NotNull MediaType mediaType) { // Configure media types ... -// final HttpHeaders requestHeaders = createHeaders(mediaType); -// final RestTemplate template = createTemplate(userEmail); -// -// // Create a sample map ... -// final String title1 = "Batch delete map 1"; -// addNewMap(template, title1); -// -// final String title2 = "Batch delete map 2"; -// addNewMap(template, title2); -// -// -// String maps; -// maps = fetchMaps(requestHeaders, template).getMindmapsInfo().stream().map(map -> { -// return String.valueOf(map.getId()); -// }).collect(Collectors.joining(",")); -// -// -// template.delete(BASE_REST_URL + "/maps/batch?ids=" + maps); -// -// // Validate that the two maps are there ... -// final RestMindmapList body = fetchMaps(requestHeaders, template); -// assertEquals(body.getMindmapsInfo().size(), 0); -// } -// -// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") // public void updatePublishState(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... // final HttpHeaders requestHeaders = createHeaders(mediaType); // final RestTemplate template = createTemplate(userEmail);