mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-22 11:33:47 +01:00
Add starred unit test
This commit is contained in:
parent
cb2436889b
commit
485814f22a
@ -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());
|
||||
|
@ -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
|
||||
@ -166,12 +170,12 @@ public class RestMindmapITCase {
|
||||
|
||||
private String updateMapDocument(final HttpHeaders requestHeaders, final RestTemplate template, final String resourceUrl, String content) throws RestClientException {
|
||||
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);
|
||||
template.put(resourceUrl + "/document/xml", updateEntity);
|
||||
return newXmlContent;
|
||||
}
|
||||
|
||||
|
||||
private String updateMapDocument(final HttpHeaders requestHeaders, final RestTemplate template, final String resourceUrl) throws RestClientException {
|
||||
return updateMapDocument(requestHeaders, template, resourceUrl, null);
|
||||
}
|
||||
@ -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();
|
||||
@ -212,7 +242,7 @@ public class RestMindmapITCase {
|
||||
|
||||
//create another user
|
||||
RestUser secondUser = restAdminITCase.createNewUserAndGetUser(MediaType.APPLICATION_JSON);
|
||||
final RestTemplate secondTemplate = createTemplate(secondUser.getEmail()+":admin");
|
||||
final RestTemplate secondTemplate = createTemplate(secondUser.getEmail() + ":admin");
|
||||
|
||||
final String title2 = "verifyMapOwnership Map user 2";
|
||||
addNewMap(secondTemplate, title2);
|
||||
@ -221,7 +251,7 @@ public class RestMindmapITCase {
|
||||
String authorisation = "admin@wisemapping.org" + ":" + "test";
|
||||
RestTemplate superadminTemplate = createTemplate(authorisation);
|
||||
|
||||
superadminTemplate.delete(BASE_REST_URL + "/admin/users/"+secondUser.getId());
|
||||
superadminTemplate.delete(BASE_REST_URL + "/admin/users/" + secondUser.getId());
|
||||
|
||||
// Validate that the two maps are there ...
|
||||
final RestMindmapList body = fetchMaps(requestHeaders, template);
|
||||
@ -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");
|
||||
@ -364,7 +395,7 @@ public class RestMindmapITCase {
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
return newCollab;
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void deleteCollabsWithInvalidEmail(final @NotNull MediaType mediaType) {
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -375,22 +406,22 @@ public class RestMindmapITCase {
|
||||
|
||||
// Remove with invalid email ...
|
||||
try {
|
||||
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email=invalidEmail" );
|
||||
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email=invalidEmail");
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
assertTrue(e.getMessage().contains("Invalid email exception:"));
|
||||
assertTrue(e.getMessage().contains("Invalid email exception:"));
|
||||
}
|
||||
|
||||
// Check that it has been removed ...
|
||||
final ResponseEntity<RestCollaborationList> 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);
|
||||
|
||||
@ -398,15 +429,15 @@ public class RestMindmapITCase {
|
||||
final URI resourceUri = addNewMap(template, "deleteWithoutOwnerPermission");
|
||||
|
||||
final String newCollab = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
||||
template = createTemplate(newCollab+":admin");
|
||||
template = createTemplate(newCollab + ":admin");
|
||||
|
||||
// Remove with invalid email ...
|
||||
try {
|
||||
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email="+newCollab );
|
||||
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email=" + newCollab);
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
assertTrue(e.getMessage().contains("No enough permissions"));
|
||||
assertTrue(e.getMessage().contains("No enough permissions"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -419,15 +450,15 @@ public class RestMindmapITCase {
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "Map for deleteOwnerCollab");
|
||||
|
||||
// Now, remove owner collab ...
|
||||
try {
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email=" + userEmail.replace(":admin", "") );
|
||||
// Now, remove owner collab ...
|
||||
try {
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email=" + userEmail.replace(":admin", ""));
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
assertTrue(e.getMessage().contains("Can not remove owner collab"));
|
||||
assertTrue(e.getMessage().contains("Can not remove owner collab"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private ResponseEntity<RestCollaborationList> fetchCollabs(HttpHeaders requestHeaders, RestTemplate template, URI resourceUri) {
|
||||
final HttpEntity findCollabs = new HttpEntity(requestHeaders);
|
||||
@ -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);
|
||||
}
|
||||
@ -544,17 +576,17 @@ public class RestMindmapITCase {
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
|
||||
collabs = fetchAndGetCollabs(requestHeaders, template, resourceUri);
|
||||
|
||||
|
||||
//delete one collab
|
||||
collabs.setCollaborations(collabs.getCollaborations().stream().filter(c -> c.getRole().equals("owner")).collect(Collectors.toList()));
|
||||
|
||||
|
||||
//Add another collaborationMediaType
|
||||
newCollab = "another-collab@example.com";
|
||||
addCollabToList(newCollab, role, collabs);
|
||||
|
||||
//add owner to list
|
||||
addCollabToList(userEmail.replace(":admin", ""), "owner", collabs);
|
||||
|
||||
|
||||
updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.postForLocation(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
|
||||
@ -566,7 +598,7 @@ public class RestMindmapITCase {
|
||||
assertEquals(responseCollbs.getCount(), 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void updateProperties(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -609,20 +641,20 @@ public class RestMindmapITCase {
|
||||
final String title2 = "Batch delete map 2";
|
||||
addNewMap(template, title2);
|
||||
|
||||
|
||||
|
||||
String maps;
|
||||
maps = fetchMaps(requestHeaders, template).getMindmapsInfo().stream().map(map-> {
|
||||
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);
|
||||
|
||||
|
||||
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);
|
||||
@ -641,11 +673,11 @@ public class RestMindmapITCase {
|
||||
|
||||
//fetch public view
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
ResponseEntity<String> publicView = template.exchange(HOST_PORT + "/c/"+ mapId + "/public", HttpMethod.GET, findMapEntity, String.class);
|
||||
ResponseEntity<String> publicView = template.exchange(HOST_PORT + "/c/" + mapId + "/public", HttpMethod.GET, findMapEntity, String.class);
|
||||
assertNotNull(publicView.getBody());
|
||||
assertEquals(publicView.getStatusCodeValue(), 200);
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void fetchMapHistory(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -655,10 +687,10 @@ public class RestMindmapITCase {
|
||||
final URI resourceUri = addNewMap(template, "Map to change title - " + mediaType);
|
||||
|
||||
updateMapDocument(requestHeaders, template, HOST_PORT + resourceUri.toString());
|
||||
|
||||
|
||||
//fetch map history
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmapHistoryList> maps = template.exchange(HOST_PORT+resourceUri+"/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
|
||||
final ResponseEntity<RestMindmapHistoryList> maps = template.exchange(HOST_PORT + resourceUri + "/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
|
||||
assertEquals(maps.getBody().getCount(), 1);
|
||||
}
|
||||
|
||||
@ -670,26 +702,26 @@ public class RestMindmapITCase {
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "map to test revert changes");
|
||||
updateMapDocument(requestHeaders, template, HOST_PORT + resourceUri.toString(), "<map><node text='this is an xml to test revert changes service'></map>");
|
||||
|
||||
|
||||
updateMapDocument(requestHeaders, template, HOST_PORT + resourceUri.toString(), "<map><node text='this is an xml with modification to be reverted'></map>");
|
||||
|
||||
|
||||
//fetch map history
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmapHistoryList> mapHistories = template.exchange(HOST_PORT+resourceUri+"/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
|
||||
|
||||
final ResponseEntity<RestMindmapHistoryList> mapHistories = template.exchange(HOST_PORT + resourceUri + "/history/", HttpMethod.GET, findMapEntity, RestMindmapHistoryList.class);
|
||||
|
||||
//aply revert
|
||||
final HttpEntity<String> cloneEntity = new HttpEntity<>(requestHeaders);
|
||||
template.postForLocation(HOST_PORT + resourceUri+"/history/latest", cloneEntity);
|
||||
template.postForLocation(HOST_PORT + resourceUri + "/history/latest", cloneEntity);
|
||||
final RestMindmap latestStoredMap = findMap(requestHeaders, template, resourceUri);
|
||||
template.postForLocation(HOST_PORT + resourceUri+"/history/"+mapHistories.getBody().getChanges().get(1).getId(), cloneEntity);
|
||||
template.postForLocation(HOST_PORT + resourceUri + "/history/" + mapHistories.getBody().getChanges().get(1).getId(), cloneEntity);
|
||||
final RestMindmap firstVersionMap = findMap(requestHeaders, template, resourceUri);
|
||||
|
||||
//verify revert
|
||||
assertEquals(firstVersionMap.getXml(), "<map><node text='this is an xml to test revert changes service'></map>");
|
||||
assertEquals(latestStoredMap.getXml(), "<map><node text='this is an xml with modification to be reverted'></map>");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void addCollabWhitoutOwnerPermission(final @NotNull MediaType mediaType) {
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -710,17 +742,17 @@ public class RestMindmapITCase {
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
|
||||
template = createTemplate(newCollab+":admin");
|
||||
|
||||
template = createTemplate(newCollab + ":admin");
|
||||
//add collab again with the new user expecting the Exception
|
||||
try{
|
||||
try {
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
} catch (HttpClientErrorException e){
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
assertTrue(e.getMessage().contains("User must be owner to share mindmap"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void addCollabWhitOwnerRole(final @NotNull MediaType mediaType) {
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -740,14 +772,14 @@ public class RestMindmapITCase {
|
||||
addCollabToList(newCollab, role, collabs);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
try{
|
||||
try {
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
} catch (HttpClientErrorException e){
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
assertTrue(e.getMessage().contains("Collab email can not be change"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String changeMapTitle(final HttpHeaders requestHeaders, final MediaType mediaType, final RestTemplate template, final URI resourceUri) throws RestClientException {
|
||||
// Change map title ...
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
@ -762,7 +794,7 @@ public class RestMindmapITCase {
|
||||
final ResponseEntity<RestMindmapList> maps = template.exchange(BASE_REST_URL + "/maps/", HttpMethod.GET, findMapEntity, RestMindmapList.class);
|
||||
return maps.getBody();
|
||||
}
|
||||
|
||||
|
||||
private RestCollaborationList fetchAndGetCollabs(final HttpHeaders requestHeaders, final RestTemplate template, final URI resourceUri) {
|
||||
final ResponseEntity<RestCollaborationList> response = fetchCollabs(requestHeaders, template, resourceUri);
|
||||
RestCollaborationList responseCollbs = response.getBody();
|
||||
|
Loading…
Reference in New Issue
Block a user