More tests fixed.

This commit is contained in:
Paulo Gustavo Veiga 2024-02-03 14:51:59 -08:00
parent 51e2732ae2
commit 80c30daece
4 changed files with 41 additions and 40 deletions

View File

@ -12,7 +12,7 @@ spring.sql.init.mode=always
spring.sql.init.platform=hsqldb spring.sql.init.platform=hsqldb
# LOG # LOG
logging.level.root=DEBUG logging.level.root=TRACE
logging.level.org.apache.tomcat=INFO logging.level.org.apache.tomcat=INFO
################################################################################## ##################################################################################

View File

@ -94,6 +94,8 @@ public class RestAccountControllerTest {
result = findUserByEmail(requestHeaders, templateRest, restUser.getEmail()); result = findUserByEmail(requestHeaders, templateRest, restUser.getEmail());
assertEquals(result.getBody().getEmail(), restUser.getEmail(), "Returned object object seems not be the same."); assertEquals(result.getBody().getEmail(), restUser.getEmail(), "Returned object object seems not be the same.");
// Assign generated id ...
restUser.setId(result.getBody().getId());
return restUser; return restUser;
} }

View File

@ -17,7 +17,6 @@ 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.util.DefaultUriBuilderFactory; import org.springframework.web.util.DefaultUriBuilderFactory;
import java.net.URI; import java.net.URI;

View File

@ -30,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
@ -90,7 +90,8 @@ public class RestMindmapControllerTest {
final URI resourceUri = addNewMap(restTemplate, title1); final URI resourceUri = addNewMap(restTemplate, title1);
// Now remove it ... // Now remove it ...
restTemplate.delete(resourceUri.toString()); final ResponseEntity<String> exchange = restTemplate.exchange(resourceUri.toString(), HttpMethod.DELETE, null, String.class);
assertTrue(exchange.getStatusCode().is2xxSuccessful(), "Status code:" + exchange.getStatusCode());
// Check that has been removed ... // Check that has been removed ...
try { try {
@ -249,7 +250,8 @@ public class RestMindmapControllerTest {
addNewMap(secondTemplate, title2); addNewMap(secondTemplate, title2);
final TestRestTemplate superadminTemplate = this.restTemplate.withBasicAuth("admin@wisemapping.org", "test"); final TestRestTemplate superadminTemplate = this.restTemplate.withBasicAuth("admin@wisemapping.org", "test");
superadminTemplate.delete("/admin/users/" + secondUser.getId()); final ResponseEntity<String> 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 ... // Validate that the two maps are there ...
final RestMindmapList body = fetchMaps(requestHeaders, firstUser); final RestMindmapList body = fetchMaps(requestHeaders, firstUser);
@ -371,7 +373,8 @@ public class RestMindmapControllerTest {
assertEquals(responseCollbs.getCount(), 2); assertEquals(responseCollbs.getCount(), 2);
// Now, remove it ... // Now, remove it ...
restTemplate.delete(resourceUri + "/collabs?email=" + newCollab); final ResponseEntity<String> exchange = restTemplate.exchange(resourceUri + "/collabs?email=" + newCollab, HttpMethod.DELETE, null, String.class);
assertTrue(exchange.getStatusCode().is2xxSuccessful());
// Check that it has been removed ... // Check that it has been removed ...
final ResponseEntity<RestCollaborationList> afterDeleteResponse = fetchCollabs(requestHeaders, restTemplate, resourceUri); final ResponseEntity<RestCollaborationList> afterDeleteResponse = fetchCollabs(requestHeaders, restTemplate, resourceUri);
@ -491,7 +494,9 @@ public class RestMindmapControllerTest {
restTemplate.postForLocation("/api/restfull/maps/" + mapId + "/labels", labelEntity); restTemplate.postForLocation("/api/restfull/maps/" + mapId + "/labels", labelEntity);
// Remove label from map // Remove label from map
restTemplate.delete("/api/restfull//maps/" + mapId + "/labels/" + labelId); final ResponseEntity<String> exchange = restTemplate.exchange("/api/restfull//maps/" + mapId + "/labels/" + labelId, HttpMethod.DELETE, null, String.class);
assertTrue(exchange.getStatusCode().is2xxSuccessful());
Optional<RestMindmapInfo> mindmapInfo = fetchMap(requestHeaders, restTemplate, mapId); Optional<RestMindmapInfo> mindmapInfo = fetchMap(requestHeaders, restTemplate, mapId);
assertEquals(0, mindmapInfo.get().getLabels().size()); assertEquals(0, mindmapInfo.get().getLabels().size());
@ -574,8 +579,7 @@ public class RestMindmapControllerTest {
updateEntity = new HttpEntity<>(collabs, requestHeaders); updateEntity = new HttpEntity<>(collabs, requestHeaders);
restTemplate.postForLocation(resourceUri + "/collabs/", updateEntity); restTemplate.postForLocation(resourceUri + "/collabs/", updateEntity);
final RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, restTemplate, resourceUri);
RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, restTemplate, resourceUri);
// Has been another-collaboration list updated ? // Has been another-collaboration list updated ?
assertTrue(responseCollbs.getCollaborations().stream().anyMatch(x -> x.getEmail().equals("another-collab@example.com"))); assertTrue(responseCollbs.getCollaborations().stream().anyMatch(x -> x.getEmail().equals("another-collab@example.com")));
@ -584,9 +588,8 @@ public class RestMindmapControllerTest {
@Test @Test
@Disabled public void updateProperties() throws IOException, WiseMappingException {
public void updateProperties(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { final HttpHeaders requestHeaders = createHeaders(MediaType.APPLICATION_JSON);
final HttpHeaders requestHeaders = createHeaders(mediaType);
final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword()); final TestRestTemplate restTemplate = this.restTemplate.withBasicAuth(user.getEmail(), user.getPassword());
// Create a sample map ... // Create a sample map ...
@ -614,32 +617,29 @@ public class RestMindmapControllerTest {
assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties()); assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties());
} }
//
// @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function") @Test
// public void batchDelete(final @NotNull MediaType mediaType) { // Configure media types ... public void batchDelete() {
// 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 title1 = "Batch delete map 1"; final String title1 = "Batch delete map 1";
// addNewMap(template, title1); addNewMap(restTemplate, title1);
//
// final String title2 = "Batch delete map 2"; final String title2 = "Batch delete map 2";
// addNewMap(template, title2); addNewMap(restTemplate, title2);
//
// final String maps = fetchMaps(requestHeaders, restTemplate).getMindmapsInfo().stream().map(map -> String.valueOf(map.getId())).collect(Collectors.joining(","));
// String maps;
// maps = fetchMaps(requestHeaders, template).getMindmapsInfo().stream().map(map -> { final ResponseEntity<String> exchange = restTemplate.exchange("/api/restfull/maps/batch?ids=" + maps , HttpMethod.DELETE, null, String.class);
// return String.valueOf(map.getId()); assertTrue(exchange.getStatusCode().is2xxSuccessful(), "Status code:" + exchange.getStatusCode() + " - " + exchange.getBody());
// }).collect(Collectors.joining(","));
// // Validate that the two maps are there ...
// final RestMindmapList body = fetchMaps(requestHeaders, restTemplate);
// template.delete(BASE_REST_URL + "/maps/batch?ids=" + maps); assertEquals(0, body.getMindmapsInfo().size());
// }
// // 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") // @Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
// public void updatePublishState(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... // public void updatePublishState(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ...