mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-21 13:47:57 +01:00
Merged in integration-test-incresed-coverage (pull request #19)
Integration test incresed coverage * batchDelete test implementation * updatePublishState test implementation * RestMindmapHistory basic constructor for testing purpose * fetchMapHistory test implementation * updateRevertMindmap test implementation * Coverage report in README * correction * updateRevertMindmap test improvement * addCollab missed branches * deleteCollab missed branches Approved-by: Paulo Veiga
This commit is contained in:
parent
8ffb48d095
commit
edaa4b78f4
@ -53,6 +53,11 @@ A quick and dirty solution to share changes in the UI is to manually compile the
|
||||
|
||||
Check out the [docker section](./docker/README.)
|
||||
|
||||
### Test reports
|
||||
|
||||
Individual test result reports can be found in wisemapping-open-source/wise-webapp/target/failsafe-reports/index.html
|
||||
Test coverage report of unit and integration test can be found in wisemapping-open-source/wise-webapp/target/site/jacoco and wisemapping-open-source/wise-webapp/target/site/jacoco-it folders. Coverage report is generated in the verify phase of [lifecicle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#introduction-to-the-build-lifecyclea) using [jacoco](https://www.jacoco.org/jacoco/trunk/doc/maven.html)
|
||||
|
||||
## Members
|
||||
|
||||
### Founders
|
||||
|
@ -1,5 +1,4 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>wise-webapp</artifactId>
|
||||
<packaging>war</packaging>
|
||||
@ -452,6 +451,68 @@
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-prepare-agent</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-prepare-agent-integration</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>prepare-agent-integration</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*Test*</exclude>
|
||||
</excludes>
|
||||
<propertyName>integrationTestArgLine</propertyName>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>default-check</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<rule>
|
||||
<element>BUNDLE</element>
|
||||
<limits>
|
||||
<limit>
|
||||
<counter>COMPLEXITY</counter>
|
||||
<value>COVEREDRATIO</value>
|
||||
<minimum>0.10</minimum>
|
||||
</limit>
|
||||
</limits>
|
||||
</rule>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-report-integration</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>report-integration</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-report</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
@ -459,6 +520,9 @@
|
||||
<version>9.4.34.v20201102</version>
|
||||
<configuration>
|
||||
<stopKey>foo</stopKey>
|
||||
<httpConnector>
|
||||
<port>8080</port>
|
||||
</httpConnector>
|
||||
<stopPort>9999</stopPort>
|
||||
<war>${project.build.directory}/wisemapping.war</war>
|
||||
<reload>automatic</reload>
|
||||
@ -488,9 +552,13 @@
|
||||
<goal>run-forked</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<useTestClasspath>true</useTestClasspath>
|
||||
<useTestScope>true</useTestScope>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
<waitForChild>false</waitForChild>
|
||||
<jvmArgs>-Ddatabase.base.url=${project.build.directory}</jvmArgs>
|
||||
<maxStartupLines>200</maxStartupLines>
|
||||
<jvmArgs>${integrationTestArgLine} -Ddatabase.base.url=${project.build.directory} -Djetty.port=8080</jvmArgs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
@ -499,6 +567,9 @@
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<stopWait>1</stopWait>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
@ -514,6 +585,7 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
</project>
|
@ -40,15 +40,18 @@ import java.util.TimeZone;
|
||||
public class RestMindmapHistory {
|
||||
|
||||
static private final SimpleDateFormat sdf;
|
||||
private final int id;
|
||||
private final Calendar creation;
|
||||
private final String creator;
|
||||
private int id;
|
||||
private Calendar creation;
|
||||
private String creator;
|
||||
|
||||
static {
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
public RestMindmapHistory() {
|
||||
}
|
||||
|
||||
public RestMindmapHistory(@NotNull MindMapHistory history) {
|
||||
this.id = history.getId();
|
||||
this.creation = history.getCreationTime();
|
||||
@ -61,18 +64,18 @@ public class RestMindmapHistory {
|
||||
}
|
||||
|
||||
public void setCreationTime() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setCreator() {
|
||||
// Do nothing ...
|
||||
public void setCreator(String creator) {
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
private String toISO8601(@NotNull Date date) {
|
||||
|
@ -83,7 +83,7 @@ public class RestAdminITCase {
|
||||
}
|
||||
}
|
||||
|
||||
public String createNewUser(final @NotNull MediaType mediaType) {
|
||||
public RestUser createNewUserAndGetUser(final @NotNull MediaType mediaType) {
|
||||
|
||||
// Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -99,6 +99,13 @@ public class RestAdminITCase {
|
||||
ResponseEntity<RestUser> result = findUser(requestHeaders, templateRest, location);
|
||||
assertEquals(result.getBody().getEmail(), restUser.getEmail(), "Returned object object seems not be the same.");
|
||||
|
||||
return result.getBody();
|
||||
}
|
||||
|
||||
public String createNewUser(final @NotNull MediaType mediaType) {
|
||||
|
||||
// Fill user data ...
|
||||
final RestUser restUser = createNewUserAndGetUser(mediaType);
|
||||
// Find by email and check ...
|
||||
// @todo: review find by email... It's failing with 406
|
||||
// findUser(requestHeaders, templateRest, location);
|
||||
@ -119,7 +126,7 @@ public class RestAdminITCase {
|
||||
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class);
|
||||
}
|
||||
|
||||
private ResponseEntity<RestUser> findUserByEmail(HttpHeaders requestHeaders, RestTemplate templateRest, final String email) {
|
||||
public ResponseEntity<RestUser> findUserByEmail(HttpHeaders requestHeaders, RestTemplate templateRest, final String email) {
|
||||
HttpEntity<RestUser> findUserEntity = new HttpEntity<>(requestHeaders);
|
||||
|
||||
// Add extension only to avoid the fact that the last part is extracted ...
|
||||
|
@ -78,6 +78,7 @@ public class RestLabelITCase {
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void createLabelWithoutRequiredField(final @NotNull MediaType mediaType) throws IOException, WiseMappingException {
|
||||
final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType);
|
||||
requestHeaders.set(HttpHeaders.ACCEPT_LANGUAGE, "en");
|
||||
final RestTemplate template = RestHelper.createTemplate(userEmail + ":" + "admin");
|
||||
|
||||
try {
|
||||
|
@ -18,6 +18,10 @@ 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
|
||||
@ -25,11 +29,11 @@ public class RestMindmapITCase {
|
||||
|
||||
private String userEmail = "admin@wisemapping.com";
|
||||
private static final String ICON = "glyphicon glyphicon-tag";
|
||||
final RestAdminITCase restAdminITCase = new RestAdminITCase();
|
||||
|
||||
@BeforeClass
|
||||
void createUser() {
|
||||
|
||||
final RestAdminITCase restAdminITCase = new RestAdminITCase();
|
||||
userEmail = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
||||
userEmail += ":" + "admin";
|
||||
}
|
||||
@ -46,12 +50,8 @@ public class RestMindmapITCase {
|
||||
final String title2 = "List Maps 2 - " + mediaType;
|
||||
addNewMap(template, title2);
|
||||
|
||||
// Check that the map has been created ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmapList> response = template.exchange(BASE_REST_URL + "/maps/", HttpMethod.GET, findMapEntity, RestMindmapList.class);
|
||||
|
||||
// Validate that the two maps are there ...
|
||||
final RestMindmapList body = response.getBody();
|
||||
final RestMindmapList body = fetchMaps(requestHeaders, template);
|
||||
final List<RestMindmapInfo> mindmaps = body.getMindmapsInfo();
|
||||
|
||||
boolean found1 = false;
|
||||
@ -96,11 +96,7 @@ public class RestMindmapITCase {
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "Map to change title - " + mediaType);
|
||||
|
||||
// Change map title ...
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
final String newTitle = "New map to change title - " + mediaType;
|
||||
final HttpEntity<String> updateEntity = new HttpEntity<>(newTitle, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/title", updateEntity);
|
||||
String newTitle = changeMapTitle(requestHeaders, mediaType, template, resourceUri);
|
||||
|
||||
// Load map again ..
|
||||
final RestMindmap map = findMap(requestHeaders, template, resourceUri);
|
||||
@ -110,6 +106,7 @@ public class RestMindmapITCase {
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void validateMapsCreation(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
requestHeaders.set(HttpHeaders.ACCEPT_LANGUAGE, "en");
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
@ -160,16 +157,25 @@ public class RestMindmapITCase {
|
||||
|
||||
// Update map xml content ...
|
||||
final String resourceUrl = HOST_PORT + resourceUri.toString();
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
final String newXmlContent = "<map>this is not valid</map>";
|
||||
HttpEntity<String> updateEntity = new HttpEntity<>(newXmlContent, requestHeaders);
|
||||
template.put(resourceUrl + "/document/xml", updateEntity);
|
||||
String newXmlContent = updateMapDocument(requestHeaders, template, resourceUrl);
|
||||
|
||||
// Check that the map has been updated ...
|
||||
final RestMindmap response = findMap(requestHeaders, template, resourceUri);
|
||||
assertEquals(response.getXml(), newXmlContent);
|
||||
}
|
||||
|
||||
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>";
|
||||
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);
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void cloneMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
@ -196,7 +202,38 @@ public class RestMindmapITCase {
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void verifyMapOwnership(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
throw new SkipException("missing test: removeUserShouldOnlyDeleteOnwedMap");
|
||||
final RestAdminITCase restAdminITCase = new RestAdminITCase();
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
final String title1 = "verifyMapOwnership Map user 1";
|
||||
addNewMap(template, title1);
|
||||
|
||||
//create another user
|
||||
RestUser secondUser = restAdminITCase.createNewUserAndGetUser(MediaType.APPLICATION_JSON);
|
||||
final RestTemplate secondTemplate = createTemplate(secondUser.getEmail()+":admin");
|
||||
|
||||
final String title2 = "verifyMapOwnership Map user 2";
|
||||
addNewMap(secondTemplate, title2);
|
||||
|
||||
// Delete user ...
|
||||
String authorisation = "admin@wisemapping.org" + ":" + "test";
|
||||
RestTemplate superadminTemplate = createTemplate(authorisation);
|
||||
|
||||
superadminTemplate.delete(BASE_REST_URL + "/admin/users/"+secondUser.getId());
|
||||
|
||||
// Validate that the two maps are there ...
|
||||
final RestMindmapList body = fetchMaps(requestHeaders, template);
|
||||
final List<RestMindmapInfo> mindmaps = body.getMindmapsInfo();
|
||||
|
||||
boolean found1 = false;
|
||||
for (RestMindmapInfo mindmap : mindmaps) {
|
||||
if (mindmap.getTitle().equals(title1)) {
|
||||
found1 = true; break;
|
||||
}
|
||||
}
|
||||
assertTrue(found1, "Map could not be found");
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
@ -242,25 +279,10 @@ public class RestMindmapITCase {
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "Map for addCollabs - " + mediaType);
|
||||
|
||||
// Add a new collaboration ...
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
final RestCollaborationList collabs = new RestCollaborationList();
|
||||
collabs.setMessage("Adding new permission");
|
||||
|
||||
final String newCollab = "new-collab@example.com";
|
||||
String role = "editor";
|
||||
|
||||
final RestCollaboration collab = new RestCollaboration();
|
||||
collab.setEmail(newCollab);
|
||||
collab.setRole(role);
|
||||
collabs.addCollaboration(collab);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
String newCollab = addNewCollaboration(requestHeaders, template, resourceUri);
|
||||
|
||||
// Has been added ?
|
||||
final ResponseEntity<RestCollaborationList> response = fetchCollabs(requestHeaders, template, resourceUri);
|
||||
RestCollaborationList responseCollbs = response.getBody();
|
||||
RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, template, resourceUri);
|
||||
|
||||
// Has been added ?
|
||||
assertEquals(responseCollbs.getCount(), 2);
|
||||
@ -286,17 +308,13 @@ public class RestMindmapITCase {
|
||||
final String newCollab = "new-collab@example.com";
|
||||
String role = "editor";
|
||||
|
||||
final RestCollaboration collab = new RestCollaboration();
|
||||
collab.setEmail(newCollab);
|
||||
collab.setRole(role);
|
||||
collabs.addCollaboration(collab);
|
||||
final RestCollaboration collab = addCollabToList(newCollab, role, collabs);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
|
||||
// Has been added ?
|
||||
final ResponseEntity<RestCollaborationList> response = fetchCollabs(requestHeaders, template, resourceUri);
|
||||
RestCollaborationList responseCollbs = response.getBody();
|
||||
RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, template, resourceUri);
|
||||
assertEquals(responseCollbs.getCount(), 2);
|
||||
|
||||
// Update the collaboration type ...
|
||||
@ -318,25 +336,10 @@ public class RestMindmapITCase {
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "Map for deleteCollabs - " + mediaType);
|
||||
|
||||
// Add a new collaboration ...
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
final RestCollaborationList collabs = new RestCollaborationList();
|
||||
collabs.setMessage("Adding new permission");
|
||||
|
||||
final String newCollab = "new-collab@example.com";
|
||||
String role = "editor";
|
||||
|
||||
final RestCollaboration collab = new RestCollaboration();
|
||||
collab.setEmail(newCollab);
|
||||
collab.setRole(role);
|
||||
collabs.addCollaboration(collab);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
String newCollab = addNewCollaboration(requestHeaders, template, resourceUri);
|
||||
|
||||
// Has been added ?
|
||||
final ResponseEntity<RestCollaborationList> response = fetchCollabs(requestHeaders, template, resourceUri);
|
||||
RestCollaborationList responseCollbs = response.getBody();
|
||||
RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, template, resourceUri);
|
||||
|
||||
// Has been added ?
|
||||
assertEquals(responseCollbs.getCount(), 2);
|
||||
@ -349,6 +352,82 @@ public class RestMindmapITCase {
|
||||
assertEquals(afterDeleteResponse.getBody().getCollaborations().size(), 1);
|
||||
}
|
||||
|
||||
private String addNewCollaboration(final HttpHeaders requestHeaders, final RestTemplate template, final URI resourceUri) throws RestClientException {
|
||||
// Add a new collaboration ...
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
final RestCollaborationList collabs = new RestCollaborationList();
|
||||
collabs.setMessage("Adding new permission");
|
||||
final String newCollab = "new-collab@example.com";
|
||||
String role = "editor";
|
||||
addCollabToList(newCollab, role, collabs);
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
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);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// 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<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);
|
||||
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "deleteWithoutOwnerPermission");
|
||||
|
||||
final String newCollab = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
||||
template = createTemplate(newCollab+":admin");
|
||||
|
||||
// Remove with invalid email ...
|
||||
try {
|
||||
|
||||
template.delete(HOST_PORT + resourceUri + "/collabs?email="+newCollab );
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
assertTrue(e.getMessage().contains("No enough permissions"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void deleteOwnerCollab(final @NotNull MediaType mediaType) {
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// 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", "") );
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(e.getRawStatusCode(), 400);
|
||||
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);
|
||||
@ -361,7 +440,7 @@ public class RestMindmapITCase {
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
// Create a sample map ...fetchAndGetCollabs(requestHeaders, template, resourceUri);
|
||||
final URI resourceUri = addNewMap(template, "Map for Collaboration - " + mediaType);
|
||||
|
||||
// Add a new collaboration ...
|
||||
@ -370,19 +449,43 @@ public class RestMindmapITCase {
|
||||
collabs.setMessage("Adding new permission");
|
||||
|
||||
// Validate that owner can not be added.
|
||||
final RestCollaboration collab = new RestCollaboration();
|
||||
final String newCollab = "new-collab@example.com";
|
||||
collab.setEmail(newCollab);
|
||||
collab.setRole("owner");
|
||||
collabs.addCollaboration(collab);
|
||||
addCollabToList("newCollab@example", "owner", collabs);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void removeLabelFromMindmap(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
throw new SkipException("missing test: label removal from map");
|
||||
public void removeLabelFromMindmap(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a new label
|
||||
final String titleLabel = "removeLabelFromMindmap";
|
||||
final URI labelUri = RestLabelITCase.addNewLabel(requestHeaders, template, titleLabel, COLOR, ICON);
|
||||
|
||||
// Create a sample map ...
|
||||
final String mapTitle = "removeLabelFromMindmap";
|
||||
final URI mindmapUri = addNewMap(template, mapTitle);
|
||||
final String mapId = mindmapUri.getPath().replace("/service/maps/", "");
|
||||
|
||||
// Assign label to map ...
|
||||
String labelId = labelUri.getPath().replace("/service/labels/", "");
|
||||
HttpEntity<String> labelEntity = new HttpEntity<>(labelId, requestHeaders);
|
||||
template.postForLocation(BASE_REST_URL + "/maps/" + mapId + "/labels", labelEntity);
|
||||
|
||||
// Remove label from map
|
||||
template.delete(BASE_REST_URL + "/maps/" + mapId + "/labels/" + labelId);
|
||||
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
@ -410,10 +513,7 @@ public class RestMindmapITCase {
|
||||
template.postForLocation(BASE_REST_URL + "/maps/" + mapId + "/labels", labelEntity);
|
||||
|
||||
// Check that the label has been assigned ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmapList> mindmapList = template.exchange(BASE_REST_URL + "/maps/", HttpMethod.GET, findMapEntity, RestMindmapList.class);
|
||||
|
||||
final List<RestMindmapInfo> mindmapsInfo = mindmapList.getBody().getMindmapsInfo();
|
||||
final List<RestMindmapInfo> mindmapsInfo = fetchMaps(requestHeaders, template).getMindmapsInfo();
|
||||
Optional<RestMindmapInfo> mindmapInfo = mindmapsInfo
|
||||
.stream()
|
||||
.filter(m -> m.getId() == Integer.parseInt(mapId))
|
||||
@ -422,6 +522,261 @@ public class RestMindmapITCase {
|
||||
assertTrue(mindmapInfo.get().getLabels().size() == 1);
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void updateCollabs(final @NotNull MediaType mediaType) {
|
||||
|
||||
// Create a sample map ...
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
final URI resourceUri = addNewMap(template, "Map for updateCollabs - " + mediaType);
|
||||
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
// Add a new collaboration ...
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
RestCollaborationList collabs = new RestCollaborationList();
|
||||
collabs.setMessage("Adding new permission");
|
||||
|
||||
String newCollab = "new-collab@example.com";
|
||||
String role = "editor";
|
||||
|
||||
addCollabToList(newCollab, role, collabs);
|
||||
|
||||
HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
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);
|
||||
|
||||
|
||||
RestCollaborationList responseCollbs = fetchAndGetCollabs(requestHeaders, template, resourceUri);
|
||||
|
||||
// Has been another-collaboration list updated ?
|
||||
assertTrue(responseCollbs.getCollaborations().stream().anyMatch(x -> x.getEmail().equals("another-collab@example.com")));
|
||||
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);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
final String title = "updateProperties map";
|
||||
final URI resourceUri = addNewMap(template, title);
|
||||
|
||||
// Build map to update ...
|
||||
final RestMindmap mapToUpdate = new RestMindmap();
|
||||
mapToUpdate.setXml("<map>this is not valid</map>");
|
||||
mapToUpdate.setProperties("{zoom:x}");
|
||||
mapToUpdate.setTitle("new title for map");
|
||||
mapToUpdate.setDescription("updated map description");
|
||||
|
||||
// Update map ...
|
||||
final String resourceUrl = HOST_PORT + resourceUri.toString();
|
||||
final HttpEntity<RestMindmap> updateEntity = new HttpEntity<>(mapToUpdate, requestHeaders);
|
||||
template.put(resourceUrl, updateEntity);
|
||||
|
||||
// Check that the map has been updated ...
|
||||
HttpEntity<RestUser> findMapEntity = new HttpEntity<>(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = template.exchange(HOST_PORT + resourceUri, HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
assertEquals(response.getBody().getTitle(), mapToUpdate.getTitle());
|
||||
assertEquals(response.getBody().getDescription(), mapToUpdate.getDescription());
|
||||
assertEquals(response.getBody().getXml(), mapToUpdate.getXml());
|
||||
assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties());
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
// Create a sample map ...
|
||||
final String mapTitle = "updatePublishState";
|
||||
final URI mindmapUri = addNewMap(template, mapTitle);
|
||||
final String mapId = mindmapUri.getPath().replace("/service/maps/", "");
|
||||
|
||||
// Change map status ...
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
//final String newPublicState = "true";
|
||||
final HttpEntity<String> updateEntity = new HttpEntity<>(Boolean.TRUE.toString(), requestHeaders);
|
||||
template.put(HOST_PORT + mindmapUri + "/publish", updateEntity);
|
||||
|
||||
//fetch public view
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
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);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
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);
|
||||
assertEquals(maps.getBody().getCount(), 1);
|
||||
}
|
||||
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
|
||||
public void updateRevertMindmap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// 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);
|
||||
|
||||
//aply revert
|
||||
final HttpEntity<String> cloneEntity = new HttpEntity<>(requestHeaders);
|
||||
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);
|
||||
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);
|
||||
RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "MaddCollabWhitoutOwnerPermission");
|
||||
|
||||
// Add a new collaboration ...
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
final RestCollaborationList collabs = new RestCollaborationList();
|
||||
collabs.setMessage("Adding new permission");
|
||||
|
||||
final String newCollab = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
||||
String role = "editor";
|
||||
|
||||
addCollabToList(newCollab, role, collabs);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
|
||||
template = createTemplate(newCollab+":admin");
|
||||
//add collab again with the new user expecting the Exception
|
||||
try{
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
} 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);
|
||||
RestTemplate template = createTemplate(userEmail);
|
||||
|
||||
// Create a sample map ...
|
||||
final URI resourceUri = addNewMap(template, "addCollabWhitOwnerRole");
|
||||
|
||||
// Add a new collaboration ...
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
final RestCollaborationList collabs = new RestCollaborationList();
|
||||
collabs.setMessage("Adding new permission");
|
||||
|
||||
final String newCollab = "new-collaborator@mail.com";
|
||||
String role = "owner";
|
||||
|
||||
addCollabToList(newCollab, role, collabs);
|
||||
|
||||
final HttpEntity<RestCollaborationList> updateEntity = new HttpEntity<>(collabs, requestHeaders);
|
||||
try{
|
||||
template.put(HOST_PORT + resourceUri + "/collabs/", updateEntity);
|
||||
} 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);
|
||||
final String newTitle = "New map to change title - " + mediaType;
|
||||
final HttpEntity<String> updateEntity = new HttpEntity<>(newTitle, requestHeaders);
|
||||
template.put(HOST_PORT + resourceUri + "/title", updateEntity);
|
||||
return newTitle;
|
||||
}
|
||||
|
||||
private RestMindmapList fetchMaps(final HttpHeaders requestHeaders, final RestTemplate template) throws RestClientException {
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
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();
|
||||
return responseCollbs;
|
||||
}
|
||||
|
||||
private RestCollaboration addCollabToList(String newCollab, String role, RestCollaborationList collabs) {
|
||||
RestCollaboration collab = new RestCollaboration();
|
||||
collab.setEmail(newCollab);
|
||||
collab.setRole(role);
|
||||
collabs.addCollaboration(collab);
|
||||
return collab;
|
||||
}
|
||||
|
||||
private RestMindmap findMap(HttpHeaders requestHeaders, RestTemplate template, URI resourceUri) {
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = template.exchange(HOST_PORT + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
|
Loading…
Reference in New Issue
Block a user