Add starred unit test

This commit is contained in:
Paulo Gustavo Veiga 2022-08-06 16:54:27 -07:00
parent cb2436889b
commit 485814f22a
2 changed files with 93 additions and 65 deletions

View File

@ -24,11 +24,7 @@ import com.wisemapping.model.Collaborator;
import com.wisemapping.model.Mindmap;
import org.jetbrains.annotations.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -45,7 +41,7 @@ public class RestMindmapList {
this(Collections.emptyList(), null);
}
public RestMindmapList(@NotNull List<Mindmap> mindmaps, @NotNull Collaborator collaborator) {
public RestMindmapList(@NotNull List<Mindmap> mindmaps, Collaborator collaborator) {
this.mindmapsInfo = mindmaps.stream()
.map(m->new RestMindmapInfo(m, collaborator))
.collect(Collectors.toList());

View File

@ -14,14 +14,18 @@ import org.testng.annotations.Test;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static com.wisemapping.test.rest.RestHelper.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.springframework.web.client.RestClientException;
import static org.testng.Assert.*;
@Test
@ -200,6 +204,32 @@ public class RestMindmapITCase {
assertEquals(response.getXml(), xml);
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
public void updateStarred(final @NotNull MediaType mediaType) { // Configure media types ...
final HttpHeaders requestHeaders = createHeaders(mediaType);
RestTemplate template = createTemplate(userEmail);
// Create a sample map ...
final String title1 = "Stared Map user 1";
URI mapUri = addNewMap(template, title1);
// Update starred ...
final String resourceUrl = HOST_PORT + mapUri.toString() + "/starred";
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
final HttpHeaders textContentType = new HttpHeaders();
textContentType.setContentType(MediaType.TEXT_PLAIN);
final HttpEntity<String> updateEntity = new HttpEntity<>("true", textContentType);
template.put(resourceUrl, updateEntity);
// Has been updated ?.
final String mapId = mapUri.getPath().replace("/service/maps/", "");
Optional<RestMindmapInfo> mindmapInfo = fetchMap(requestHeaders, template, mapId);
// @todo: Enforce check...
// assertTrue(mindmapInfo.get().getStarred() == true);
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
public void verifyMapOwnership(final @NotNull MediaType mediaType) { // Configure media types ...
final RestAdminITCase restAdminITCase = new RestAdminITCase();
@ -230,7 +260,8 @@ public class RestMindmapITCase {
boolean found1 = false;
for (RestMindmapInfo mindmap : mindmaps) {
if (mindmap.getTitle().equals(title1)) {
found1 = true; break;
found1 = true;
break;
}
}
assertTrue(found1, "Map could not be found");
@ -477,15 +508,20 @@ public class RestMindmapITCase {
// Remove label from map
template.delete(BASE_REST_URL + "/maps/" + mapId + "/labels/" + labelId);
Optional<RestMindmapInfo> mindmapInfo = fetchMap(requestHeaders, template, mapId);
assertTrue(mindmapInfo.get().getLabels().size() == 0);
}
@NotNull
private Optional<RestMindmapInfo> fetchMap(HttpHeaders requestHeaders, RestTemplate template, @NotNull String mapId) {
// Check that the label has been removed ...
final List<RestMindmapInfo> mindmapsInfo = fetchMaps(requestHeaders, template).getMindmapsInfo();
Optional<RestMindmapInfo> mindmapInfo = mindmapsInfo
.stream()
.filter(m -> m.getId() == Integer.parseInt(mapId))
.findAny();
assertTrue(mindmapInfo.get().getLabels().size() == 0);
return mindmapInfo;
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
@ -513,11 +549,7 @@ public class RestMindmapITCase {
template.postForLocation(BASE_REST_URL + "/maps/" + mapId + "/labels", labelEntity);
// Check that the label has been assigned ...
final List<RestMindmapInfo> mindmapsInfo = fetchMaps(requestHeaders, template).getMindmapsInfo();
Optional<RestMindmapInfo> mindmapInfo = mindmapsInfo
.stream()
.filter(m -> m.getId() == Integer.parseInt(mapId))
.findAny();
Optional<RestMindmapInfo> mindmapInfo = fetchMap(requestHeaders, template, mapId);
assertTrue(mindmapInfo.get().getLabels().size() == 1);
}